UNPKG

6.9 kBTypeScriptView Raw
1/**
2 * Copyright (c) 2015, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 */
9
10/**
11 * GraphQL parser.
12 */
13declare module "graphql/language" {
14 export function parse(source:string, options?: any): Document;
15
16 export function visit(root: Node, visitor: Visitor, keyMap?: any): void;
17
18 export interface Visitor {
19 enter(node: Node, key?: string, parent?: Node, path?: any, ancestors?: any): void;
20 leave(node: Node, key?: string, parent?: Node, path?: any, ancestors?: any): void;
21 }
22
23 /**
24 * Converts an AST into a string, using one set of reasonable
25 * formatting rules.
26 */
27 export function print(ast: Node): string;
28
29 //import type { Source } from './source';
30
31 export class Source {
32 body:string;
33 name:string;
34
35 constructor(body:string, name?:string);
36 }
37
38 /**
39 * Contains a range of UTF-8 character offsets that identify
40 * the region of the source from which the AST derived.
41 */
42 export type Location = {
43 start: number;
44 end: number;
45 source?: Source
46 }
47
48 /**
49 * The list of all possible AST node types.
50 */
51 export type Node = Name
52 | Document
53 | OperationDefinition
54 | VariableDefinition
55 | Variable
56 | SelectionSet
57 | Field
58 | Argument
59 | FragmentSpread
60 | InlineFragment
61 | FragmentDefinition
62 | IntValue
63 | FloatValue
64 | StringValue
65 | BooleanValue
66 | EnumValue
67 | ListValue
68 | ObjectValue
69 | ObjectField
70 | Directive
71 | NamedType
72 | ListType
73 | NonNullType
74 | ObjectTypeDefinition
75 | FieldDefinition
76 | InputValueDefinition
77 | InterfaceTypeDefinition
78 | UnionTypeDefinition
79 | ScalarTypeDefinition
80 | EnumTypeDefinition
81 | EnumValueDefinition
82 | InputObjectTypeDefinition
83 | TypeExtensionDefinition
84
85 // Name
86
87 export type Name = {
88 kind: string;
89 loc?: Location;
90 value: string;
91 }
92
93 // Document
94
95 export type Document = {
96 kind: string;
97 loc?: Location;
98 definitions: Array<Definition>;
99 }
100
101 export type Definition = OperationDefinition
102 | FragmentDefinition
103 | TypeDefinition
104 | TypeExtensionDefinition
105
106 export type OperationDefinition = {
107 kind: string;
108 loc?: Location;
109 // Note: subscription is an experimental non-spec addition.
110 operation: string; // 'queryDocument' | 'mutation' | 'subscription';
111 name?: Name;
112 variableDefinitions?: Array<VariableDefinition>;
113 directives?: Array<Directive>;
114 selectionSet: SelectionSet;
115 }
116
117 export type VariableDefinition = {
118 kind: string;
119 loc?: Location;
120 variable: Variable;
121 type: Type;
122 defaultValue?: Value;
123 }
124
125 export type Variable = {
126 kind: string;
127 loc?: Location;
128 name: Name;
129 }
130
131 export type SelectionSet = {
132 kind: string;
133 loc?: Location;
134 selections: Array<Selection>;
135 }
136
137 export type Selection = Field
138 | FragmentSpread
139 | InlineFragment
140
141 export type Field = {
142 kind: string;
143 loc?: Location;
144 alias?: Name;
145 name: Name;
146 arguments?: Array<Argument>;
147 directives?: Array<Directive>;
148 selectionSet?: SelectionSet;
149 }
150
151 export type Argument = {
152 kind: string;
153 loc?: Location;
154 name: Name;
155 value: Value;
156 }
157
158
159 // Fragments
160
161 export type FragmentSpread = {
162 kind: string;
163 loc?: Location;
164 name: Name;
165 directives?: Array<Directive>;
166 }
167
168 export type InlineFragment = {
169 kind: string;
170 loc?: Location;
171 typeCondition?: NamedType;
172 directives?: Array<Directive>;
173 selectionSet: SelectionSet;
174 }
175
176 export type FragmentDefinition = {
177 kind: string;
178 loc?: Location;
179 name: Name;
180 typeCondition: NamedType;
181 directives?: Array<Directive>;
182 selectionSet: SelectionSet;
183 }
184
185
186 // Values
187
188 export type Value = Variable
189 | IntValue
190 | FloatValue
191 | StringValue
192 | BooleanValue
193 | EnumValue
194 | ListValue
195 | ObjectValue
196
197 export type IntValue = {
198 kind: string;
199 loc?: Location;
200 value: string;
201 }
202
203 export type FloatValue = {
204 kind: string;
205 loc?: Location;
206 value: string;
207 }
208
209 export type StringValue = {
210 kind: string;
211 loc?: Location;
212 value: string;
213 }
214
215 export type BooleanValue = {
216 kind: string;
217 loc?: Location;
218 value: boolean;
219 }
220
221 export type EnumValue = {
222 kind: string;
223 loc?: Location;
224 value: string;
225 }
226
227 export type ListValue = {
228 kind: string;
229 loc?: Location;
230 values: Array<Value>;
231 }
232
233 export type ObjectValue = {
234 kind: string;
235 loc?: Location;
236 fields: Array<ObjectField>;
237 }
238
239 export type ObjectField = {
240 kind: string;
241 loc?: Location;
242 name: Name;
243 value: Value;
244 }
245
246
247 // Directives
248
249 export type Directive = {
250 kind: string;
251 loc?: Location;
252 name: Name;
253 arguments?: Array<Argument>;
254 }
255
256
257 // Type Reference
258
259 export type Type
260 = NamedType
261 | ListType
262 | NonNullType
263
264 export type NamedType = {
265 kind: string;
266 loc?: Location;
267 name: Name;
268 };
269
270 export type ListType = {
271 kind: string;
272 loc?: Location;
273 type: Type;
274 }
275
276 export type NonNullType = {
277 kind: string;
278 loc?: Location;
279 type: NamedType | ListType;
280 }
281
282 // Type Definition
283
284 export type TypeDefinition = ObjectTypeDefinition
285 | InterfaceTypeDefinition
286 | UnionTypeDefinition
287 | ScalarTypeDefinition
288 | EnumTypeDefinition
289 | InputObjectTypeDefinition
290
291 export type ObjectTypeDefinition = {
292 kind: string;
293 loc?: Location;
294 name: Name;
295 interfaces?: Array<NamedType>;
296 fields: Array<FieldDefinition>;
297 }
298
299 export type FieldDefinition = {
300 kind: string;
301 loc?: Location;
302 name: Name;
303 arguments: Array<InputValueDefinition>;
304 type: Type;
305 }
306
307 export type InputValueDefinition = {
308 kind: string;
309 loc?: Location;
310 name: Name;
311 type: Type;
312 defaultValue?: Value;
313 }
314
315 export type InterfaceTypeDefinition = {
316 kind: string;
317 loc?: Location;
318 name: Name;
319 fields: Array<FieldDefinition>;
320 }
321
322 export type UnionTypeDefinition = {
323 kind: string;
324 loc?: Location;
325 name: Name;
326 types: Array<NamedType>;
327 }
328
329 export type ScalarTypeDefinition = {
330 kind: string;
331 loc?: Location;
332 name: Name;
333 }
334
335 export type EnumTypeDefinition = {
336 kind: string;
337 loc?: Location;
338 name: Name;
339 values: Array<EnumValueDefinition>;
340 }
341
342 export type EnumValueDefinition = {
343 kind: string;
344 loc?: Location;
345 name: Name;
346 }
347
348 export type InputObjectTypeDefinition = {
349 kind: string;
350 loc?: Location;
351 name: Name;
352 fields: Array<InputValueDefinition>;
353 }
354
355 export type TypeExtensionDefinition = {
356 kind: string;
357 loc?: Location;
358 definition: ObjectTypeDefinition;
359 }
360}