1
1
import Maybe from '../tsutils/Maybe' ;
2
- import { ASTNode , ASTKindToNode } from './ast' ;
3
2
import { TypeInfo } from '../utilities/TypeInfo' ;
3
+ import { ASTNode , ASTKindToNode } from './ast' ;
4
+
5
+ /**
6
+ * A visitor is provided to visit, it contains the collection of
7
+ * relevant functions to be called during the visitor's traversal.
8
+ */
9
+ export type ASTVisitor = Visitor < ASTKindToNode > ;
10
+ export type Visitor < KindToNode , Nodes = KindToNode [ keyof KindToNode ] > =
11
+ | EnterLeaveVisitor < KindToNode , Nodes >
12
+ | ShapeMapVisitor < KindToNode , Nodes > ;
4
13
5
14
interface EnterLeave < T > {
6
15
readonly enter ?: T ;
@@ -17,27 +26,23 @@ type ShapeMapVisitor<KindToNode, Nodes> = {
17
26
| EnterLeave < VisitFn < Nodes , KindToNode [ K ] > > ;
18
27
} ;
19
28
20
- export type ASTVisitor = Visitor < ASTKindToNode > ;
21
- export type Visitor < KindToNode , Nodes = KindToNode [ keyof KindToNode ] > =
22
- | EnterLeaveVisitor < KindToNode , Nodes >
23
- | ShapeMapVisitor < KindToNode , Nodes > ;
24
-
25
29
/**
26
30
* A visitor is comprised of visit functions, which are called on each node
27
31
* during the visitor's traversal.
28
32
*/
29
33
export type VisitFn < TAnyNode , TVisitedNode = TAnyNode > = (
30
- // The current node being visiting.
34
+ /** The current node being visiting.*/
31
35
node : TVisitedNode ,
32
- // The index or key to this node from the parent node or Array.
36
+ /** The index or key to this node from the parent node or Array. */
33
37
key : string | number | undefined ,
34
- // The parent immediately above this node, which may be an Array.
38
+ /** The parent immediately above this node, which may be an Array. */
35
39
parent : TAnyNode | ReadonlyArray < TAnyNode > | undefined ,
36
- // The key path to get to this node from the root node.
40
+ /** The key path to get to this node from the root node. */
37
41
path : ReadonlyArray < string | number > ,
38
- // All nodes and Arrays visited before reaching parent of this node.
39
- // These correspond to array indices in `path`.
40
- // Note: ancestors includes arrays which contain the parent of visited node.
42
+ /** All nodes and Arrays visited before reaching parent of this node.
43
+ * These correspond to array indices in `path`.
44
+ * Note: ancestors includes arrays which contain the parent of visited node.
45
+ */
41
46
ancestors : ReadonlyArray < TAnyNode | ReadonlyArray < TAnyNode > > ,
42
47
) => any ;
43
48
@@ -46,9 +51,88 @@ export type VisitFn<TAnyNode, TVisitedNode = TAnyNode> = (
46
51
*/
47
52
export type VisitorKeyMap < T > = { [ P in keyof T ] : ReadonlyArray < keyof T [ P ] > } ;
48
53
49
- export const QueryDocumentKeys : { [ key : string ] : string [ ] } ;
54
+ export const QueryDocumentKeys : {
55
+ Name : [ ] ;
56
+
57
+ Document : [ 'definitions' ] ;
58
+ OperationDefinition : [
59
+ 'name' ,
60
+ 'variableDefinitions' ,
61
+ 'directives' ,
62
+ 'selectionSet' ,
63
+ ] ;
64
+ VariableDefinition : [ 'variable' , 'type' , 'defaultValue' , 'directives' ] ;
65
+ Variable : [ 'name' ] ;
66
+ SelectionSet : [ 'selections' ] ;
67
+ Field : [ 'alias' , 'name' , 'arguments' , 'directives' , 'selectionSet' ] ;
68
+ Argument : [ 'name' , 'value' ] ;
69
+
70
+ FragmentSpread : [ 'name' , 'directives' ] ;
71
+ InlineFragment : [ 'typeCondition' , 'directives' , 'selectionSet' ] ;
72
+ FragmentDefinition : [
73
+ 'name' ,
74
+ // Note: fragment variable definitions are experimental and may be changed
75
+ // or removed in the future.
76
+ 'variableDefinitions' ,
77
+ 'typeCondition' ,
78
+ 'directives' ,
79
+ 'selectionSet' ,
80
+ ] ;
81
+
82
+ IntValue : [ ] ;
83
+ FloatValue : [ ] ;
84
+ StringValue : [ ] ;
85
+ BooleanValue : [ ] ;
86
+ NullValue : [ ] ;
87
+ EnumValue : [ ] ;
88
+ ListValue : [ 'values' ] ;
89
+ ObjectValue : [ 'fields' ] ;
90
+ ObjectField : [ 'name' , 'value' ] ;
91
+
92
+ Directive : [ 'name' , 'arguments' ] ;
93
+
94
+ NamedType : [ 'name' ] ;
95
+ ListType : [ 'type' ] ;
96
+ NonNullType : [ 'type' ] ;
97
+
98
+ SchemaDefinition : [ 'directives' , 'operationTypes' ] ;
99
+ OperationTypeDefinition : [ 'type' ] ;
100
+
101
+ ScalarTypeDefinition : [ 'description' , 'name' , 'directives' ] ;
102
+ ObjectTypeDefinition : [
103
+ 'description' ,
104
+ 'name' ,
105
+ 'interfaces' ,
106
+ 'directives' ,
107
+ 'fields' ,
108
+ ] ;
109
+ FieldDefinition : [ 'description' , 'name' , 'arguments' , 'type' , 'directives' ] ;
110
+ InputValueDefinition : [
111
+ 'description' ,
112
+ 'name' ,
113
+ 'type' ,
114
+ 'defaultValue' ,
115
+ 'directives' ,
116
+ ] ;
117
+ InterfaceTypeDefinition : [ 'description' , 'name' , 'directives' , 'fields' ] ;
118
+ UnionTypeDefinition : [ 'description' , 'name' , 'directives' , 'types' ] ;
119
+ EnumTypeDefinition : [ 'description' , 'name' , 'directives' , 'values' ] ;
120
+ EnumValueDefinition : [ 'description' , 'name' , 'directives' ] ;
121
+ InputObjectTypeDefinition : [ 'description' , 'name' , 'directives' , 'fields' ] ;
122
+
123
+ DirectiveDefinition : [ 'description' , 'name' , 'arguments' , 'locations' ] ;
124
+
125
+ SchemaExtension : [ 'directives' , 'operationTypes' ] ;
126
+
127
+ ScalarTypeExtension : [ 'name' , 'directives' ] ;
128
+ ObjectTypeExtension : [ 'name' , 'interfaces' , 'directives' , 'fields' ] ;
129
+ InterfaceTypeExtension : [ 'name' , 'directives' , 'fields' ] ;
130
+ UnionTypeExtension : [ 'name' , 'directives' , 'types' ] ;
131
+ EnumTypeExtension : [ 'name' , 'directives' , 'values' ] ;
132
+ InputObjectTypeExtension : [ 'name' , 'directives' , 'fields' ] ;
133
+ } ;
50
134
51
- export const BREAK : any ;
135
+ export const BREAK : { } ;
52
136
53
137
/**
54
138
* visit() will walk through an AST using a depth first traversal, calling
@@ -149,7 +233,7 @@ export function visit(
149
233
* If a prior visitor edits a node, no following visitors will see that node.
150
234
*/
151
235
export function visitInParallel (
152
- visitors : Array < Visitor < ASTKindToNode > > ,
236
+ visitors : ReadonlyArray < Visitor < ASTKindToNode > > ,
153
237
) : Visitor < ASTKindToNode > ;
154
238
155
239
/**
0 commit comments