@luvio/graphql-parser 0.62.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/babel.config.js +1 -0
  2. package/dist/argument-node.d.ts +4 -0
  3. package/dist/ast.d.ts +95 -0
  4. package/dist/constants.d.ts +12 -0
  5. package/dist/directive-node.d.ts +5 -0
  6. package/dist/document.d.ts +3 -0
  7. package/dist/field-node.d.ts +4 -0
  8. package/dist/fragment-spread-node.d.ts +4 -0
  9. package/dist/fragment.d.ts +3 -0
  10. package/dist/inline-fragment-node.d.ts +4 -0
  11. package/dist/luvioGraphqlParser.js +3887 -0
  12. package/dist/main.d.ts +4 -0
  13. package/dist/operation/index.d.ts +3 -0
  14. package/dist/operation/query/index.d.ts +6 -0
  15. package/dist/type-node.d.ts +3 -0
  16. package/dist/value-node.d.ts +4 -0
  17. package/dist/variable-definition.d.ts +4 -0
  18. package/dist/visitor.d.ts +4 -0
  19. package/jest.config.js +8 -0
  20. package/package.json +19 -0
  21. package/rollup.config.js +19 -0
  22. package/scripts/cli.mjs +18 -0
  23. package/src/__tests__/ast.spec.ts +109 -0
  24. package/src/__tests__/main.spec.ts +600 -0
  25. package/src/__tests__/type-node.spec.ts +82 -0
  26. package/src/argument-node.ts +18 -0
  27. package/src/ast.ts +200 -0
  28. package/src/constants.ts +14 -0
  29. package/src/directive-node.ts +36 -0
  30. package/src/document.ts +33 -0
  31. package/src/field-node.ts +72 -0
  32. package/src/fragment-spread-node.ts +28 -0
  33. package/src/fragment.ts +46 -0
  34. package/src/inline-fragment-node.ts +31 -0
  35. package/src/main.ts +58 -0
  36. package/src/operation/index.ts +12 -0
  37. package/src/operation/query/index.ts +78 -0
  38. package/src/type-node.ts +39 -0
  39. package/src/value-node.ts +71 -0
  40. package/src/variable-definition.ts +37 -0
  41. package/src/visitor.ts +62 -0
  42. package/tsconfig.json +9 -0
@@ -0,0 +1,3887 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ // In ES2015 (or a polyfilled) environment, this will be Symbol.iterator
6
+
7
+ var SYMBOL_TO_STRING_TAG = typeof Symbol === 'function' && Symbol.toStringTag != null ? Symbol.toStringTag : '@@toStringTag';
8
+
9
+ // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
10
+ var nodejsCustomInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined;
11
+
12
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
13
+ var MAX_ARRAY_LENGTH = 10;
14
+ var MAX_RECURSIVE_DEPTH = 2;
15
+ /**
16
+ * Used to print values in error messages.
17
+ */
18
+
19
+ function inspect(value) {
20
+ return formatValue(value, []);
21
+ }
22
+
23
+ function formatValue(value, seenValues) {
24
+ switch (_typeof(value)) {
25
+ case 'string':
26
+ return JSON.stringify(value);
27
+
28
+ case 'function':
29
+ return value.name ? "[function ".concat(value.name, "]") : '[function]';
30
+
31
+ case 'object':
32
+ if (value === null) {
33
+ return 'null';
34
+ }
35
+
36
+ return formatObjectValue(value, seenValues);
37
+
38
+ default:
39
+ return String(value);
40
+ }
41
+ }
42
+
43
+ function formatObjectValue(value, previouslySeenValues) {
44
+ if (previouslySeenValues.indexOf(value) !== -1) {
45
+ return '[Circular]';
46
+ }
47
+
48
+ var seenValues = [].concat(previouslySeenValues, [value]);
49
+ var customInspectFn = getCustomFn(value);
50
+
51
+ if (customInspectFn !== undefined) {
52
+ var customValue = customInspectFn.call(value); // check for infinite recursion
53
+
54
+ if (customValue !== value) {
55
+ return typeof customValue === 'string' ? customValue : formatValue(customValue, seenValues);
56
+ }
57
+ } else if (Array.isArray(value)) {
58
+ return formatArray(value, seenValues);
59
+ }
60
+
61
+ return formatObject(value, seenValues);
62
+ }
63
+
64
+ function formatObject(object, seenValues) {
65
+ var keys = Object.keys(object);
66
+
67
+ if (keys.length === 0) {
68
+ return '{}';
69
+ }
70
+
71
+ if (seenValues.length > MAX_RECURSIVE_DEPTH) {
72
+ return '[' + getObjectTag(object) + ']';
73
+ }
74
+
75
+ var properties = keys.map(function (key) {
76
+ var value = formatValue(object[key], seenValues);
77
+ return key + ': ' + value;
78
+ });
79
+ return '{ ' + properties.join(', ') + ' }';
80
+ }
81
+
82
+ function formatArray(array, seenValues) {
83
+ if (array.length === 0) {
84
+ return '[]';
85
+ }
86
+
87
+ if (seenValues.length > MAX_RECURSIVE_DEPTH) {
88
+ return '[Array]';
89
+ }
90
+
91
+ var len = Math.min(MAX_ARRAY_LENGTH, array.length);
92
+ var remaining = array.length - len;
93
+ var items = [];
94
+
95
+ for (var i = 0; i < len; ++i) {
96
+ items.push(formatValue(array[i], seenValues));
97
+ }
98
+
99
+ if (remaining === 1) {
100
+ items.push('... 1 more item');
101
+ } else if (remaining > 1) {
102
+ items.push("... ".concat(remaining, " more items"));
103
+ }
104
+
105
+ return '[' + items.join(', ') + ']';
106
+ }
107
+
108
+ function getCustomFn(object) {
109
+ var customInspectFn = object[String(nodejsCustomInspectSymbol)];
110
+
111
+ if (typeof customInspectFn === 'function') {
112
+ return customInspectFn;
113
+ }
114
+
115
+ if (typeof object.inspect === 'function') {
116
+ return object.inspect;
117
+ }
118
+ }
119
+
120
+ function getObjectTag(object) {
121
+ var tag = Object.prototype.toString.call(object).replace(/^\[object /, '').replace(/]$/, '');
122
+
123
+ if (tag === 'Object' && typeof object.constructor === 'function') {
124
+ var name = object.constructor.name;
125
+
126
+ if (typeof name === 'string' && name !== '') {
127
+ return name;
128
+ }
129
+ }
130
+
131
+ return tag;
132
+ }
133
+
134
+ function devAssert(condition, message) {
135
+ var booleanCondition = Boolean(condition); // istanbul ignore else (See transformation done in './resources/inlineInvariant.js')
136
+
137
+ if (!booleanCondition) {
138
+ throw new Error(message);
139
+ }
140
+ }
141
+
142
+ /**
143
+ * A replacement for instanceof which includes an error warning when multi-realm
144
+ * constructors are detected.
145
+ */
146
+ // See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
147
+ // See: https://webpack.js.org/guides/production/
148
+ var instanceOf = process.env.NODE_ENV === 'production' ? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
149
+ // eslint-disable-next-line no-shadow
150
+ function instanceOf(value, constructor) {
151
+ return value instanceof constructor;
152
+ } : // eslint-disable-next-line no-shadow
153
+ function instanceOf(value, constructor) {
154
+ if (value instanceof constructor) {
155
+ return true;
156
+ }
157
+
158
+ if (value) {
159
+ var valueClass = value.constructor;
160
+ var className = constructor.name;
161
+
162
+ if (className && valueClass && valueClass.name === className) {
163
+ throw new Error("Cannot use ".concat(className, " \"").concat(value, "\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results."));
164
+ }
165
+ }
166
+
167
+ return false;
168
+ };
169
+
170
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
171
+
172
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
173
+
174
+ /**
175
+ * A representation of source input to GraphQL. The `name` and `locationOffset` parameters are
176
+ * optional, but they are useful for clients who store GraphQL documents in source files.
177
+ * For example, if the GraphQL input starts at line 40 in a file named `Foo.graphql`, it might
178
+ * be useful for `name` to be `"Foo.graphql"` and location to be `{ line: 40, column: 1 }`.
179
+ * The `line` and `column` properties in `locationOffset` are 1-indexed.
180
+ */
181
+ var Source = /*#__PURE__*/function () {
182
+ function Source(body) {
183
+ var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GraphQL request';
184
+ var locationOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
185
+ line: 1,
186
+ column: 1
187
+ };
188
+ typeof body === 'string' || devAssert(0, "Body must be a string. Received: ".concat(inspect(body), "."));
189
+ this.body = body;
190
+ this.name = name;
191
+ this.locationOffset = locationOffset;
192
+ this.locationOffset.line > 0 || devAssert(0, 'line in locationOffset is 1-indexed and must be positive.');
193
+ this.locationOffset.column > 0 || devAssert(0, 'column in locationOffset is 1-indexed and must be positive.');
194
+ } // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
195
+
196
+
197
+ _createClass(Source, [{
198
+ key: SYMBOL_TO_STRING_TAG,
199
+ get: function get() {
200
+ return 'Source';
201
+ }
202
+ }]);
203
+
204
+ return Source;
205
+ }();
206
+ /**
207
+ * Test if the given value is a Source object.
208
+ *
209
+ * @internal
210
+ */
211
+
212
+ // eslint-disable-next-line no-redeclare
213
+ function isSource(source) {
214
+ return instanceOf(source, Source);
215
+ }
216
+
217
+ /**
218
+ * Represents a location in a Source.
219
+ */
220
+
221
+ /**
222
+ * Takes a Source and a UTF-8 character offset, and returns the corresponding
223
+ * line and column as a SourceLocation.
224
+ */
225
+ function getLocation(source, position) {
226
+ var lineRegexp = /\r\n|[\n\r]/g;
227
+ var line = 1;
228
+ var column = position + 1;
229
+ var match;
230
+
231
+ while ((match = lineRegexp.exec(source.body)) && match.index < position) {
232
+ line += 1;
233
+ column = position + 1 - (match.index + match[0].length);
234
+ }
235
+
236
+ return {
237
+ line: line,
238
+ column: column
239
+ };
240
+ }
241
+
242
+ /**
243
+ * Render a helpful description of the location in the GraphQL Source document.
244
+ */
245
+
246
+ function printLocation(location) {
247
+ return printSourceLocation(location.source, getLocation(location.source, location.start));
248
+ }
249
+ /**
250
+ * Render a helpful description of the location in the GraphQL Source document.
251
+ */
252
+
253
+ function printSourceLocation(source, sourceLocation) {
254
+ var firstLineColumnOffset = source.locationOffset.column - 1;
255
+ var body = whitespace(firstLineColumnOffset) + source.body;
256
+ var lineIndex = sourceLocation.line - 1;
257
+ var lineOffset = source.locationOffset.line - 1;
258
+ var lineNum = sourceLocation.line + lineOffset;
259
+ var columnOffset = sourceLocation.line === 1 ? firstLineColumnOffset : 0;
260
+ var columnNum = sourceLocation.column + columnOffset;
261
+ var locationStr = "".concat(source.name, ":").concat(lineNum, ":").concat(columnNum, "\n");
262
+ var lines = body.split(/\r\n|[\n\r]/g);
263
+ var locationLine = lines[lineIndex]; // Special case for minified documents
264
+
265
+ if (locationLine.length > 120) {
266
+ var subLineIndex = Math.floor(columnNum / 80);
267
+ var subLineColumnNum = columnNum % 80;
268
+ var subLines = [];
269
+
270
+ for (var i = 0; i < locationLine.length; i += 80) {
271
+ subLines.push(locationLine.slice(i, i + 80));
272
+ }
273
+
274
+ return locationStr + printPrefixedLines([["".concat(lineNum), subLines[0]]].concat(subLines.slice(1, subLineIndex + 1).map(function (subLine) {
275
+ return ['', subLine];
276
+ }), [[' ', whitespace(subLineColumnNum - 1) + '^'], ['', subLines[subLineIndex + 1]]]));
277
+ }
278
+
279
+ return locationStr + printPrefixedLines([// Lines specified like this: ["prefix", "string"],
280
+ ["".concat(lineNum - 1), lines[lineIndex - 1]], ["".concat(lineNum), locationLine], ['', whitespace(columnNum - 1) + '^'], ["".concat(lineNum + 1), lines[lineIndex + 1]]]);
281
+ }
282
+
283
+ function printPrefixedLines(lines) {
284
+ var existingLines = lines.filter(function (_ref) {
285
+ var _ = _ref[0],
286
+ line = _ref[1];
287
+ return line !== undefined;
288
+ });
289
+ var padLen = Math.max.apply(Math, existingLines.map(function (_ref2) {
290
+ var prefix = _ref2[0];
291
+ return prefix.length;
292
+ }));
293
+ return existingLines.map(function (_ref3) {
294
+ var prefix = _ref3[0],
295
+ line = _ref3[1];
296
+ return leftPad(padLen, prefix) + (line ? ' | ' + line : ' |');
297
+ }).join('\n');
298
+ }
299
+
300
+ function whitespace(len) {
301
+ return Array(len + 1).join(' ');
302
+ }
303
+
304
+ function leftPad(len, str) {
305
+ return whitespace(len - str.length) + str;
306
+ }
307
+
308
+ /**
309
+ * The set of allowed kind values for AST nodes.
310
+ */
311
+ var Kind = Object.freeze({
312
+ // Name
313
+ NAME: 'Name',
314
+ // Document
315
+ DOCUMENT: 'Document',
316
+ OPERATION_DEFINITION: 'OperationDefinition',
317
+ VARIABLE_DEFINITION: 'VariableDefinition',
318
+ SELECTION_SET: 'SelectionSet',
319
+ FIELD: 'Field',
320
+ ARGUMENT: 'Argument',
321
+ // Fragments
322
+ FRAGMENT_SPREAD: 'FragmentSpread',
323
+ INLINE_FRAGMENT: 'InlineFragment',
324
+ FRAGMENT_DEFINITION: 'FragmentDefinition',
325
+ // Values
326
+ VARIABLE: 'Variable',
327
+ INT: 'IntValue',
328
+ FLOAT: 'FloatValue',
329
+ STRING: 'StringValue',
330
+ BOOLEAN: 'BooleanValue',
331
+ NULL: 'NullValue',
332
+ ENUM: 'EnumValue',
333
+ LIST: 'ListValue',
334
+ OBJECT: 'ObjectValue',
335
+ OBJECT_FIELD: 'ObjectField',
336
+ // Directives
337
+ DIRECTIVE: 'Directive',
338
+ // Types
339
+ NAMED_TYPE: 'NamedType',
340
+ LIST_TYPE: 'ListType',
341
+ NON_NULL_TYPE: 'NonNullType',
342
+ // Type System Definitions
343
+ SCHEMA_DEFINITION: 'SchemaDefinition',
344
+ OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition',
345
+ // Type Definitions
346
+ SCALAR_TYPE_DEFINITION: 'ScalarTypeDefinition',
347
+ OBJECT_TYPE_DEFINITION: 'ObjectTypeDefinition',
348
+ FIELD_DEFINITION: 'FieldDefinition',
349
+ INPUT_VALUE_DEFINITION: 'InputValueDefinition',
350
+ INTERFACE_TYPE_DEFINITION: 'InterfaceTypeDefinition',
351
+ UNION_TYPE_DEFINITION: 'UnionTypeDefinition',
352
+ ENUM_TYPE_DEFINITION: 'EnumTypeDefinition',
353
+ ENUM_VALUE_DEFINITION: 'EnumValueDefinition',
354
+ INPUT_OBJECT_TYPE_DEFINITION: 'InputObjectTypeDefinition',
355
+ // Directive Definitions
356
+ DIRECTIVE_DEFINITION: 'DirectiveDefinition',
357
+ // Type System Extensions
358
+ SCHEMA_EXTENSION: 'SchemaExtension',
359
+ // Type Extensions
360
+ SCALAR_TYPE_EXTENSION: 'ScalarTypeExtension',
361
+ OBJECT_TYPE_EXTENSION: 'ObjectTypeExtension',
362
+ INTERFACE_TYPE_EXTENSION: 'InterfaceTypeExtension',
363
+ UNION_TYPE_EXTENSION: 'UnionTypeExtension',
364
+ ENUM_TYPE_EXTENSION: 'EnumTypeExtension',
365
+ INPUT_OBJECT_TYPE_EXTENSION: 'InputObjectTypeExtension'
366
+ });
367
+ /**
368
+ * The enum type representing the possible kind values of AST nodes.
369
+ */
370
+
371
+ /**
372
+ * An exported enum describing the different kinds of tokens that the
373
+ * lexer emits.
374
+ */
375
+ var TokenKind = Object.freeze({
376
+ SOF: '<SOF>',
377
+ EOF: '<EOF>',
378
+ BANG: '!',
379
+ DOLLAR: '$',
380
+ AMP: '&',
381
+ PAREN_L: '(',
382
+ PAREN_R: ')',
383
+ SPREAD: '...',
384
+ COLON: ':',
385
+ EQUALS: '=',
386
+ AT: '@',
387
+ BRACKET_L: '[',
388
+ BRACKET_R: ']',
389
+ BRACE_L: '{',
390
+ PIPE: '|',
391
+ BRACE_R: '}',
392
+ NAME: 'Name',
393
+ INT: 'Int',
394
+ FLOAT: 'Float',
395
+ STRING: 'String',
396
+ BLOCK_STRING: 'BlockString',
397
+ COMMENT: 'Comment'
398
+ });
399
+ /**
400
+ * The enum type representing the token kinds values.
401
+ */
402
+
403
+ function _typeof$1(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); }
404
+
405
+ /**
406
+ * Return true if `value` is object-like. A value is object-like if it's not
407
+ * `null` and has a `typeof` result of "object".
408
+ */
409
+ function isObjectLike(value) {
410
+ return _typeof$1(value) == 'object' && value !== null;
411
+ }
412
+
413
+ function _typeof$2(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$2 = function _typeof(obj) { return typeof obj; }; } else { _typeof$2 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$2(obj); }
414
+
415
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
416
+
417
+ function _defineProperties$1(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
418
+
419
+ function _createClass$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1(Constructor, staticProps); return Constructor; }
420
+
421
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
422
+
423
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
424
+
425
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof$2(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
426
+
427
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
428
+
429
+ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
430
+
431
+ function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
432
+
433
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
434
+
435
+ function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
436
+
437
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
438
+
439
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
440
+ /**
441
+ * A GraphQLError describes an Error found during the parse, validate, or
442
+ * execute phases of performing a GraphQL operation. In addition to a message
443
+ * and stack trace, it also includes information about the locations in a
444
+ * GraphQL document and/or execution result that correspond to the Error.
445
+ */
446
+
447
+ var GraphQLError = /*#__PURE__*/function (_Error) {
448
+ _inherits(GraphQLError, _Error);
449
+
450
+ var _super = _createSuper(GraphQLError);
451
+
452
+ /**
453
+ * A message describing the Error for debugging purposes.
454
+ *
455
+ * Enumerable, and appears in the result of JSON.stringify().
456
+ *
457
+ * Note: should be treated as readonly, despite invariant usage.
458
+ */
459
+
460
+ /**
461
+ * An array of { line, column } locations within the source GraphQL document
462
+ * which correspond to this error.
463
+ *
464
+ * Errors during validation often contain multiple locations, for example to
465
+ * point out two things with the same name. Errors during execution include a
466
+ * single location, the field which produced the error.
467
+ *
468
+ * Enumerable, and appears in the result of JSON.stringify().
469
+ */
470
+
471
+ /**
472
+ * An array describing the JSON-path into the execution response which
473
+ * corresponds to this error. Only included for errors during execution.
474
+ *
475
+ * Enumerable, and appears in the result of JSON.stringify().
476
+ */
477
+
478
+ /**
479
+ * An array of GraphQL AST Nodes corresponding to this error.
480
+ */
481
+
482
+ /**
483
+ * The source GraphQL document for the first location of this error.
484
+ *
485
+ * Note that if this Error represents more than one node, the source may not
486
+ * represent nodes after the first node.
487
+ */
488
+
489
+ /**
490
+ * An array of character offsets within the source GraphQL document
491
+ * which correspond to this error.
492
+ */
493
+
494
+ /**
495
+ * The original error thrown from a field resolver during execution.
496
+ */
497
+
498
+ /**
499
+ * Extension fields to add to the formatted error.
500
+ */
501
+ function GraphQLError(message, nodes, source, positions, path, originalError, extensions) {
502
+ var _locations2, _source2, _positions2, _extensions2;
503
+
504
+ var _this;
505
+
506
+ _classCallCheck(this, GraphQLError);
507
+
508
+ _this = _super.call(this, message); // Compute list of blame nodes.
509
+
510
+ var _nodes = Array.isArray(nodes) ? nodes.length !== 0 ? nodes : undefined : nodes ? [nodes] : undefined; // Compute locations in the source for the given nodes/positions.
511
+
512
+
513
+ var _source = source;
514
+
515
+ if (!_source && _nodes) {
516
+ var _nodes$0$loc;
517
+
518
+ _source = (_nodes$0$loc = _nodes[0].loc) === null || _nodes$0$loc === void 0 ? void 0 : _nodes$0$loc.source;
519
+ }
520
+
521
+ var _positions = positions;
522
+
523
+ if (!_positions && _nodes) {
524
+ _positions = _nodes.reduce(function (list, node) {
525
+ if (node.loc) {
526
+ list.push(node.loc.start);
527
+ }
528
+
529
+ return list;
530
+ }, []);
531
+ }
532
+
533
+ if (_positions && _positions.length === 0) {
534
+ _positions = undefined;
535
+ }
536
+
537
+ var _locations;
538
+
539
+ if (positions && source) {
540
+ _locations = positions.map(function (pos) {
541
+ return getLocation(source, pos);
542
+ });
543
+ } else if (_nodes) {
544
+ _locations = _nodes.reduce(function (list, node) {
545
+ if (node.loc) {
546
+ list.push(getLocation(node.loc.source, node.loc.start));
547
+ }
548
+
549
+ return list;
550
+ }, []);
551
+ }
552
+
553
+ var _extensions = extensions;
554
+
555
+ if (_extensions == null && originalError != null) {
556
+ var originalExtensions = originalError.extensions;
557
+
558
+ if (isObjectLike(originalExtensions)) {
559
+ _extensions = originalExtensions;
560
+ }
561
+ }
562
+
563
+ Object.defineProperties(_assertThisInitialized(_this), {
564
+ name: {
565
+ value: 'GraphQLError'
566
+ },
567
+ message: {
568
+ value: message,
569
+ // By being enumerable, JSON.stringify will include `message` in the
570
+ // resulting output. This ensures that the simplest possible GraphQL
571
+ // service adheres to the spec.
572
+ enumerable: true,
573
+ writable: true
574
+ },
575
+ locations: {
576
+ // Coercing falsy values to undefined ensures they will not be included
577
+ // in JSON.stringify() when not provided.
578
+ value: (_locations2 = _locations) !== null && _locations2 !== void 0 ? _locations2 : undefined,
579
+ // By being enumerable, JSON.stringify will include `locations` in the
580
+ // resulting output. This ensures that the simplest possible GraphQL
581
+ // service adheres to the spec.
582
+ enumerable: _locations != null
583
+ },
584
+ path: {
585
+ // Coercing falsy values to undefined ensures they will not be included
586
+ // in JSON.stringify() when not provided.
587
+ value: path !== null && path !== void 0 ? path : undefined,
588
+ // By being enumerable, JSON.stringify will include `path` in the
589
+ // resulting output. This ensures that the simplest possible GraphQL
590
+ // service adheres to the spec.
591
+ enumerable: path != null
592
+ },
593
+ nodes: {
594
+ value: _nodes !== null && _nodes !== void 0 ? _nodes : undefined
595
+ },
596
+ source: {
597
+ value: (_source2 = _source) !== null && _source2 !== void 0 ? _source2 : undefined
598
+ },
599
+ positions: {
600
+ value: (_positions2 = _positions) !== null && _positions2 !== void 0 ? _positions2 : undefined
601
+ },
602
+ originalError: {
603
+ value: originalError
604
+ },
605
+ extensions: {
606
+ // Coercing falsy values to undefined ensures they will not be included
607
+ // in JSON.stringify() when not provided.
608
+ value: (_extensions2 = _extensions) !== null && _extensions2 !== void 0 ? _extensions2 : undefined,
609
+ // By being enumerable, JSON.stringify will include `path` in the
610
+ // resulting output. This ensures that the simplest possible GraphQL
611
+ // service adheres to the spec.
612
+ enumerable: _extensions != null
613
+ }
614
+ }); // Include (non-enumerable) stack trace.
615
+
616
+ if (originalError !== null && originalError !== void 0 && originalError.stack) {
617
+ Object.defineProperty(_assertThisInitialized(_this), 'stack', {
618
+ value: originalError.stack,
619
+ writable: true,
620
+ configurable: true
621
+ });
622
+ return _possibleConstructorReturn(_this);
623
+ } // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
624
+
625
+
626
+ if (Error.captureStackTrace) {
627
+ Error.captureStackTrace(_assertThisInitialized(_this), GraphQLError);
628
+ } else {
629
+ Object.defineProperty(_assertThisInitialized(_this), 'stack', {
630
+ value: Error().stack,
631
+ writable: true,
632
+ configurable: true
633
+ });
634
+ }
635
+
636
+ return _this;
637
+ }
638
+
639
+ _createClass$1(GraphQLError, [{
640
+ key: "toString",
641
+ value: function toString() {
642
+ return printError(this);
643
+ } // FIXME: workaround to not break chai comparisons, should be remove in v16
644
+ // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
645
+
646
+ }, {
647
+ key: SYMBOL_TO_STRING_TAG,
648
+ get: function get() {
649
+ return 'Object';
650
+ }
651
+ }]);
652
+
653
+ return GraphQLError;
654
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
655
+ /**
656
+ * Prints a GraphQLError to a string, representing useful location information
657
+ * about the error's position in the source.
658
+ */
659
+
660
+ function printError(error) {
661
+ var output = error.message;
662
+
663
+ if (error.nodes) {
664
+ for (var _i2 = 0, _error$nodes2 = error.nodes; _i2 < _error$nodes2.length; _i2++) {
665
+ var node = _error$nodes2[_i2];
666
+
667
+ if (node.loc) {
668
+ output += '\n\n' + printLocation(node.loc);
669
+ }
670
+ }
671
+ } else if (error.source && error.locations) {
672
+ for (var _i4 = 0, _error$locations2 = error.locations; _i4 < _error$locations2.length; _i4++) {
673
+ var location = _error$locations2[_i4];
674
+ output += '\n\n' + printSourceLocation(error.source, location);
675
+ }
676
+ }
677
+
678
+ return output;
679
+ }
680
+
681
+ /**
682
+ * Produces a GraphQLError representing a syntax error, containing useful
683
+ * descriptive information about the syntax error's position in the source.
684
+ */
685
+
686
+ function syntaxError(source, position, description) {
687
+ return new GraphQLError("Syntax Error: ".concat(description), undefined, source, [position]);
688
+ }
689
+
690
+ function invariant(condition, message) {
691
+ var booleanCondition = Boolean(condition); // istanbul ignore else (See transformation done in './resources/inlineInvariant.js')
692
+
693
+ if (!booleanCondition) {
694
+ throw new Error(message != null ? message : 'Unexpected invariant triggered.');
695
+ }
696
+ }
697
+
698
+ /**
699
+ * The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`
700
+ */
701
+
702
+ function defineInspect(classObject) {
703
+ var fn = classObject.prototype.toJSON;
704
+ typeof fn === 'function' || invariant(0);
705
+ classObject.prototype.inspect = fn; // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2317')
706
+
707
+ if (nodejsCustomInspectSymbol) {
708
+ classObject.prototype[nodejsCustomInspectSymbol] = fn;
709
+ }
710
+ }
711
+
712
+ /**
713
+ * Contains a range of UTF-8 character offsets and token references that
714
+ * identify the region of the source from which the AST derived.
715
+ */
716
+ var Location = /*#__PURE__*/function () {
717
+ /**
718
+ * The character offset at which this Node begins.
719
+ */
720
+
721
+ /**
722
+ * The character offset at which this Node ends.
723
+ */
724
+
725
+ /**
726
+ * The Token at which this Node begins.
727
+ */
728
+
729
+ /**
730
+ * The Token at which this Node ends.
731
+ */
732
+
733
+ /**
734
+ * The Source document the AST represents.
735
+ */
736
+ function Location(startToken, endToken, source) {
737
+ this.start = startToken.start;
738
+ this.end = endToken.end;
739
+ this.startToken = startToken;
740
+ this.endToken = endToken;
741
+ this.source = source;
742
+ }
743
+
744
+ var _proto = Location.prototype;
745
+
746
+ _proto.toJSON = function toJSON() {
747
+ return {
748
+ start: this.start,
749
+ end: this.end
750
+ };
751
+ };
752
+
753
+ return Location;
754
+ }(); // Print a simplified form when appearing in `inspect` and `util.inspect`.
755
+
756
+ defineInspect(Location);
757
+ /**
758
+ * Represents a range of characters represented by a lexical token
759
+ * within a Source.
760
+ */
761
+
762
+ var Token = /*#__PURE__*/function () {
763
+ /**
764
+ * The kind of Token.
765
+ */
766
+
767
+ /**
768
+ * The character offset at which this Node begins.
769
+ */
770
+
771
+ /**
772
+ * The character offset at which this Node ends.
773
+ */
774
+
775
+ /**
776
+ * The 1-indexed line number on which this Token appears.
777
+ */
778
+
779
+ /**
780
+ * The 1-indexed column number at which this Token begins.
781
+ */
782
+
783
+ /**
784
+ * For non-punctuation tokens, represents the interpreted value of the token.
785
+ */
786
+
787
+ /**
788
+ * Tokens exist as nodes in a double-linked-list amongst all tokens
789
+ * including ignored tokens. <SOF> is always the first node and <EOF>
790
+ * the last.
791
+ */
792
+ function Token(kind, start, end, line, column, prev, value) {
793
+ this.kind = kind;
794
+ this.start = start;
795
+ this.end = end;
796
+ this.line = line;
797
+ this.column = column;
798
+ this.value = value;
799
+ this.prev = prev;
800
+ this.next = null;
801
+ }
802
+
803
+ var _proto2 = Token.prototype;
804
+
805
+ _proto2.toJSON = function toJSON() {
806
+ return {
807
+ kind: this.kind,
808
+ value: this.value,
809
+ line: this.line,
810
+ column: this.column
811
+ };
812
+ };
813
+
814
+ return Token;
815
+ }(); // Print a simplified form when appearing in `inspect` and `util.inspect`.
816
+
817
+ defineInspect(Token);
818
+ /**
819
+ * @internal
820
+ */
821
+
822
+ function isNode(maybeNode) {
823
+ return maybeNode != null && typeof maybeNode.kind === 'string';
824
+ }
825
+ /**
826
+ * The list of all possible AST node types.
827
+ */
828
+
829
+ /**
830
+ * Produces the value of a block string from its parsed raw value, similar to
831
+ * CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc.
832
+ *
833
+ * This implements the GraphQL spec's BlockStringValue() static algorithm.
834
+ *
835
+ * @internal
836
+ */
837
+ function dedentBlockStringValue(rawString) {
838
+ // Expand a block string's raw value into independent lines.
839
+ var lines = rawString.split(/\r\n|[\n\r]/g); // Remove common indentation from all lines but first.
840
+
841
+ var commonIndent = getBlockStringIndentation(rawString);
842
+
843
+ if (commonIndent !== 0) {
844
+ for (var i = 1; i < lines.length; i++) {
845
+ lines[i] = lines[i].slice(commonIndent);
846
+ }
847
+ } // Remove leading and trailing blank lines.
848
+
849
+
850
+ var startLine = 0;
851
+
852
+ while (startLine < lines.length && isBlank(lines[startLine])) {
853
+ ++startLine;
854
+ }
855
+
856
+ var endLine = lines.length;
857
+
858
+ while (endLine > startLine && isBlank(lines[endLine - 1])) {
859
+ --endLine;
860
+ } // Return a string of the lines joined with U+000A.
861
+
862
+
863
+ return lines.slice(startLine, endLine).join('\n');
864
+ }
865
+
866
+ function isBlank(str) {
867
+ for (var i = 0; i < str.length; ++i) {
868
+ if (str[i] !== ' ' && str[i] !== '\t') {
869
+ return false;
870
+ }
871
+ }
872
+
873
+ return true;
874
+ }
875
+ /**
876
+ * @internal
877
+ */
878
+
879
+
880
+ function getBlockStringIndentation(value) {
881
+ var _commonIndent;
882
+
883
+ var isFirstLine = true;
884
+ var isEmptyLine = true;
885
+ var indent = 0;
886
+ var commonIndent = null;
887
+
888
+ for (var i = 0; i < value.length; ++i) {
889
+ switch (value.charCodeAt(i)) {
890
+ case 13:
891
+ // \r
892
+ if (value.charCodeAt(i + 1) === 10) {
893
+ ++i; // skip \r\n as one symbol
894
+ }
895
+
896
+ // falls through
897
+
898
+ case 10:
899
+ // \n
900
+ isFirstLine = false;
901
+ isEmptyLine = true;
902
+ indent = 0;
903
+ break;
904
+
905
+ case 9: // \t
906
+
907
+ case 32:
908
+ // <space>
909
+ ++indent;
910
+ break;
911
+
912
+ default:
913
+ if (isEmptyLine && !isFirstLine && (commonIndent === null || indent < commonIndent)) {
914
+ commonIndent = indent;
915
+ }
916
+
917
+ isEmptyLine = false;
918
+ }
919
+ }
920
+
921
+ return (_commonIndent = commonIndent) !== null && _commonIndent !== void 0 ? _commonIndent : 0;
922
+ }
923
+
924
+ /**
925
+ * Given a Source object, creates a Lexer for that source.
926
+ * A Lexer is a stateful stream generator in that every time
927
+ * it is advanced, it returns the next token in the Source. Assuming the
928
+ * source lexes, the final Token emitted by the lexer will be of kind
929
+ * EOF, after which the lexer will repeatedly return the same EOF token
930
+ * whenever called.
931
+ */
932
+
933
+ var Lexer = /*#__PURE__*/function () {
934
+ /**
935
+ * The previously focused non-ignored token.
936
+ */
937
+
938
+ /**
939
+ * The currently focused non-ignored token.
940
+ */
941
+
942
+ /**
943
+ * The (1-indexed) line containing the current token.
944
+ */
945
+
946
+ /**
947
+ * The character offset at which the current line begins.
948
+ */
949
+ function Lexer(source) {
950
+ var startOfFileToken = new Token(TokenKind.SOF, 0, 0, 0, 0, null);
951
+ this.source = source;
952
+ this.lastToken = startOfFileToken;
953
+ this.token = startOfFileToken;
954
+ this.line = 1;
955
+ this.lineStart = 0;
956
+ }
957
+ /**
958
+ * Advances the token stream to the next non-ignored token.
959
+ */
960
+
961
+
962
+ var _proto = Lexer.prototype;
963
+
964
+ _proto.advance = function advance() {
965
+ this.lastToken = this.token;
966
+ var token = this.token = this.lookahead();
967
+ return token;
968
+ }
969
+ /**
970
+ * Looks ahead and returns the next non-ignored token, but does not change
971
+ * the state of Lexer.
972
+ */
973
+ ;
974
+
975
+ _proto.lookahead = function lookahead() {
976
+ var token = this.token;
977
+
978
+ if (token.kind !== TokenKind.EOF) {
979
+ do {
980
+ var _token$next;
981
+
982
+ // Note: next is only mutable during parsing, so we cast to allow this.
983
+ token = (_token$next = token.next) !== null && _token$next !== void 0 ? _token$next : token.next = readToken(this, token);
984
+ } while (token.kind === TokenKind.COMMENT);
985
+ }
986
+
987
+ return token;
988
+ };
989
+
990
+ return Lexer;
991
+ }();
992
+ /**
993
+ * @internal
994
+ */
995
+
996
+ function isPunctuatorTokenKind(kind) {
997
+ return kind === TokenKind.BANG || kind === TokenKind.DOLLAR || kind === TokenKind.AMP || kind === TokenKind.PAREN_L || kind === TokenKind.PAREN_R || kind === TokenKind.SPREAD || kind === TokenKind.COLON || kind === TokenKind.EQUALS || kind === TokenKind.AT || kind === TokenKind.BRACKET_L || kind === TokenKind.BRACKET_R || kind === TokenKind.BRACE_L || kind === TokenKind.PIPE || kind === TokenKind.BRACE_R;
998
+ }
999
+
1000
+ function printCharCode(code) {
1001
+ return (// NaN/undefined represents access beyond the end of the file.
1002
+ isNaN(code) ? TokenKind.EOF : // Trust JSON for ASCII.
1003
+ code < 0x007f ? JSON.stringify(String.fromCharCode(code)) : // Otherwise print the escaped form.
1004
+ "\"\\u".concat(('00' + code.toString(16).toUpperCase()).slice(-4), "\"")
1005
+ );
1006
+ }
1007
+ /**
1008
+ * Gets the next token from the source starting at the given position.
1009
+ *
1010
+ * This skips over whitespace until it finds the next lexable token, then lexes
1011
+ * punctuators immediately or calls the appropriate helper function for more
1012
+ * complicated tokens.
1013
+ */
1014
+
1015
+
1016
+ function readToken(lexer, prev) {
1017
+ var source = lexer.source;
1018
+ var body = source.body;
1019
+ var bodyLength = body.length;
1020
+ var pos = prev.end;
1021
+
1022
+ while (pos < bodyLength) {
1023
+ var code = body.charCodeAt(pos);
1024
+ var _line = lexer.line;
1025
+
1026
+ var _col = 1 + pos - lexer.lineStart; // SourceCharacter
1027
+
1028
+
1029
+ switch (code) {
1030
+ case 0xfeff: // <BOM>
1031
+
1032
+ case 9: // \t
1033
+
1034
+ case 32: // <space>
1035
+
1036
+ case 44:
1037
+ // ,
1038
+ ++pos;
1039
+ continue;
1040
+
1041
+ case 10:
1042
+ // \n
1043
+ ++pos;
1044
+ ++lexer.line;
1045
+ lexer.lineStart = pos;
1046
+ continue;
1047
+
1048
+ case 13:
1049
+ // \r
1050
+ if (body.charCodeAt(pos + 1) === 10) {
1051
+ pos += 2;
1052
+ } else {
1053
+ ++pos;
1054
+ }
1055
+
1056
+ ++lexer.line;
1057
+ lexer.lineStart = pos;
1058
+ continue;
1059
+
1060
+ case 33:
1061
+ // !
1062
+ return new Token(TokenKind.BANG, pos, pos + 1, _line, _col, prev);
1063
+
1064
+ case 35:
1065
+ // #
1066
+ return readComment(source, pos, _line, _col, prev);
1067
+
1068
+ case 36:
1069
+ // $
1070
+ return new Token(TokenKind.DOLLAR, pos, pos + 1, _line, _col, prev);
1071
+
1072
+ case 38:
1073
+ // &
1074
+ return new Token(TokenKind.AMP, pos, pos + 1, _line, _col, prev);
1075
+
1076
+ case 40:
1077
+ // (
1078
+ return new Token(TokenKind.PAREN_L, pos, pos + 1, _line, _col, prev);
1079
+
1080
+ case 41:
1081
+ // )
1082
+ return new Token(TokenKind.PAREN_R, pos, pos + 1, _line, _col, prev);
1083
+
1084
+ case 46:
1085
+ // .
1086
+ if (body.charCodeAt(pos + 1) === 46 && body.charCodeAt(pos + 2) === 46) {
1087
+ return new Token(TokenKind.SPREAD, pos, pos + 3, _line, _col, prev);
1088
+ }
1089
+
1090
+ break;
1091
+
1092
+ case 58:
1093
+ // :
1094
+ return new Token(TokenKind.COLON, pos, pos + 1, _line, _col, prev);
1095
+
1096
+ case 61:
1097
+ // =
1098
+ return new Token(TokenKind.EQUALS, pos, pos + 1, _line, _col, prev);
1099
+
1100
+ case 64:
1101
+ // @
1102
+ return new Token(TokenKind.AT, pos, pos + 1, _line, _col, prev);
1103
+
1104
+ case 91:
1105
+ // [
1106
+ return new Token(TokenKind.BRACKET_L, pos, pos + 1, _line, _col, prev);
1107
+
1108
+ case 93:
1109
+ // ]
1110
+ return new Token(TokenKind.BRACKET_R, pos, pos + 1, _line, _col, prev);
1111
+
1112
+ case 123:
1113
+ // {
1114
+ return new Token(TokenKind.BRACE_L, pos, pos + 1, _line, _col, prev);
1115
+
1116
+ case 124:
1117
+ // |
1118
+ return new Token(TokenKind.PIPE, pos, pos + 1, _line, _col, prev);
1119
+
1120
+ case 125:
1121
+ // }
1122
+ return new Token(TokenKind.BRACE_R, pos, pos + 1, _line, _col, prev);
1123
+
1124
+ case 34:
1125
+ // "
1126
+ if (body.charCodeAt(pos + 1) === 34 && body.charCodeAt(pos + 2) === 34) {
1127
+ return readBlockString(source, pos, _line, _col, prev, lexer);
1128
+ }
1129
+
1130
+ return readString(source, pos, _line, _col, prev);
1131
+
1132
+ case 45: // -
1133
+
1134
+ case 48: // 0
1135
+
1136
+ case 49: // 1
1137
+
1138
+ case 50: // 2
1139
+
1140
+ case 51: // 3
1141
+
1142
+ case 52: // 4
1143
+
1144
+ case 53: // 5
1145
+
1146
+ case 54: // 6
1147
+
1148
+ case 55: // 7
1149
+
1150
+ case 56: // 8
1151
+
1152
+ case 57:
1153
+ // 9
1154
+ return readNumber(source, pos, code, _line, _col, prev);
1155
+
1156
+ case 65: // A
1157
+
1158
+ case 66: // B
1159
+
1160
+ case 67: // C
1161
+
1162
+ case 68: // D
1163
+
1164
+ case 69: // E
1165
+
1166
+ case 70: // F
1167
+
1168
+ case 71: // G
1169
+
1170
+ case 72: // H
1171
+
1172
+ case 73: // I
1173
+
1174
+ case 74: // J
1175
+
1176
+ case 75: // K
1177
+
1178
+ case 76: // L
1179
+
1180
+ case 77: // M
1181
+
1182
+ case 78: // N
1183
+
1184
+ case 79: // O
1185
+
1186
+ case 80: // P
1187
+
1188
+ case 81: // Q
1189
+
1190
+ case 82: // R
1191
+
1192
+ case 83: // S
1193
+
1194
+ case 84: // T
1195
+
1196
+ case 85: // U
1197
+
1198
+ case 86: // V
1199
+
1200
+ case 87: // W
1201
+
1202
+ case 88: // X
1203
+
1204
+ case 89: // Y
1205
+
1206
+ case 90: // Z
1207
+
1208
+ case 95: // _
1209
+
1210
+ case 97: // a
1211
+
1212
+ case 98: // b
1213
+
1214
+ case 99: // c
1215
+
1216
+ case 100: // d
1217
+
1218
+ case 101: // e
1219
+
1220
+ case 102: // f
1221
+
1222
+ case 103: // g
1223
+
1224
+ case 104: // h
1225
+
1226
+ case 105: // i
1227
+
1228
+ case 106: // j
1229
+
1230
+ case 107: // k
1231
+
1232
+ case 108: // l
1233
+
1234
+ case 109: // m
1235
+
1236
+ case 110: // n
1237
+
1238
+ case 111: // o
1239
+
1240
+ case 112: // p
1241
+
1242
+ case 113: // q
1243
+
1244
+ case 114: // r
1245
+
1246
+ case 115: // s
1247
+
1248
+ case 116: // t
1249
+
1250
+ case 117: // u
1251
+
1252
+ case 118: // v
1253
+
1254
+ case 119: // w
1255
+
1256
+ case 120: // x
1257
+
1258
+ case 121: // y
1259
+
1260
+ case 122:
1261
+ // z
1262
+ return readName(source, pos, _line, _col, prev);
1263
+ }
1264
+
1265
+ throw syntaxError(source, pos, unexpectedCharacterMessage(code));
1266
+ }
1267
+
1268
+ var line = lexer.line;
1269
+ var col = 1 + pos - lexer.lineStart;
1270
+ return new Token(TokenKind.EOF, bodyLength, bodyLength, line, col, prev);
1271
+ }
1272
+ /**
1273
+ * Report a message that an unexpected character was encountered.
1274
+ */
1275
+
1276
+
1277
+ function unexpectedCharacterMessage(code) {
1278
+ if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
1279
+ return "Cannot contain the invalid character ".concat(printCharCode(code), ".");
1280
+ }
1281
+
1282
+ if (code === 39) {
1283
+ // '
1284
+ return 'Unexpected single quote character (\'), did you mean to use a double quote (")?';
1285
+ }
1286
+
1287
+ return "Cannot parse the unexpected character ".concat(printCharCode(code), ".");
1288
+ }
1289
+ /**
1290
+ * Reads a comment token from the source file.
1291
+ *
1292
+ * #[\u0009\u0020-\uFFFF]*
1293
+ */
1294
+
1295
+
1296
+ function readComment(source, start, line, col, prev) {
1297
+ var body = source.body;
1298
+ var code;
1299
+ var position = start;
1300
+
1301
+ do {
1302
+ code = body.charCodeAt(++position);
1303
+ } while (!isNaN(code) && ( // SourceCharacter but not LineTerminator
1304
+ code > 0x001f || code === 0x0009));
1305
+
1306
+ return new Token(TokenKind.COMMENT, start, position, line, col, prev, body.slice(start + 1, position));
1307
+ }
1308
+ /**
1309
+ * Reads a number token from the source file, either a float
1310
+ * or an int depending on whether a decimal point appears.
1311
+ *
1312
+ * Int: -?(0|[1-9][0-9]*)
1313
+ * Float: -?(0|[1-9][0-9]*)(\.[0-9]+)?((E|e)(+|-)?[0-9]+)?
1314
+ */
1315
+
1316
+
1317
+ function readNumber(source, start, firstCode, line, col, prev) {
1318
+ var body = source.body;
1319
+ var code = firstCode;
1320
+ var position = start;
1321
+ var isFloat = false;
1322
+
1323
+ if (code === 45) {
1324
+ // -
1325
+ code = body.charCodeAt(++position);
1326
+ }
1327
+
1328
+ if (code === 48) {
1329
+ // 0
1330
+ code = body.charCodeAt(++position);
1331
+
1332
+ if (code >= 48 && code <= 57) {
1333
+ throw syntaxError(source, position, "Invalid number, unexpected digit after 0: ".concat(printCharCode(code), "."));
1334
+ }
1335
+ } else {
1336
+ position = readDigits(source, position, code);
1337
+ code = body.charCodeAt(position);
1338
+ }
1339
+
1340
+ if (code === 46) {
1341
+ // .
1342
+ isFloat = true;
1343
+ code = body.charCodeAt(++position);
1344
+ position = readDigits(source, position, code);
1345
+ code = body.charCodeAt(position);
1346
+ }
1347
+
1348
+ if (code === 69 || code === 101) {
1349
+ // E e
1350
+ isFloat = true;
1351
+ code = body.charCodeAt(++position);
1352
+
1353
+ if (code === 43 || code === 45) {
1354
+ // + -
1355
+ code = body.charCodeAt(++position);
1356
+ }
1357
+
1358
+ position = readDigits(source, position, code);
1359
+ code = body.charCodeAt(position);
1360
+ } // Numbers cannot be followed by . or NameStart
1361
+
1362
+
1363
+ if (code === 46 || isNameStart(code)) {
1364
+ throw syntaxError(source, position, "Invalid number, expected digit but got: ".concat(printCharCode(code), "."));
1365
+ }
1366
+
1367
+ return new Token(isFloat ? TokenKind.FLOAT : TokenKind.INT, start, position, line, col, prev, body.slice(start, position));
1368
+ }
1369
+ /**
1370
+ * Returns the new position in the source after reading digits.
1371
+ */
1372
+
1373
+
1374
+ function readDigits(source, start, firstCode) {
1375
+ var body = source.body;
1376
+ var position = start;
1377
+ var code = firstCode;
1378
+
1379
+ if (code >= 48 && code <= 57) {
1380
+ // 0 - 9
1381
+ do {
1382
+ code = body.charCodeAt(++position);
1383
+ } while (code >= 48 && code <= 57); // 0 - 9
1384
+
1385
+
1386
+ return position;
1387
+ }
1388
+
1389
+ throw syntaxError(source, position, "Invalid number, expected digit but got: ".concat(printCharCode(code), "."));
1390
+ }
1391
+ /**
1392
+ * Reads a string token from the source file.
1393
+ *
1394
+ * "([^"\\\u000A\u000D]|(\\(u[0-9a-fA-F]{4}|["\\/bfnrt])))*"
1395
+ */
1396
+
1397
+
1398
+ function readString(source, start, line, col, prev) {
1399
+ var body = source.body;
1400
+ var position = start + 1;
1401
+ var chunkStart = position;
1402
+ var code = 0;
1403
+ var value = '';
1404
+
1405
+ while (position < body.length && !isNaN(code = body.charCodeAt(position)) && // not LineTerminator
1406
+ code !== 0x000a && code !== 0x000d) {
1407
+ // Closing Quote (")
1408
+ if (code === 34) {
1409
+ value += body.slice(chunkStart, position);
1410
+ return new Token(TokenKind.STRING, start, position + 1, line, col, prev, value);
1411
+ } // SourceCharacter
1412
+
1413
+
1414
+ if (code < 0x0020 && code !== 0x0009) {
1415
+ throw syntaxError(source, position, "Invalid character within String: ".concat(printCharCode(code), "."));
1416
+ }
1417
+
1418
+ ++position;
1419
+
1420
+ if (code === 92) {
1421
+ // \
1422
+ value += body.slice(chunkStart, position - 1);
1423
+ code = body.charCodeAt(position);
1424
+
1425
+ switch (code) {
1426
+ case 34:
1427
+ value += '"';
1428
+ break;
1429
+
1430
+ case 47:
1431
+ value += '/';
1432
+ break;
1433
+
1434
+ case 92:
1435
+ value += '\\';
1436
+ break;
1437
+
1438
+ case 98:
1439
+ value += '\b';
1440
+ break;
1441
+
1442
+ case 102:
1443
+ value += '\f';
1444
+ break;
1445
+
1446
+ case 110:
1447
+ value += '\n';
1448
+ break;
1449
+
1450
+ case 114:
1451
+ value += '\r';
1452
+ break;
1453
+
1454
+ case 116:
1455
+ value += '\t';
1456
+ break;
1457
+
1458
+ case 117:
1459
+ {
1460
+ // uXXXX
1461
+ var charCode = uniCharCode(body.charCodeAt(position + 1), body.charCodeAt(position + 2), body.charCodeAt(position + 3), body.charCodeAt(position + 4));
1462
+
1463
+ if (charCode < 0) {
1464
+ var invalidSequence = body.slice(position + 1, position + 5);
1465
+ throw syntaxError(source, position, "Invalid character escape sequence: \\u".concat(invalidSequence, "."));
1466
+ }
1467
+
1468
+ value += String.fromCharCode(charCode);
1469
+ position += 4;
1470
+ break;
1471
+ }
1472
+
1473
+ default:
1474
+ throw syntaxError(source, position, "Invalid character escape sequence: \\".concat(String.fromCharCode(code), "."));
1475
+ }
1476
+
1477
+ ++position;
1478
+ chunkStart = position;
1479
+ }
1480
+ }
1481
+
1482
+ throw syntaxError(source, position, 'Unterminated string.');
1483
+ }
1484
+ /**
1485
+ * Reads a block string token from the source file.
1486
+ *
1487
+ * """("?"?(\\"""|\\(?!=""")|[^"\\]))*"""
1488
+ */
1489
+
1490
+
1491
+ function readBlockString(source, start, line, col, prev, lexer) {
1492
+ var body = source.body;
1493
+ var position = start + 3;
1494
+ var chunkStart = position;
1495
+ var code = 0;
1496
+ var rawValue = '';
1497
+
1498
+ while (position < body.length && !isNaN(code = body.charCodeAt(position))) {
1499
+ // Closing Triple-Quote (""")
1500
+ if (code === 34 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34) {
1501
+ rawValue += body.slice(chunkStart, position);
1502
+ return new Token(TokenKind.BLOCK_STRING, start, position + 3, line, col, prev, dedentBlockStringValue(rawValue));
1503
+ } // SourceCharacter
1504
+
1505
+
1506
+ if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
1507
+ throw syntaxError(source, position, "Invalid character within String: ".concat(printCharCode(code), "."));
1508
+ }
1509
+
1510
+ if (code === 10) {
1511
+ // new line
1512
+ ++position;
1513
+ ++lexer.line;
1514
+ lexer.lineStart = position;
1515
+ } else if (code === 13) {
1516
+ // carriage return
1517
+ if (body.charCodeAt(position + 1) === 10) {
1518
+ position += 2;
1519
+ } else {
1520
+ ++position;
1521
+ }
1522
+
1523
+ ++lexer.line;
1524
+ lexer.lineStart = position;
1525
+ } else if ( // Escape Triple-Quote (\""")
1526
+ code === 92 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34 && body.charCodeAt(position + 3) === 34) {
1527
+ rawValue += body.slice(chunkStart, position) + '"""';
1528
+ position += 4;
1529
+ chunkStart = position;
1530
+ } else {
1531
+ ++position;
1532
+ }
1533
+ }
1534
+
1535
+ throw syntaxError(source, position, 'Unterminated string.');
1536
+ }
1537
+ /**
1538
+ * Converts four hexadecimal chars to the integer that the
1539
+ * string represents. For example, uniCharCode('0','0','0','f')
1540
+ * will return 15, and uniCharCode('0','0','f','f') returns 255.
1541
+ *
1542
+ * Returns a negative number on error, if a char was invalid.
1543
+ *
1544
+ * This is implemented by noting that char2hex() returns -1 on error,
1545
+ * which means the result of ORing the char2hex() will also be negative.
1546
+ */
1547
+
1548
+
1549
+ function uniCharCode(a, b, c, d) {
1550
+ return char2hex(a) << 12 | char2hex(b) << 8 | char2hex(c) << 4 | char2hex(d);
1551
+ }
1552
+ /**
1553
+ * Converts a hex character to its integer value.
1554
+ * '0' becomes 0, '9' becomes 9
1555
+ * 'A' becomes 10, 'F' becomes 15
1556
+ * 'a' becomes 10, 'f' becomes 15
1557
+ *
1558
+ * Returns -1 on error.
1559
+ */
1560
+
1561
+
1562
+ function char2hex(a) {
1563
+ return a >= 48 && a <= 57 ? a - 48 // 0-9
1564
+ : a >= 65 && a <= 70 ? a - 55 // A-F
1565
+ : a >= 97 && a <= 102 ? a - 87 // a-f
1566
+ : -1;
1567
+ }
1568
+ /**
1569
+ * Reads an alphanumeric + underscore name from the source.
1570
+ *
1571
+ * [_A-Za-z][_0-9A-Za-z]*
1572
+ */
1573
+
1574
+
1575
+ function readName(source, start, line, col, prev) {
1576
+ var body = source.body;
1577
+ var bodyLength = body.length;
1578
+ var position = start + 1;
1579
+ var code = 0;
1580
+
1581
+ while (position !== bodyLength && !isNaN(code = body.charCodeAt(position)) && (code === 95 || // _
1582
+ code >= 48 && code <= 57 || // 0-9
1583
+ code >= 65 && code <= 90 || // A-Z
1584
+ code >= 97 && code <= 122) // a-z
1585
+ ) {
1586
+ ++position;
1587
+ }
1588
+
1589
+ return new Token(TokenKind.NAME, start, position, line, col, prev, body.slice(start, position));
1590
+ } // _ A-Z a-z
1591
+
1592
+
1593
+ function isNameStart(code) {
1594
+ return code === 95 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
1595
+ }
1596
+
1597
+ /**
1598
+ * The set of allowed directive location values.
1599
+ */
1600
+ var DirectiveLocation = Object.freeze({
1601
+ // Request Definitions
1602
+ QUERY: 'QUERY',
1603
+ MUTATION: 'MUTATION',
1604
+ SUBSCRIPTION: 'SUBSCRIPTION',
1605
+ FIELD: 'FIELD',
1606
+ FRAGMENT_DEFINITION: 'FRAGMENT_DEFINITION',
1607
+ FRAGMENT_SPREAD: 'FRAGMENT_SPREAD',
1608
+ INLINE_FRAGMENT: 'INLINE_FRAGMENT',
1609
+ VARIABLE_DEFINITION: 'VARIABLE_DEFINITION',
1610
+ // Type System Definitions
1611
+ SCHEMA: 'SCHEMA',
1612
+ SCALAR: 'SCALAR',
1613
+ OBJECT: 'OBJECT',
1614
+ FIELD_DEFINITION: 'FIELD_DEFINITION',
1615
+ ARGUMENT_DEFINITION: 'ARGUMENT_DEFINITION',
1616
+ INTERFACE: 'INTERFACE',
1617
+ UNION: 'UNION',
1618
+ ENUM: 'ENUM',
1619
+ ENUM_VALUE: 'ENUM_VALUE',
1620
+ INPUT_OBJECT: 'INPUT_OBJECT',
1621
+ INPUT_FIELD_DEFINITION: 'INPUT_FIELD_DEFINITION'
1622
+ });
1623
+ /**
1624
+ * The enum type representing the directive location values.
1625
+ */
1626
+
1627
+ /**
1628
+ * Configuration options to control parser behavior
1629
+ */
1630
+
1631
+ /**
1632
+ * Given a GraphQL source, parses it into a Document.
1633
+ * Throws GraphQLError if a syntax error is encountered.
1634
+ */
1635
+ function parse(source, options) {
1636
+ var parser = new Parser(source, options);
1637
+ return parser.parseDocument();
1638
+ }
1639
+ /**
1640
+ * This class is exported only to assist people in implementing their own parsers
1641
+ * without duplicating too much code and should be used only as last resort for cases
1642
+ * such as experimental syntax or if certain features could not be contributed upstream.
1643
+ *
1644
+ * It is still part of the internal API and is versioned, so any changes to it are never
1645
+ * considered breaking changes. If you still need to support multiple versions of the
1646
+ * library, please use the `versionInfo` variable for version detection.
1647
+ *
1648
+ * @internal
1649
+ */
1650
+
1651
+ var Parser = /*#__PURE__*/function () {
1652
+ function Parser(source, options) {
1653
+ var sourceObj = isSource(source) ? source : new Source(source);
1654
+ this._lexer = new Lexer(sourceObj);
1655
+ this._options = options;
1656
+ }
1657
+ /**
1658
+ * Converts a name lex token into a name parse node.
1659
+ */
1660
+
1661
+
1662
+ var _proto = Parser.prototype;
1663
+
1664
+ _proto.parseName = function parseName() {
1665
+ var token = this.expectToken(TokenKind.NAME);
1666
+ return {
1667
+ kind: Kind.NAME,
1668
+ value: token.value,
1669
+ loc: this.loc(token)
1670
+ };
1671
+ } // Implements the parsing rules in the Document section.
1672
+
1673
+ /**
1674
+ * Document : Definition+
1675
+ */
1676
+ ;
1677
+
1678
+ _proto.parseDocument = function parseDocument() {
1679
+ var start = this._lexer.token;
1680
+ return {
1681
+ kind: Kind.DOCUMENT,
1682
+ definitions: this.many(TokenKind.SOF, this.parseDefinition, TokenKind.EOF),
1683
+ loc: this.loc(start)
1684
+ };
1685
+ }
1686
+ /**
1687
+ * Definition :
1688
+ * - ExecutableDefinition
1689
+ * - TypeSystemDefinition
1690
+ * - TypeSystemExtension
1691
+ *
1692
+ * ExecutableDefinition :
1693
+ * - OperationDefinition
1694
+ * - FragmentDefinition
1695
+ */
1696
+ ;
1697
+
1698
+ _proto.parseDefinition = function parseDefinition() {
1699
+ if (this.peek(TokenKind.NAME)) {
1700
+ switch (this._lexer.token.value) {
1701
+ case 'query':
1702
+ case 'mutation':
1703
+ case 'subscription':
1704
+ return this.parseOperationDefinition();
1705
+
1706
+ case 'fragment':
1707
+ return this.parseFragmentDefinition();
1708
+
1709
+ case 'schema':
1710
+ case 'scalar':
1711
+ case 'type':
1712
+ case 'interface':
1713
+ case 'union':
1714
+ case 'enum':
1715
+ case 'input':
1716
+ case 'directive':
1717
+ return this.parseTypeSystemDefinition();
1718
+
1719
+ case 'extend':
1720
+ return this.parseTypeSystemExtension();
1721
+ }
1722
+ } else if (this.peek(TokenKind.BRACE_L)) {
1723
+ return this.parseOperationDefinition();
1724
+ } else if (this.peekDescription()) {
1725
+ return this.parseTypeSystemDefinition();
1726
+ }
1727
+
1728
+ throw this.unexpected();
1729
+ } // Implements the parsing rules in the Operations section.
1730
+
1731
+ /**
1732
+ * OperationDefinition :
1733
+ * - SelectionSet
1734
+ * - OperationType Name? VariableDefinitions? Directives? SelectionSet
1735
+ */
1736
+ ;
1737
+
1738
+ _proto.parseOperationDefinition = function parseOperationDefinition() {
1739
+ var start = this._lexer.token;
1740
+
1741
+ if (this.peek(TokenKind.BRACE_L)) {
1742
+ return {
1743
+ kind: Kind.OPERATION_DEFINITION,
1744
+ operation: 'query',
1745
+ name: undefined,
1746
+ variableDefinitions: [],
1747
+ directives: [],
1748
+ selectionSet: this.parseSelectionSet(),
1749
+ loc: this.loc(start)
1750
+ };
1751
+ }
1752
+
1753
+ var operation = this.parseOperationType();
1754
+ var name;
1755
+
1756
+ if (this.peek(TokenKind.NAME)) {
1757
+ name = this.parseName();
1758
+ }
1759
+
1760
+ return {
1761
+ kind: Kind.OPERATION_DEFINITION,
1762
+ operation: operation,
1763
+ name: name,
1764
+ variableDefinitions: this.parseVariableDefinitions(),
1765
+ directives: this.parseDirectives(false),
1766
+ selectionSet: this.parseSelectionSet(),
1767
+ loc: this.loc(start)
1768
+ };
1769
+ }
1770
+ /**
1771
+ * OperationType : one of query mutation subscription
1772
+ */
1773
+ ;
1774
+
1775
+ _proto.parseOperationType = function parseOperationType() {
1776
+ var operationToken = this.expectToken(TokenKind.NAME);
1777
+
1778
+ switch (operationToken.value) {
1779
+ case 'query':
1780
+ return 'query';
1781
+
1782
+ case 'mutation':
1783
+ return 'mutation';
1784
+
1785
+ case 'subscription':
1786
+ return 'subscription';
1787
+ }
1788
+
1789
+ throw this.unexpected(operationToken);
1790
+ }
1791
+ /**
1792
+ * VariableDefinitions : ( VariableDefinition+ )
1793
+ */
1794
+ ;
1795
+
1796
+ _proto.parseVariableDefinitions = function parseVariableDefinitions() {
1797
+ return this.optionalMany(TokenKind.PAREN_L, this.parseVariableDefinition, TokenKind.PAREN_R);
1798
+ }
1799
+ /**
1800
+ * VariableDefinition : Variable : Type DefaultValue? Directives[Const]?
1801
+ */
1802
+ ;
1803
+
1804
+ _proto.parseVariableDefinition = function parseVariableDefinition() {
1805
+ var start = this._lexer.token;
1806
+ return {
1807
+ kind: Kind.VARIABLE_DEFINITION,
1808
+ variable: this.parseVariable(),
1809
+ type: (this.expectToken(TokenKind.COLON), this.parseTypeReference()),
1810
+ defaultValue: this.expectOptionalToken(TokenKind.EQUALS) ? this.parseValueLiteral(true) : undefined,
1811
+ directives: this.parseDirectives(true),
1812
+ loc: this.loc(start)
1813
+ };
1814
+ }
1815
+ /**
1816
+ * Variable : $ Name
1817
+ */
1818
+ ;
1819
+
1820
+ _proto.parseVariable = function parseVariable() {
1821
+ var start = this._lexer.token;
1822
+ this.expectToken(TokenKind.DOLLAR);
1823
+ return {
1824
+ kind: Kind.VARIABLE,
1825
+ name: this.parseName(),
1826
+ loc: this.loc(start)
1827
+ };
1828
+ }
1829
+ /**
1830
+ * SelectionSet : { Selection+ }
1831
+ */
1832
+ ;
1833
+
1834
+ _proto.parseSelectionSet = function parseSelectionSet() {
1835
+ var start = this._lexer.token;
1836
+ return {
1837
+ kind: Kind.SELECTION_SET,
1838
+ selections: this.many(TokenKind.BRACE_L, this.parseSelection, TokenKind.BRACE_R),
1839
+ loc: this.loc(start)
1840
+ };
1841
+ }
1842
+ /**
1843
+ * Selection :
1844
+ * - Field
1845
+ * - FragmentSpread
1846
+ * - InlineFragment
1847
+ */
1848
+ ;
1849
+
1850
+ _proto.parseSelection = function parseSelection() {
1851
+ return this.peek(TokenKind.SPREAD) ? this.parseFragment() : this.parseField();
1852
+ }
1853
+ /**
1854
+ * Field : Alias? Name Arguments? Directives? SelectionSet?
1855
+ *
1856
+ * Alias : Name :
1857
+ */
1858
+ ;
1859
+
1860
+ _proto.parseField = function parseField() {
1861
+ var start = this._lexer.token;
1862
+ var nameOrAlias = this.parseName();
1863
+ var alias;
1864
+ var name;
1865
+
1866
+ if (this.expectOptionalToken(TokenKind.COLON)) {
1867
+ alias = nameOrAlias;
1868
+ name = this.parseName();
1869
+ } else {
1870
+ name = nameOrAlias;
1871
+ }
1872
+
1873
+ return {
1874
+ kind: Kind.FIELD,
1875
+ alias: alias,
1876
+ name: name,
1877
+ arguments: this.parseArguments(false),
1878
+ directives: this.parseDirectives(false),
1879
+ selectionSet: this.peek(TokenKind.BRACE_L) ? this.parseSelectionSet() : undefined,
1880
+ loc: this.loc(start)
1881
+ };
1882
+ }
1883
+ /**
1884
+ * Arguments[Const] : ( Argument[?Const]+ )
1885
+ */
1886
+ ;
1887
+
1888
+ _proto.parseArguments = function parseArguments(isConst) {
1889
+ var item = isConst ? this.parseConstArgument : this.parseArgument;
1890
+ return this.optionalMany(TokenKind.PAREN_L, item, TokenKind.PAREN_R);
1891
+ }
1892
+ /**
1893
+ * Argument[Const] : Name : Value[?Const]
1894
+ */
1895
+ ;
1896
+
1897
+ _proto.parseArgument = function parseArgument() {
1898
+ var start = this._lexer.token;
1899
+ var name = this.parseName();
1900
+ this.expectToken(TokenKind.COLON);
1901
+ return {
1902
+ kind: Kind.ARGUMENT,
1903
+ name: name,
1904
+ value: this.parseValueLiteral(false),
1905
+ loc: this.loc(start)
1906
+ };
1907
+ };
1908
+
1909
+ _proto.parseConstArgument = function parseConstArgument() {
1910
+ var start = this._lexer.token;
1911
+ return {
1912
+ kind: Kind.ARGUMENT,
1913
+ name: this.parseName(),
1914
+ value: (this.expectToken(TokenKind.COLON), this.parseValueLiteral(true)),
1915
+ loc: this.loc(start)
1916
+ };
1917
+ } // Implements the parsing rules in the Fragments section.
1918
+
1919
+ /**
1920
+ * Corresponds to both FragmentSpread and InlineFragment in the spec.
1921
+ *
1922
+ * FragmentSpread : ... FragmentName Directives?
1923
+ *
1924
+ * InlineFragment : ... TypeCondition? Directives? SelectionSet
1925
+ */
1926
+ ;
1927
+
1928
+ _proto.parseFragment = function parseFragment() {
1929
+ var start = this._lexer.token;
1930
+ this.expectToken(TokenKind.SPREAD);
1931
+ var hasTypeCondition = this.expectOptionalKeyword('on');
1932
+
1933
+ if (!hasTypeCondition && this.peek(TokenKind.NAME)) {
1934
+ return {
1935
+ kind: Kind.FRAGMENT_SPREAD,
1936
+ name: this.parseFragmentName(),
1937
+ directives: this.parseDirectives(false),
1938
+ loc: this.loc(start)
1939
+ };
1940
+ }
1941
+
1942
+ return {
1943
+ kind: Kind.INLINE_FRAGMENT,
1944
+ typeCondition: hasTypeCondition ? this.parseNamedType() : undefined,
1945
+ directives: this.parseDirectives(false),
1946
+ selectionSet: this.parseSelectionSet(),
1947
+ loc: this.loc(start)
1948
+ };
1949
+ }
1950
+ /**
1951
+ * FragmentDefinition :
1952
+ * - fragment FragmentName on TypeCondition Directives? SelectionSet
1953
+ *
1954
+ * TypeCondition : NamedType
1955
+ */
1956
+ ;
1957
+
1958
+ _proto.parseFragmentDefinition = function parseFragmentDefinition() {
1959
+ var _this$_options;
1960
+
1961
+ var start = this._lexer.token;
1962
+ this.expectKeyword('fragment'); // Experimental support for defining variables within fragments changes
1963
+ // the grammar of FragmentDefinition:
1964
+ // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
1965
+
1966
+ if (((_this$_options = this._options) === null || _this$_options === void 0 ? void 0 : _this$_options.experimentalFragmentVariables) === true) {
1967
+ return {
1968
+ kind: Kind.FRAGMENT_DEFINITION,
1969
+ name: this.parseFragmentName(),
1970
+ variableDefinitions: this.parseVariableDefinitions(),
1971
+ typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
1972
+ directives: this.parseDirectives(false),
1973
+ selectionSet: this.parseSelectionSet(),
1974
+ loc: this.loc(start)
1975
+ };
1976
+ }
1977
+
1978
+ return {
1979
+ kind: Kind.FRAGMENT_DEFINITION,
1980
+ name: this.parseFragmentName(),
1981
+ typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
1982
+ directives: this.parseDirectives(false),
1983
+ selectionSet: this.parseSelectionSet(),
1984
+ loc: this.loc(start)
1985
+ };
1986
+ }
1987
+ /**
1988
+ * FragmentName : Name but not `on`
1989
+ */
1990
+ ;
1991
+
1992
+ _proto.parseFragmentName = function parseFragmentName() {
1993
+ if (this._lexer.token.value === 'on') {
1994
+ throw this.unexpected();
1995
+ }
1996
+
1997
+ return this.parseName();
1998
+ } // Implements the parsing rules in the Values section.
1999
+
2000
+ /**
2001
+ * Value[Const] :
2002
+ * - [~Const] Variable
2003
+ * - IntValue
2004
+ * - FloatValue
2005
+ * - StringValue
2006
+ * - BooleanValue
2007
+ * - NullValue
2008
+ * - EnumValue
2009
+ * - ListValue[?Const]
2010
+ * - ObjectValue[?Const]
2011
+ *
2012
+ * BooleanValue : one of `true` `false`
2013
+ *
2014
+ * NullValue : `null`
2015
+ *
2016
+ * EnumValue : Name but not `true`, `false` or `null`
2017
+ */
2018
+ ;
2019
+
2020
+ _proto.parseValueLiteral = function parseValueLiteral(isConst) {
2021
+ var token = this._lexer.token;
2022
+
2023
+ switch (token.kind) {
2024
+ case TokenKind.BRACKET_L:
2025
+ return this.parseList(isConst);
2026
+
2027
+ case TokenKind.BRACE_L:
2028
+ return this.parseObject(isConst);
2029
+
2030
+ case TokenKind.INT:
2031
+ this._lexer.advance();
2032
+
2033
+ return {
2034
+ kind: Kind.INT,
2035
+ value: token.value,
2036
+ loc: this.loc(token)
2037
+ };
2038
+
2039
+ case TokenKind.FLOAT:
2040
+ this._lexer.advance();
2041
+
2042
+ return {
2043
+ kind: Kind.FLOAT,
2044
+ value: token.value,
2045
+ loc: this.loc(token)
2046
+ };
2047
+
2048
+ case TokenKind.STRING:
2049
+ case TokenKind.BLOCK_STRING:
2050
+ return this.parseStringLiteral();
2051
+
2052
+ case TokenKind.NAME:
2053
+ this._lexer.advance();
2054
+
2055
+ switch (token.value) {
2056
+ case 'true':
2057
+ return {
2058
+ kind: Kind.BOOLEAN,
2059
+ value: true,
2060
+ loc: this.loc(token)
2061
+ };
2062
+
2063
+ case 'false':
2064
+ return {
2065
+ kind: Kind.BOOLEAN,
2066
+ value: false,
2067
+ loc: this.loc(token)
2068
+ };
2069
+
2070
+ case 'null':
2071
+ return {
2072
+ kind: Kind.NULL,
2073
+ loc: this.loc(token)
2074
+ };
2075
+
2076
+ default:
2077
+ return {
2078
+ kind: Kind.ENUM,
2079
+ value: token.value,
2080
+ loc: this.loc(token)
2081
+ };
2082
+ }
2083
+
2084
+ case TokenKind.DOLLAR:
2085
+ if (!isConst) {
2086
+ return this.parseVariable();
2087
+ }
2088
+
2089
+ break;
2090
+ }
2091
+
2092
+ throw this.unexpected();
2093
+ };
2094
+
2095
+ _proto.parseStringLiteral = function parseStringLiteral() {
2096
+ var token = this._lexer.token;
2097
+
2098
+ this._lexer.advance();
2099
+
2100
+ return {
2101
+ kind: Kind.STRING,
2102
+ value: token.value,
2103
+ block: token.kind === TokenKind.BLOCK_STRING,
2104
+ loc: this.loc(token)
2105
+ };
2106
+ }
2107
+ /**
2108
+ * ListValue[Const] :
2109
+ * - [ ]
2110
+ * - [ Value[?Const]+ ]
2111
+ */
2112
+ ;
2113
+
2114
+ _proto.parseList = function parseList(isConst) {
2115
+ var _this = this;
2116
+
2117
+ var start = this._lexer.token;
2118
+
2119
+ var item = function item() {
2120
+ return _this.parseValueLiteral(isConst);
2121
+ };
2122
+
2123
+ return {
2124
+ kind: Kind.LIST,
2125
+ values: this.any(TokenKind.BRACKET_L, item, TokenKind.BRACKET_R),
2126
+ loc: this.loc(start)
2127
+ };
2128
+ }
2129
+ /**
2130
+ * ObjectValue[Const] :
2131
+ * - { }
2132
+ * - { ObjectField[?Const]+ }
2133
+ */
2134
+ ;
2135
+
2136
+ _proto.parseObject = function parseObject(isConst) {
2137
+ var _this2 = this;
2138
+
2139
+ var start = this._lexer.token;
2140
+
2141
+ var item = function item() {
2142
+ return _this2.parseObjectField(isConst);
2143
+ };
2144
+
2145
+ return {
2146
+ kind: Kind.OBJECT,
2147
+ fields: this.any(TokenKind.BRACE_L, item, TokenKind.BRACE_R),
2148
+ loc: this.loc(start)
2149
+ };
2150
+ }
2151
+ /**
2152
+ * ObjectField[Const] : Name : Value[?Const]
2153
+ */
2154
+ ;
2155
+
2156
+ _proto.parseObjectField = function parseObjectField(isConst) {
2157
+ var start = this._lexer.token;
2158
+ var name = this.parseName();
2159
+ this.expectToken(TokenKind.COLON);
2160
+ return {
2161
+ kind: Kind.OBJECT_FIELD,
2162
+ name: name,
2163
+ value: this.parseValueLiteral(isConst),
2164
+ loc: this.loc(start)
2165
+ };
2166
+ } // Implements the parsing rules in the Directives section.
2167
+
2168
+ /**
2169
+ * Directives[Const] : Directive[?Const]+
2170
+ */
2171
+ ;
2172
+
2173
+ _proto.parseDirectives = function parseDirectives(isConst) {
2174
+ var directives = [];
2175
+
2176
+ while (this.peek(TokenKind.AT)) {
2177
+ directives.push(this.parseDirective(isConst));
2178
+ }
2179
+
2180
+ return directives;
2181
+ }
2182
+ /**
2183
+ * Directive[Const] : @ Name Arguments[?Const]?
2184
+ */
2185
+ ;
2186
+
2187
+ _proto.parseDirective = function parseDirective(isConst) {
2188
+ var start = this._lexer.token;
2189
+ this.expectToken(TokenKind.AT);
2190
+ return {
2191
+ kind: Kind.DIRECTIVE,
2192
+ name: this.parseName(),
2193
+ arguments: this.parseArguments(isConst),
2194
+ loc: this.loc(start)
2195
+ };
2196
+ } // Implements the parsing rules in the Types section.
2197
+
2198
+ /**
2199
+ * Type :
2200
+ * - NamedType
2201
+ * - ListType
2202
+ * - NonNullType
2203
+ */
2204
+ ;
2205
+
2206
+ _proto.parseTypeReference = function parseTypeReference() {
2207
+ var start = this._lexer.token;
2208
+ var type;
2209
+
2210
+ if (this.expectOptionalToken(TokenKind.BRACKET_L)) {
2211
+ type = this.parseTypeReference();
2212
+ this.expectToken(TokenKind.BRACKET_R);
2213
+ type = {
2214
+ kind: Kind.LIST_TYPE,
2215
+ type: type,
2216
+ loc: this.loc(start)
2217
+ };
2218
+ } else {
2219
+ type = this.parseNamedType();
2220
+ }
2221
+
2222
+ if (this.expectOptionalToken(TokenKind.BANG)) {
2223
+ return {
2224
+ kind: Kind.NON_NULL_TYPE,
2225
+ type: type,
2226
+ loc: this.loc(start)
2227
+ };
2228
+ }
2229
+
2230
+ return type;
2231
+ }
2232
+ /**
2233
+ * NamedType : Name
2234
+ */
2235
+ ;
2236
+
2237
+ _proto.parseNamedType = function parseNamedType() {
2238
+ var start = this._lexer.token;
2239
+ return {
2240
+ kind: Kind.NAMED_TYPE,
2241
+ name: this.parseName(),
2242
+ loc: this.loc(start)
2243
+ };
2244
+ } // Implements the parsing rules in the Type Definition section.
2245
+
2246
+ /**
2247
+ * TypeSystemDefinition :
2248
+ * - SchemaDefinition
2249
+ * - TypeDefinition
2250
+ * - DirectiveDefinition
2251
+ *
2252
+ * TypeDefinition :
2253
+ * - ScalarTypeDefinition
2254
+ * - ObjectTypeDefinition
2255
+ * - InterfaceTypeDefinition
2256
+ * - UnionTypeDefinition
2257
+ * - EnumTypeDefinition
2258
+ * - InputObjectTypeDefinition
2259
+ */
2260
+ ;
2261
+
2262
+ _proto.parseTypeSystemDefinition = function parseTypeSystemDefinition() {
2263
+ // Many definitions begin with a description and require a lookahead.
2264
+ var keywordToken = this.peekDescription() ? this._lexer.lookahead() : this._lexer.token;
2265
+
2266
+ if (keywordToken.kind === TokenKind.NAME) {
2267
+ switch (keywordToken.value) {
2268
+ case 'schema':
2269
+ return this.parseSchemaDefinition();
2270
+
2271
+ case 'scalar':
2272
+ return this.parseScalarTypeDefinition();
2273
+
2274
+ case 'type':
2275
+ return this.parseObjectTypeDefinition();
2276
+
2277
+ case 'interface':
2278
+ return this.parseInterfaceTypeDefinition();
2279
+
2280
+ case 'union':
2281
+ return this.parseUnionTypeDefinition();
2282
+
2283
+ case 'enum':
2284
+ return this.parseEnumTypeDefinition();
2285
+
2286
+ case 'input':
2287
+ return this.parseInputObjectTypeDefinition();
2288
+
2289
+ case 'directive':
2290
+ return this.parseDirectiveDefinition();
2291
+ }
2292
+ }
2293
+
2294
+ throw this.unexpected(keywordToken);
2295
+ };
2296
+
2297
+ _proto.peekDescription = function peekDescription() {
2298
+ return this.peek(TokenKind.STRING) || this.peek(TokenKind.BLOCK_STRING);
2299
+ }
2300
+ /**
2301
+ * Description : StringValue
2302
+ */
2303
+ ;
2304
+
2305
+ _proto.parseDescription = function parseDescription() {
2306
+ if (this.peekDescription()) {
2307
+ return this.parseStringLiteral();
2308
+ }
2309
+ }
2310
+ /**
2311
+ * SchemaDefinition : Description? schema Directives[Const]? { OperationTypeDefinition+ }
2312
+ */
2313
+ ;
2314
+
2315
+ _proto.parseSchemaDefinition = function parseSchemaDefinition() {
2316
+ var start = this._lexer.token;
2317
+ var description = this.parseDescription();
2318
+ this.expectKeyword('schema');
2319
+ var directives = this.parseDirectives(true);
2320
+ var operationTypes = this.many(TokenKind.BRACE_L, this.parseOperationTypeDefinition, TokenKind.BRACE_R);
2321
+ return {
2322
+ kind: Kind.SCHEMA_DEFINITION,
2323
+ description: description,
2324
+ directives: directives,
2325
+ operationTypes: operationTypes,
2326
+ loc: this.loc(start)
2327
+ };
2328
+ }
2329
+ /**
2330
+ * OperationTypeDefinition : OperationType : NamedType
2331
+ */
2332
+ ;
2333
+
2334
+ _proto.parseOperationTypeDefinition = function parseOperationTypeDefinition() {
2335
+ var start = this._lexer.token;
2336
+ var operation = this.parseOperationType();
2337
+ this.expectToken(TokenKind.COLON);
2338
+ var type = this.parseNamedType();
2339
+ return {
2340
+ kind: Kind.OPERATION_TYPE_DEFINITION,
2341
+ operation: operation,
2342
+ type: type,
2343
+ loc: this.loc(start)
2344
+ };
2345
+ }
2346
+ /**
2347
+ * ScalarTypeDefinition : Description? scalar Name Directives[Const]?
2348
+ */
2349
+ ;
2350
+
2351
+ _proto.parseScalarTypeDefinition = function parseScalarTypeDefinition() {
2352
+ var start = this._lexer.token;
2353
+ var description = this.parseDescription();
2354
+ this.expectKeyword('scalar');
2355
+ var name = this.parseName();
2356
+ var directives = this.parseDirectives(true);
2357
+ return {
2358
+ kind: Kind.SCALAR_TYPE_DEFINITION,
2359
+ description: description,
2360
+ name: name,
2361
+ directives: directives,
2362
+ loc: this.loc(start)
2363
+ };
2364
+ }
2365
+ /**
2366
+ * ObjectTypeDefinition :
2367
+ * Description?
2368
+ * type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition?
2369
+ */
2370
+ ;
2371
+
2372
+ _proto.parseObjectTypeDefinition = function parseObjectTypeDefinition() {
2373
+ var start = this._lexer.token;
2374
+ var description = this.parseDescription();
2375
+ this.expectKeyword('type');
2376
+ var name = this.parseName();
2377
+ var interfaces = this.parseImplementsInterfaces();
2378
+ var directives = this.parseDirectives(true);
2379
+ var fields = this.parseFieldsDefinition();
2380
+ return {
2381
+ kind: Kind.OBJECT_TYPE_DEFINITION,
2382
+ description: description,
2383
+ name: name,
2384
+ interfaces: interfaces,
2385
+ directives: directives,
2386
+ fields: fields,
2387
+ loc: this.loc(start)
2388
+ };
2389
+ }
2390
+ /**
2391
+ * ImplementsInterfaces :
2392
+ * - implements `&`? NamedType
2393
+ * - ImplementsInterfaces & NamedType
2394
+ */
2395
+ ;
2396
+
2397
+ _proto.parseImplementsInterfaces = function parseImplementsInterfaces() {
2398
+ var _this$_options2;
2399
+
2400
+ if (!this.expectOptionalKeyword('implements')) {
2401
+ return [];
2402
+ }
2403
+
2404
+ if (((_this$_options2 = this._options) === null || _this$_options2 === void 0 ? void 0 : _this$_options2.allowLegacySDLImplementsInterfaces) === true) {
2405
+ var types = []; // Optional leading ampersand
2406
+
2407
+ this.expectOptionalToken(TokenKind.AMP);
2408
+
2409
+ do {
2410
+ types.push(this.parseNamedType());
2411
+ } while (this.expectOptionalToken(TokenKind.AMP) || this.peek(TokenKind.NAME));
2412
+
2413
+ return types;
2414
+ }
2415
+
2416
+ return this.delimitedMany(TokenKind.AMP, this.parseNamedType);
2417
+ }
2418
+ /**
2419
+ * FieldsDefinition : { FieldDefinition+ }
2420
+ */
2421
+ ;
2422
+
2423
+ _proto.parseFieldsDefinition = function parseFieldsDefinition() {
2424
+ var _this$_options3;
2425
+
2426
+ // Legacy support for the SDL?
2427
+ if (((_this$_options3 = this._options) === null || _this$_options3 === void 0 ? void 0 : _this$_options3.allowLegacySDLEmptyFields) === true && this.peek(TokenKind.BRACE_L) && this._lexer.lookahead().kind === TokenKind.BRACE_R) {
2428
+ this._lexer.advance();
2429
+
2430
+ this._lexer.advance();
2431
+
2432
+ return [];
2433
+ }
2434
+
2435
+ return this.optionalMany(TokenKind.BRACE_L, this.parseFieldDefinition, TokenKind.BRACE_R);
2436
+ }
2437
+ /**
2438
+ * FieldDefinition :
2439
+ * - Description? Name ArgumentsDefinition? : Type Directives[Const]?
2440
+ */
2441
+ ;
2442
+
2443
+ _proto.parseFieldDefinition = function parseFieldDefinition() {
2444
+ var start = this._lexer.token;
2445
+ var description = this.parseDescription();
2446
+ var name = this.parseName();
2447
+ var args = this.parseArgumentDefs();
2448
+ this.expectToken(TokenKind.COLON);
2449
+ var type = this.parseTypeReference();
2450
+ var directives = this.parseDirectives(true);
2451
+ return {
2452
+ kind: Kind.FIELD_DEFINITION,
2453
+ description: description,
2454
+ name: name,
2455
+ arguments: args,
2456
+ type: type,
2457
+ directives: directives,
2458
+ loc: this.loc(start)
2459
+ };
2460
+ }
2461
+ /**
2462
+ * ArgumentsDefinition : ( InputValueDefinition+ )
2463
+ */
2464
+ ;
2465
+
2466
+ _proto.parseArgumentDefs = function parseArgumentDefs() {
2467
+ return this.optionalMany(TokenKind.PAREN_L, this.parseInputValueDef, TokenKind.PAREN_R);
2468
+ }
2469
+ /**
2470
+ * InputValueDefinition :
2471
+ * - Description? Name : Type DefaultValue? Directives[Const]?
2472
+ */
2473
+ ;
2474
+
2475
+ _proto.parseInputValueDef = function parseInputValueDef() {
2476
+ var start = this._lexer.token;
2477
+ var description = this.parseDescription();
2478
+ var name = this.parseName();
2479
+ this.expectToken(TokenKind.COLON);
2480
+ var type = this.parseTypeReference();
2481
+ var defaultValue;
2482
+
2483
+ if (this.expectOptionalToken(TokenKind.EQUALS)) {
2484
+ defaultValue = this.parseValueLiteral(true);
2485
+ }
2486
+
2487
+ var directives = this.parseDirectives(true);
2488
+ return {
2489
+ kind: Kind.INPUT_VALUE_DEFINITION,
2490
+ description: description,
2491
+ name: name,
2492
+ type: type,
2493
+ defaultValue: defaultValue,
2494
+ directives: directives,
2495
+ loc: this.loc(start)
2496
+ };
2497
+ }
2498
+ /**
2499
+ * InterfaceTypeDefinition :
2500
+ * - Description? interface Name Directives[Const]? FieldsDefinition?
2501
+ */
2502
+ ;
2503
+
2504
+ _proto.parseInterfaceTypeDefinition = function parseInterfaceTypeDefinition() {
2505
+ var start = this._lexer.token;
2506
+ var description = this.parseDescription();
2507
+ this.expectKeyword('interface');
2508
+ var name = this.parseName();
2509
+ var interfaces = this.parseImplementsInterfaces();
2510
+ var directives = this.parseDirectives(true);
2511
+ var fields = this.parseFieldsDefinition();
2512
+ return {
2513
+ kind: Kind.INTERFACE_TYPE_DEFINITION,
2514
+ description: description,
2515
+ name: name,
2516
+ interfaces: interfaces,
2517
+ directives: directives,
2518
+ fields: fields,
2519
+ loc: this.loc(start)
2520
+ };
2521
+ }
2522
+ /**
2523
+ * UnionTypeDefinition :
2524
+ * - Description? union Name Directives[Const]? UnionMemberTypes?
2525
+ */
2526
+ ;
2527
+
2528
+ _proto.parseUnionTypeDefinition = function parseUnionTypeDefinition() {
2529
+ var start = this._lexer.token;
2530
+ var description = this.parseDescription();
2531
+ this.expectKeyword('union');
2532
+ var name = this.parseName();
2533
+ var directives = this.parseDirectives(true);
2534
+ var types = this.parseUnionMemberTypes();
2535
+ return {
2536
+ kind: Kind.UNION_TYPE_DEFINITION,
2537
+ description: description,
2538
+ name: name,
2539
+ directives: directives,
2540
+ types: types,
2541
+ loc: this.loc(start)
2542
+ };
2543
+ }
2544
+ /**
2545
+ * UnionMemberTypes :
2546
+ * - = `|`? NamedType
2547
+ * - UnionMemberTypes | NamedType
2548
+ */
2549
+ ;
2550
+
2551
+ _proto.parseUnionMemberTypes = function parseUnionMemberTypes() {
2552
+ return this.expectOptionalToken(TokenKind.EQUALS) ? this.delimitedMany(TokenKind.PIPE, this.parseNamedType) : [];
2553
+ }
2554
+ /**
2555
+ * EnumTypeDefinition :
2556
+ * - Description? enum Name Directives[Const]? EnumValuesDefinition?
2557
+ */
2558
+ ;
2559
+
2560
+ _proto.parseEnumTypeDefinition = function parseEnumTypeDefinition() {
2561
+ var start = this._lexer.token;
2562
+ var description = this.parseDescription();
2563
+ this.expectKeyword('enum');
2564
+ var name = this.parseName();
2565
+ var directives = this.parseDirectives(true);
2566
+ var values = this.parseEnumValuesDefinition();
2567
+ return {
2568
+ kind: Kind.ENUM_TYPE_DEFINITION,
2569
+ description: description,
2570
+ name: name,
2571
+ directives: directives,
2572
+ values: values,
2573
+ loc: this.loc(start)
2574
+ };
2575
+ }
2576
+ /**
2577
+ * EnumValuesDefinition : { EnumValueDefinition+ }
2578
+ */
2579
+ ;
2580
+
2581
+ _proto.parseEnumValuesDefinition = function parseEnumValuesDefinition() {
2582
+ return this.optionalMany(TokenKind.BRACE_L, this.parseEnumValueDefinition, TokenKind.BRACE_R);
2583
+ }
2584
+ /**
2585
+ * EnumValueDefinition : Description? EnumValue Directives[Const]?
2586
+ *
2587
+ * EnumValue : Name
2588
+ */
2589
+ ;
2590
+
2591
+ _proto.parseEnumValueDefinition = function parseEnumValueDefinition() {
2592
+ var start = this._lexer.token;
2593
+ var description = this.parseDescription();
2594
+ var name = this.parseName();
2595
+ var directives = this.parseDirectives(true);
2596
+ return {
2597
+ kind: Kind.ENUM_VALUE_DEFINITION,
2598
+ description: description,
2599
+ name: name,
2600
+ directives: directives,
2601
+ loc: this.loc(start)
2602
+ };
2603
+ }
2604
+ /**
2605
+ * InputObjectTypeDefinition :
2606
+ * - Description? input Name Directives[Const]? InputFieldsDefinition?
2607
+ */
2608
+ ;
2609
+
2610
+ _proto.parseInputObjectTypeDefinition = function parseInputObjectTypeDefinition() {
2611
+ var start = this._lexer.token;
2612
+ var description = this.parseDescription();
2613
+ this.expectKeyword('input');
2614
+ var name = this.parseName();
2615
+ var directives = this.parseDirectives(true);
2616
+ var fields = this.parseInputFieldsDefinition();
2617
+ return {
2618
+ kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
2619
+ description: description,
2620
+ name: name,
2621
+ directives: directives,
2622
+ fields: fields,
2623
+ loc: this.loc(start)
2624
+ };
2625
+ }
2626
+ /**
2627
+ * InputFieldsDefinition : { InputValueDefinition+ }
2628
+ */
2629
+ ;
2630
+
2631
+ _proto.parseInputFieldsDefinition = function parseInputFieldsDefinition() {
2632
+ return this.optionalMany(TokenKind.BRACE_L, this.parseInputValueDef, TokenKind.BRACE_R);
2633
+ }
2634
+ /**
2635
+ * TypeSystemExtension :
2636
+ * - SchemaExtension
2637
+ * - TypeExtension
2638
+ *
2639
+ * TypeExtension :
2640
+ * - ScalarTypeExtension
2641
+ * - ObjectTypeExtension
2642
+ * - InterfaceTypeExtension
2643
+ * - UnionTypeExtension
2644
+ * - EnumTypeExtension
2645
+ * - InputObjectTypeDefinition
2646
+ */
2647
+ ;
2648
+
2649
+ _proto.parseTypeSystemExtension = function parseTypeSystemExtension() {
2650
+ var keywordToken = this._lexer.lookahead();
2651
+
2652
+ if (keywordToken.kind === TokenKind.NAME) {
2653
+ switch (keywordToken.value) {
2654
+ case 'schema':
2655
+ return this.parseSchemaExtension();
2656
+
2657
+ case 'scalar':
2658
+ return this.parseScalarTypeExtension();
2659
+
2660
+ case 'type':
2661
+ return this.parseObjectTypeExtension();
2662
+
2663
+ case 'interface':
2664
+ return this.parseInterfaceTypeExtension();
2665
+
2666
+ case 'union':
2667
+ return this.parseUnionTypeExtension();
2668
+
2669
+ case 'enum':
2670
+ return this.parseEnumTypeExtension();
2671
+
2672
+ case 'input':
2673
+ return this.parseInputObjectTypeExtension();
2674
+ }
2675
+ }
2676
+
2677
+ throw this.unexpected(keywordToken);
2678
+ }
2679
+ /**
2680
+ * SchemaExtension :
2681
+ * - extend schema Directives[Const]? { OperationTypeDefinition+ }
2682
+ * - extend schema Directives[Const]
2683
+ */
2684
+ ;
2685
+
2686
+ _proto.parseSchemaExtension = function parseSchemaExtension() {
2687
+ var start = this._lexer.token;
2688
+ this.expectKeyword('extend');
2689
+ this.expectKeyword('schema');
2690
+ var directives = this.parseDirectives(true);
2691
+ var operationTypes = this.optionalMany(TokenKind.BRACE_L, this.parseOperationTypeDefinition, TokenKind.BRACE_R);
2692
+
2693
+ if (directives.length === 0 && operationTypes.length === 0) {
2694
+ throw this.unexpected();
2695
+ }
2696
+
2697
+ return {
2698
+ kind: Kind.SCHEMA_EXTENSION,
2699
+ directives: directives,
2700
+ operationTypes: operationTypes,
2701
+ loc: this.loc(start)
2702
+ };
2703
+ }
2704
+ /**
2705
+ * ScalarTypeExtension :
2706
+ * - extend scalar Name Directives[Const]
2707
+ */
2708
+ ;
2709
+
2710
+ _proto.parseScalarTypeExtension = function parseScalarTypeExtension() {
2711
+ var start = this._lexer.token;
2712
+ this.expectKeyword('extend');
2713
+ this.expectKeyword('scalar');
2714
+ var name = this.parseName();
2715
+ var directives = this.parseDirectives(true);
2716
+
2717
+ if (directives.length === 0) {
2718
+ throw this.unexpected();
2719
+ }
2720
+
2721
+ return {
2722
+ kind: Kind.SCALAR_TYPE_EXTENSION,
2723
+ name: name,
2724
+ directives: directives,
2725
+ loc: this.loc(start)
2726
+ };
2727
+ }
2728
+ /**
2729
+ * ObjectTypeExtension :
2730
+ * - extend type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition
2731
+ * - extend type Name ImplementsInterfaces? Directives[Const]
2732
+ * - extend type Name ImplementsInterfaces
2733
+ */
2734
+ ;
2735
+
2736
+ _proto.parseObjectTypeExtension = function parseObjectTypeExtension() {
2737
+ var start = this._lexer.token;
2738
+ this.expectKeyword('extend');
2739
+ this.expectKeyword('type');
2740
+ var name = this.parseName();
2741
+ var interfaces = this.parseImplementsInterfaces();
2742
+ var directives = this.parseDirectives(true);
2743
+ var fields = this.parseFieldsDefinition();
2744
+
2745
+ if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) {
2746
+ throw this.unexpected();
2747
+ }
2748
+
2749
+ return {
2750
+ kind: Kind.OBJECT_TYPE_EXTENSION,
2751
+ name: name,
2752
+ interfaces: interfaces,
2753
+ directives: directives,
2754
+ fields: fields,
2755
+ loc: this.loc(start)
2756
+ };
2757
+ }
2758
+ /**
2759
+ * InterfaceTypeExtension :
2760
+ * - extend interface Name ImplementsInterfaces? Directives[Const]? FieldsDefinition
2761
+ * - extend interface Name ImplementsInterfaces? Directives[Const]
2762
+ * - extend interface Name ImplementsInterfaces
2763
+ */
2764
+ ;
2765
+
2766
+ _proto.parseInterfaceTypeExtension = function parseInterfaceTypeExtension() {
2767
+ var start = this._lexer.token;
2768
+ this.expectKeyword('extend');
2769
+ this.expectKeyword('interface');
2770
+ var name = this.parseName();
2771
+ var interfaces = this.parseImplementsInterfaces();
2772
+ var directives = this.parseDirectives(true);
2773
+ var fields = this.parseFieldsDefinition();
2774
+
2775
+ if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) {
2776
+ throw this.unexpected();
2777
+ }
2778
+
2779
+ return {
2780
+ kind: Kind.INTERFACE_TYPE_EXTENSION,
2781
+ name: name,
2782
+ interfaces: interfaces,
2783
+ directives: directives,
2784
+ fields: fields,
2785
+ loc: this.loc(start)
2786
+ };
2787
+ }
2788
+ /**
2789
+ * UnionTypeExtension :
2790
+ * - extend union Name Directives[Const]? UnionMemberTypes
2791
+ * - extend union Name Directives[Const]
2792
+ */
2793
+ ;
2794
+
2795
+ _proto.parseUnionTypeExtension = function parseUnionTypeExtension() {
2796
+ var start = this._lexer.token;
2797
+ this.expectKeyword('extend');
2798
+ this.expectKeyword('union');
2799
+ var name = this.parseName();
2800
+ var directives = this.parseDirectives(true);
2801
+ var types = this.parseUnionMemberTypes();
2802
+
2803
+ if (directives.length === 0 && types.length === 0) {
2804
+ throw this.unexpected();
2805
+ }
2806
+
2807
+ return {
2808
+ kind: Kind.UNION_TYPE_EXTENSION,
2809
+ name: name,
2810
+ directives: directives,
2811
+ types: types,
2812
+ loc: this.loc(start)
2813
+ };
2814
+ }
2815
+ /**
2816
+ * EnumTypeExtension :
2817
+ * - extend enum Name Directives[Const]? EnumValuesDefinition
2818
+ * - extend enum Name Directives[Const]
2819
+ */
2820
+ ;
2821
+
2822
+ _proto.parseEnumTypeExtension = function parseEnumTypeExtension() {
2823
+ var start = this._lexer.token;
2824
+ this.expectKeyword('extend');
2825
+ this.expectKeyword('enum');
2826
+ var name = this.parseName();
2827
+ var directives = this.parseDirectives(true);
2828
+ var values = this.parseEnumValuesDefinition();
2829
+
2830
+ if (directives.length === 0 && values.length === 0) {
2831
+ throw this.unexpected();
2832
+ }
2833
+
2834
+ return {
2835
+ kind: Kind.ENUM_TYPE_EXTENSION,
2836
+ name: name,
2837
+ directives: directives,
2838
+ values: values,
2839
+ loc: this.loc(start)
2840
+ };
2841
+ }
2842
+ /**
2843
+ * InputObjectTypeExtension :
2844
+ * - extend input Name Directives[Const]? InputFieldsDefinition
2845
+ * - extend input Name Directives[Const]
2846
+ */
2847
+ ;
2848
+
2849
+ _proto.parseInputObjectTypeExtension = function parseInputObjectTypeExtension() {
2850
+ var start = this._lexer.token;
2851
+ this.expectKeyword('extend');
2852
+ this.expectKeyword('input');
2853
+ var name = this.parseName();
2854
+ var directives = this.parseDirectives(true);
2855
+ var fields = this.parseInputFieldsDefinition();
2856
+
2857
+ if (directives.length === 0 && fields.length === 0) {
2858
+ throw this.unexpected();
2859
+ }
2860
+
2861
+ return {
2862
+ kind: Kind.INPUT_OBJECT_TYPE_EXTENSION,
2863
+ name: name,
2864
+ directives: directives,
2865
+ fields: fields,
2866
+ loc: this.loc(start)
2867
+ };
2868
+ }
2869
+ /**
2870
+ * DirectiveDefinition :
2871
+ * - Description? directive @ Name ArgumentsDefinition? `repeatable`? on DirectiveLocations
2872
+ */
2873
+ ;
2874
+
2875
+ _proto.parseDirectiveDefinition = function parseDirectiveDefinition() {
2876
+ var start = this._lexer.token;
2877
+ var description = this.parseDescription();
2878
+ this.expectKeyword('directive');
2879
+ this.expectToken(TokenKind.AT);
2880
+ var name = this.parseName();
2881
+ var args = this.parseArgumentDefs();
2882
+ var repeatable = this.expectOptionalKeyword('repeatable');
2883
+ this.expectKeyword('on');
2884
+ var locations = this.parseDirectiveLocations();
2885
+ return {
2886
+ kind: Kind.DIRECTIVE_DEFINITION,
2887
+ description: description,
2888
+ name: name,
2889
+ arguments: args,
2890
+ repeatable: repeatable,
2891
+ locations: locations,
2892
+ loc: this.loc(start)
2893
+ };
2894
+ }
2895
+ /**
2896
+ * DirectiveLocations :
2897
+ * - `|`? DirectiveLocation
2898
+ * - DirectiveLocations | DirectiveLocation
2899
+ */
2900
+ ;
2901
+
2902
+ _proto.parseDirectiveLocations = function parseDirectiveLocations() {
2903
+ return this.delimitedMany(TokenKind.PIPE, this.parseDirectiveLocation);
2904
+ }
2905
+ /*
2906
+ * DirectiveLocation :
2907
+ * - ExecutableDirectiveLocation
2908
+ * - TypeSystemDirectiveLocation
2909
+ *
2910
+ * ExecutableDirectiveLocation : one of
2911
+ * `QUERY`
2912
+ * `MUTATION`
2913
+ * `SUBSCRIPTION`
2914
+ * `FIELD`
2915
+ * `FRAGMENT_DEFINITION`
2916
+ * `FRAGMENT_SPREAD`
2917
+ * `INLINE_FRAGMENT`
2918
+ *
2919
+ * TypeSystemDirectiveLocation : one of
2920
+ * `SCHEMA`
2921
+ * `SCALAR`
2922
+ * `OBJECT`
2923
+ * `FIELD_DEFINITION`
2924
+ * `ARGUMENT_DEFINITION`
2925
+ * `INTERFACE`
2926
+ * `UNION`
2927
+ * `ENUM`
2928
+ * `ENUM_VALUE`
2929
+ * `INPUT_OBJECT`
2930
+ * `INPUT_FIELD_DEFINITION`
2931
+ */
2932
+ ;
2933
+
2934
+ _proto.parseDirectiveLocation = function parseDirectiveLocation() {
2935
+ var start = this._lexer.token;
2936
+ var name = this.parseName();
2937
+
2938
+ if (DirectiveLocation[name.value] !== undefined) {
2939
+ return name;
2940
+ }
2941
+
2942
+ throw this.unexpected(start);
2943
+ } // Core parsing utility functions
2944
+
2945
+ /**
2946
+ * Returns a location object, used to identify the place in the source that created a given parsed object.
2947
+ */
2948
+ ;
2949
+
2950
+ _proto.loc = function loc(startToken) {
2951
+ var _this$_options4;
2952
+
2953
+ if (((_this$_options4 = this._options) === null || _this$_options4 === void 0 ? void 0 : _this$_options4.noLocation) !== true) {
2954
+ return new Location(startToken, this._lexer.lastToken, this._lexer.source);
2955
+ }
2956
+ }
2957
+ /**
2958
+ * Determines if the next token is of a given kind
2959
+ */
2960
+ ;
2961
+
2962
+ _proto.peek = function peek(kind) {
2963
+ return this._lexer.token.kind === kind;
2964
+ }
2965
+ /**
2966
+ * If the next token is of the given kind, return that token after advancing the lexer.
2967
+ * Otherwise, do not change the parser state and throw an error.
2968
+ */
2969
+ ;
2970
+
2971
+ _proto.expectToken = function expectToken(kind) {
2972
+ var token = this._lexer.token;
2973
+
2974
+ if (token.kind === kind) {
2975
+ this._lexer.advance();
2976
+
2977
+ return token;
2978
+ }
2979
+
2980
+ throw syntaxError(this._lexer.source, token.start, "Expected ".concat(getTokenKindDesc(kind), ", found ").concat(getTokenDesc(token), "."));
2981
+ }
2982
+ /**
2983
+ * If the next token is of the given kind, return that token after advancing the lexer.
2984
+ * Otherwise, do not change the parser state and return undefined.
2985
+ */
2986
+ ;
2987
+
2988
+ _proto.expectOptionalToken = function expectOptionalToken(kind) {
2989
+ var token = this._lexer.token;
2990
+
2991
+ if (token.kind === kind) {
2992
+ this._lexer.advance();
2993
+
2994
+ return token;
2995
+ }
2996
+
2997
+ return undefined;
2998
+ }
2999
+ /**
3000
+ * If the next token is a given keyword, advance the lexer.
3001
+ * Otherwise, do not change the parser state and throw an error.
3002
+ */
3003
+ ;
3004
+
3005
+ _proto.expectKeyword = function expectKeyword(value) {
3006
+ var token = this._lexer.token;
3007
+
3008
+ if (token.kind === TokenKind.NAME && token.value === value) {
3009
+ this._lexer.advance();
3010
+ } else {
3011
+ throw syntaxError(this._lexer.source, token.start, "Expected \"".concat(value, "\", found ").concat(getTokenDesc(token), "."));
3012
+ }
3013
+ }
3014
+ /**
3015
+ * If the next token is a given keyword, return "true" after advancing the lexer.
3016
+ * Otherwise, do not change the parser state and return "false".
3017
+ */
3018
+ ;
3019
+
3020
+ _proto.expectOptionalKeyword = function expectOptionalKeyword(value) {
3021
+ var token = this._lexer.token;
3022
+
3023
+ if (token.kind === TokenKind.NAME && token.value === value) {
3024
+ this._lexer.advance();
3025
+
3026
+ return true;
3027
+ }
3028
+
3029
+ return false;
3030
+ }
3031
+ /**
3032
+ * Helper function for creating an error when an unexpected lexed token is encountered.
3033
+ */
3034
+ ;
3035
+
3036
+ _proto.unexpected = function unexpected(atToken) {
3037
+ var token = atToken !== null && atToken !== void 0 ? atToken : this._lexer.token;
3038
+ return syntaxError(this._lexer.source, token.start, "Unexpected ".concat(getTokenDesc(token), "."));
3039
+ }
3040
+ /**
3041
+ * Returns a possibly empty list of parse nodes, determined by the parseFn.
3042
+ * This list begins with a lex token of openKind and ends with a lex token of closeKind.
3043
+ * Advances the parser to the next lex token after the closing token.
3044
+ */
3045
+ ;
3046
+
3047
+ _proto.any = function any(openKind, parseFn, closeKind) {
3048
+ this.expectToken(openKind);
3049
+ var nodes = [];
3050
+
3051
+ while (!this.expectOptionalToken(closeKind)) {
3052
+ nodes.push(parseFn.call(this));
3053
+ }
3054
+
3055
+ return nodes;
3056
+ }
3057
+ /**
3058
+ * Returns a list of parse nodes, determined by the parseFn.
3059
+ * It can be empty only if open token is missing otherwise it will always return non-empty list
3060
+ * that begins with a lex token of openKind and ends with a lex token of closeKind.
3061
+ * Advances the parser to the next lex token after the closing token.
3062
+ */
3063
+ ;
3064
+
3065
+ _proto.optionalMany = function optionalMany(openKind, parseFn, closeKind) {
3066
+ if (this.expectOptionalToken(openKind)) {
3067
+ var nodes = [];
3068
+
3069
+ do {
3070
+ nodes.push(parseFn.call(this));
3071
+ } while (!this.expectOptionalToken(closeKind));
3072
+
3073
+ return nodes;
3074
+ }
3075
+
3076
+ return [];
3077
+ }
3078
+ /**
3079
+ * Returns a non-empty list of parse nodes, determined by the parseFn.
3080
+ * This list begins with a lex token of openKind and ends with a lex token of closeKind.
3081
+ * Advances the parser to the next lex token after the closing token.
3082
+ */
3083
+ ;
3084
+
3085
+ _proto.many = function many(openKind, parseFn, closeKind) {
3086
+ this.expectToken(openKind);
3087
+ var nodes = [];
3088
+
3089
+ do {
3090
+ nodes.push(parseFn.call(this));
3091
+ } while (!this.expectOptionalToken(closeKind));
3092
+
3093
+ return nodes;
3094
+ }
3095
+ /**
3096
+ * Returns a non-empty list of parse nodes, determined by the parseFn.
3097
+ * This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
3098
+ * Advances the parser to the next lex token after last item in the list.
3099
+ */
3100
+ ;
3101
+
3102
+ _proto.delimitedMany = function delimitedMany(delimiterKind, parseFn) {
3103
+ this.expectOptionalToken(delimiterKind);
3104
+ var nodes = [];
3105
+
3106
+ do {
3107
+ nodes.push(parseFn.call(this));
3108
+ } while (this.expectOptionalToken(delimiterKind));
3109
+
3110
+ return nodes;
3111
+ };
3112
+
3113
+ return Parser;
3114
+ }();
3115
+ /**
3116
+ * A helper function to describe a token as a string for debugging.
3117
+ */
3118
+
3119
+ function getTokenDesc(token) {
3120
+ var value = token.value;
3121
+ return getTokenKindDesc(token.kind) + (value != null ? " \"".concat(value, "\"") : '');
3122
+ }
3123
+ /**
3124
+ * A helper function to describe a token kind as a string for debugging.
3125
+ */
3126
+
3127
+
3128
+ function getTokenKindDesc(kind) {
3129
+ return isPunctuatorTokenKind(kind) ? "\"".concat(kind, "\"") : kind;
3130
+ }
3131
+
3132
+ /**
3133
+ * A visitor is provided to visit, it contains the collection of
3134
+ * relevant functions to be called during the visitor's traversal.
3135
+ */
3136
+
3137
+ var QueryDocumentKeys = {
3138
+ Name: [],
3139
+ Document: ['definitions'],
3140
+ OperationDefinition: ['name', 'variableDefinitions', 'directives', 'selectionSet'],
3141
+ VariableDefinition: ['variable', 'type', 'defaultValue', 'directives'],
3142
+ Variable: ['name'],
3143
+ SelectionSet: ['selections'],
3144
+ Field: ['alias', 'name', 'arguments', 'directives', 'selectionSet'],
3145
+ Argument: ['name', 'value'],
3146
+ FragmentSpread: ['name', 'directives'],
3147
+ InlineFragment: ['typeCondition', 'directives', 'selectionSet'],
3148
+ FragmentDefinition: ['name', // Note: fragment variable definitions are experimental and may be changed
3149
+ // or removed in the future.
3150
+ 'variableDefinitions', 'typeCondition', 'directives', 'selectionSet'],
3151
+ IntValue: [],
3152
+ FloatValue: [],
3153
+ StringValue: [],
3154
+ BooleanValue: [],
3155
+ NullValue: [],
3156
+ EnumValue: [],
3157
+ ListValue: ['values'],
3158
+ ObjectValue: ['fields'],
3159
+ ObjectField: ['name', 'value'],
3160
+ Directive: ['name', 'arguments'],
3161
+ NamedType: ['name'],
3162
+ ListType: ['type'],
3163
+ NonNullType: ['type'],
3164
+ SchemaDefinition: ['description', 'directives', 'operationTypes'],
3165
+ OperationTypeDefinition: ['type'],
3166
+ ScalarTypeDefinition: ['description', 'name', 'directives'],
3167
+ ObjectTypeDefinition: ['description', 'name', 'interfaces', 'directives', 'fields'],
3168
+ FieldDefinition: ['description', 'name', 'arguments', 'type', 'directives'],
3169
+ InputValueDefinition: ['description', 'name', 'type', 'defaultValue', 'directives'],
3170
+ InterfaceTypeDefinition: ['description', 'name', 'interfaces', 'directives', 'fields'],
3171
+ UnionTypeDefinition: ['description', 'name', 'directives', 'types'],
3172
+ EnumTypeDefinition: ['description', 'name', 'directives', 'values'],
3173
+ EnumValueDefinition: ['description', 'name', 'directives'],
3174
+ InputObjectTypeDefinition: ['description', 'name', 'directives', 'fields'],
3175
+ DirectiveDefinition: ['description', 'name', 'arguments', 'locations'],
3176
+ SchemaExtension: ['directives', 'operationTypes'],
3177
+ ScalarTypeExtension: ['name', 'directives'],
3178
+ ObjectTypeExtension: ['name', 'interfaces', 'directives', 'fields'],
3179
+ InterfaceTypeExtension: ['name', 'interfaces', 'directives', 'fields'],
3180
+ UnionTypeExtension: ['name', 'directives', 'types'],
3181
+ EnumTypeExtension: ['name', 'directives', 'values'],
3182
+ InputObjectTypeExtension: ['name', 'directives', 'fields']
3183
+ };
3184
+ var BREAK = Object.freeze({});
3185
+ /**
3186
+ * visit() will walk through an AST using a depth-first traversal, calling
3187
+ * the visitor's enter function at each node in the traversal, and calling the
3188
+ * leave function after visiting that node and all of its child nodes.
3189
+ *
3190
+ * By returning different values from the enter and leave functions, the
3191
+ * behavior of the visitor can be altered, including skipping over a sub-tree of
3192
+ * the AST (by returning false), editing the AST by returning a value or null
3193
+ * to remove the value, or to stop the whole traversal by returning BREAK.
3194
+ *
3195
+ * When using visit() to edit an AST, the original AST will not be modified, and
3196
+ * a new version of the AST with the changes applied will be returned from the
3197
+ * visit function.
3198
+ *
3199
+ * const editedAST = visit(ast, {
3200
+ * enter(node, key, parent, path, ancestors) {
3201
+ * // @return
3202
+ * // undefined: no action
3203
+ * // false: skip visiting this node
3204
+ * // visitor.BREAK: stop visiting altogether
3205
+ * // null: delete this node
3206
+ * // any value: replace this node with the returned value
3207
+ * },
3208
+ * leave(node, key, parent, path, ancestors) {
3209
+ * // @return
3210
+ * // undefined: no action
3211
+ * // false: no action
3212
+ * // visitor.BREAK: stop visiting altogether
3213
+ * // null: delete this node
3214
+ * // any value: replace this node with the returned value
3215
+ * }
3216
+ * });
3217
+ *
3218
+ * Alternatively to providing enter() and leave() functions, a visitor can
3219
+ * instead provide functions named the same as the kinds of AST nodes, or
3220
+ * enter/leave visitors at a named key, leading to four permutations of the
3221
+ * visitor API:
3222
+ *
3223
+ * 1) Named visitors triggered when entering a node of a specific kind.
3224
+ *
3225
+ * visit(ast, {
3226
+ * Kind(node) {
3227
+ * // enter the "Kind" node
3228
+ * }
3229
+ * })
3230
+ *
3231
+ * 2) Named visitors that trigger upon entering and leaving a node of
3232
+ * a specific kind.
3233
+ *
3234
+ * visit(ast, {
3235
+ * Kind: {
3236
+ * enter(node) {
3237
+ * // enter the "Kind" node
3238
+ * }
3239
+ * leave(node) {
3240
+ * // leave the "Kind" node
3241
+ * }
3242
+ * }
3243
+ * })
3244
+ *
3245
+ * 3) Generic visitors that trigger upon entering and leaving any node.
3246
+ *
3247
+ * visit(ast, {
3248
+ * enter(node) {
3249
+ * // enter any node
3250
+ * },
3251
+ * leave(node) {
3252
+ * // leave any node
3253
+ * }
3254
+ * })
3255
+ *
3256
+ * 4) Parallel visitors for entering and leaving nodes of a specific kind.
3257
+ *
3258
+ * visit(ast, {
3259
+ * enter: {
3260
+ * Kind(node) {
3261
+ * // enter the "Kind" node
3262
+ * }
3263
+ * },
3264
+ * leave: {
3265
+ * Kind(node) {
3266
+ * // leave the "Kind" node
3267
+ * }
3268
+ * }
3269
+ * })
3270
+ */
3271
+
3272
+ function visit(root, visitor) {
3273
+ var visitorKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : QueryDocumentKeys;
3274
+
3275
+ /* eslint-disable no-undef-init */
3276
+ var stack = undefined;
3277
+ var inArray = Array.isArray(root);
3278
+ var keys = [root];
3279
+ var index = -1;
3280
+ var edits = [];
3281
+ var node = undefined;
3282
+ var key = undefined;
3283
+ var parent = undefined;
3284
+ var path = [];
3285
+ var ancestors = [];
3286
+ var newRoot = root;
3287
+ /* eslint-enable no-undef-init */
3288
+
3289
+ do {
3290
+ index++;
3291
+ var isLeaving = index === keys.length;
3292
+ var isEdited = isLeaving && edits.length !== 0;
3293
+
3294
+ if (isLeaving) {
3295
+ key = ancestors.length === 0 ? undefined : path[path.length - 1];
3296
+ node = parent;
3297
+ parent = ancestors.pop();
3298
+
3299
+ if (isEdited) {
3300
+ if (inArray) {
3301
+ node = node.slice();
3302
+ } else {
3303
+ var clone = {};
3304
+
3305
+ for (var _i2 = 0, _Object$keys2 = Object.keys(node); _i2 < _Object$keys2.length; _i2++) {
3306
+ var k = _Object$keys2[_i2];
3307
+ clone[k] = node[k];
3308
+ }
3309
+
3310
+ node = clone;
3311
+ }
3312
+
3313
+ var editOffset = 0;
3314
+
3315
+ for (var ii = 0; ii < edits.length; ii++) {
3316
+ var editKey = edits[ii][0];
3317
+ var editValue = edits[ii][1];
3318
+
3319
+ if (inArray) {
3320
+ editKey -= editOffset;
3321
+ }
3322
+
3323
+ if (inArray && editValue === null) {
3324
+ node.splice(editKey, 1);
3325
+ editOffset++;
3326
+ } else {
3327
+ node[editKey] = editValue;
3328
+ }
3329
+ }
3330
+ }
3331
+
3332
+ index = stack.index;
3333
+ keys = stack.keys;
3334
+ edits = stack.edits;
3335
+ inArray = stack.inArray;
3336
+ stack = stack.prev;
3337
+ } else {
3338
+ key = parent ? inArray ? index : keys[index] : undefined;
3339
+ node = parent ? parent[key] : newRoot;
3340
+
3341
+ if (node === null || node === undefined) {
3342
+ continue;
3343
+ }
3344
+
3345
+ if (parent) {
3346
+ path.push(key);
3347
+ }
3348
+ }
3349
+
3350
+ var result = void 0;
3351
+
3352
+ if (!Array.isArray(node)) {
3353
+ if (!isNode(node)) {
3354
+ throw new Error("Invalid AST Node: ".concat(inspect(node), "."));
3355
+ }
3356
+
3357
+ var visitFn = getVisitFn(visitor, node.kind, isLeaving);
3358
+
3359
+ if (visitFn) {
3360
+ result = visitFn.call(visitor, node, key, parent, path, ancestors);
3361
+
3362
+ if (result === BREAK) {
3363
+ break;
3364
+ }
3365
+
3366
+ if (result === false) {
3367
+ if (!isLeaving) {
3368
+ path.pop();
3369
+ continue;
3370
+ }
3371
+ } else if (result !== undefined) {
3372
+ edits.push([key, result]);
3373
+
3374
+ if (!isLeaving) {
3375
+ if (isNode(result)) {
3376
+ node = result;
3377
+ } else {
3378
+ path.pop();
3379
+ continue;
3380
+ }
3381
+ }
3382
+ }
3383
+ }
3384
+ }
3385
+
3386
+ if (result === undefined && isEdited) {
3387
+ edits.push([key, node]);
3388
+ }
3389
+
3390
+ if (isLeaving) {
3391
+ path.pop();
3392
+ } else {
3393
+ var _visitorKeys$node$kin;
3394
+
3395
+ stack = {
3396
+ inArray: inArray,
3397
+ index: index,
3398
+ keys: keys,
3399
+ edits: edits,
3400
+ prev: stack
3401
+ };
3402
+ inArray = Array.isArray(node);
3403
+ keys = inArray ? node : (_visitorKeys$node$kin = visitorKeys[node.kind]) !== null && _visitorKeys$node$kin !== void 0 ? _visitorKeys$node$kin : [];
3404
+ index = -1;
3405
+ edits = [];
3406
+
3407
+ if (parent) {
3408
+ ancestors.push(parent);
3409
+ }
3410
+
3411
+ parent = node;
3412
+ }
3413
+ } while (stack !== undefined);
3414
+
3415
+ if (edits.length !== 0) {
3416
+ newRoot = edits[edits.length - 1][1];
3417
+ }
3418
+
3419
+ return newRoot;
3420
+ }
3421
+ /**
3422
+ * Given a visitor instance, if it is leaving or not, and a node kind, return
3423
+ * the function the visitor runtime should call.
3424
+ */
3425
+
3426
+ function getVisitFn(visitor, kind, isLeaving) {
3427
+ var kindVisitor = visitor[kind];
3428
+
3429
+ if (kindVisitor) {
3430
+ if (!isLeaving && typeof kindVisitor === 'function') {
3431
+ // { Kind() {} }
3432
+ return kindVisitor;
3433
+ }
3434
+
3435
+ var kindSpecificVisitor = isLeaving ? kindVisitor.leave : kindVisitor.enter;
3436
+
3437
+ if (typeof kindSpecificVisitor === 'function') {
3438
+ // { Kind: { enter() {}, leave() {} } }
3439
+ return kindSpecificVisitor;
3440
+ }
3441
+ } else {
3442
+ var specificVisitor = isLeaving ? visitor.leave : visitor.enter;
3443
+
3444
+ if (specificVisitor) {
3445
+ if (typeof specificVisitor === 'function') {
3446
+ // { enter() {}, leave() {} }
3447
+ return specificVisitor;
3448
+ }
3449
+
3450
+ var specificKindVisitor = specificVisitor[kind];
3451
+
3452
+ if (typeof specificKindVisitor === 'function') {
3453
+ // { enter: { Kind() {} }, leave: { Kind() {} } }
3454
+ return specificKindVisitor;
3455
+ }
3456
+ }
3457
+ }
3458
+ }
3459
+
3460
+ /* Util Functions */
3461
+ function isOperationDefinitionNode(input) {
3462
+ return input.kind === 'OperationDefinition';
3463
+ }
3464
+ function isFragmentDefinitionNode(input) {
3465
+ return input.kind === 'FragmentDefinition';
3466
+ }
3467
+ function isNamedTypeNode(input) {
3468
+ return input.kind === 'NamedType';
3469
+ }
3470
+ function isListTypeNode(input) {
3471
+ return input.kind === 'ListType';
3472
+ }
3473
+ function isNonNullTypeNode(input) {
3474
+ return input.kind === 'NonNullType';
3475
+ }
3476
+
3477
+ const CUSTOM_DIRECTIVE_CONNECTION = 'connection';
3478
+ const CUSTOM_DIRECTIVE_RESOURCE = 'resource';
3479
+ const NODE_KIND_CUSTOM_FIELD_SELECTION = 'CustomFieldSelection';
3480
+ const NODE_KIND_FIELD = 'Field';
3481
+ const NODE_KIND_FRAGMENT_SPREAD = 'FragmentSpread';
3482
+ const NODE_KIND_INLINE_FRAGMENT = 'InlineFragment';
3483
+ const NODE_KIND_LIST_TYPE = 'ListType';
3484
+ const NODE_KIND_NAMED_TYPE = 'NamedType';
3485
+ const NODE_KIND_NON_NULL_TYPE = 'NonNullType';
3486
+ const NODE_KIND_OBJECT_FIELD_SELECTION = 'ObjectFieldSelection';
3487
+ const NODE_KIND_SCALAR_FIELD_SELECTION = 'ScalarFieldSelection';
3488
+ const NODE_TYPE_CONNECTION = 'Connection';
3489
+
3490
+ function transform(node, transformState) {
3491
+ switch (node.kind) {
3492
+ case 'Variable':
3493
+ transformState.variablesUsed[node.name.value] = true;
3494
+ return {
3495
+ kind: 'Variable',
3496
+ name: node.name.value,
3497
+ };
3498
+ case 'IntValue':
3499
+ return {
3500
+ kind: 'IntValue',
3501
+ value: node.value,
3502
+ };
3503
+ case 'FloatValue':
3504
+ return {
3505
+ kind: 'FloatValue',
3506
+ value: node.value,
3507
+ };
3508
+ case 'StringValue':
3509
+ return {
3510
+ kind: 'StringValue',
3511
+ value: node.value,
3512
+ };
3513
+ case 'BooleanValue':
3514
+ return {
3515
+ kind: 'BooleanValue',
3516
+ value: node.value,
3517
+ };
3518
+ case 'EnumValue':
3519
+ return {
3520
+ kind: 'EnumValue',
3521
+ value: node.value,
3522
+ };
3523
+ case 'NullValue':
3524
+ return {
3525
+ kind: 'NullValue',
3526
+ };
3527
+ case 'ListValue': {
3528
+ const values = [];
3529
+ for (var index = 0; index < node.values.length; index++) {
3530
+ const value = transform(node.values[index], transformState);
3531
+ values.push(value);
3532
+ }
3533
+ return {
3534
+ kind: 'ListValue',
3535
+ values: values,
3536
+ };
3537
+ }
3538
+ case 'ObjectValue': {
3539
+ const { fields } = node;
3540
+ const result = {};
3541
+ fields.forEach((field) => {
3542
+ const name = field.name.value;
3543
+ const value = transform(field.value, transformState);
3544
+ result[name] = value;
3545
+ });
3546
+ return {
3547
+ kind: 'ObjectValue',
3548
+ fields: result,
3549
+ };
3550
+ }
3551
+ default:
3552
+ throw new Error('Unsupported ValueNode kind');
3553
+ }
3554
+ }
3555
+
3556
+ function transform$1(node, transformState) {
3557
+ const { kind, name: { value: nodeName }, value: nodeValue, } = node;
3558
+ const valueNode = transform(nodeValue, transformState);
3559
+ return {
3560
+ kind,
3561
+ name: nodeName,
3562
+ value: valueNode,
3563
+ };
3564
+ }
3565
+
3566
+ function transform$2(node, transformState) {
3567
+ const { kind, name: { value: nodeName }, arguments: nodeArguments, } = node;
3568
+ const ret = {
3569
+ kind,
3570
+ name: nodeName,
3571
+ };
3572
+ if (nodeArguments !== undefined && nodeArguments.length > 0) {
3573
+ let returnArguments = [];
3574
+ for (var index = 0; index < nodeArguments.length; index++) {
3575
+ const argumentNode = nodeArguments[index];
3576
+ const value = transform$1(argumentNode, transformState);
3577
+ returnArguments.push(value);
3578
+ }
3579
+ ret.arguments = returnArguments;
3580
+ }
3581
+ return ret;
3582
+ }
3583
+ function isCustomDirective(node) {
3584
+ return (node.name.value === CUSTOM_DIRECTIVE_CONNECTION ||
3585
+ node.name.value === CUSTOM_DIRECTIVE_RESOURCE);
3586
+ }
3587
+
3588
+ function transform$3(node, transformState) {
3589
+ const { name, alias, arguments: fieldArgs, selectionSet, directives } = node;
3590
+ let luvioNode = {
3591
+ kind: NODE_KIND_OBJECT_FIELD_SELECTION,
3592
+ name: name.value,
3593
+ luvioSelections: [],
3594
+ };
3595
+ if (selectionSet === undefined || selectionSet.selections.length === 0) {
3596
+ luvioNode = {
3597
+ kind: NODE_KIND_SCALAR_FIELD_SELECTION,
3598
+ name: name.value,
3599
+ };
3600
+ }
3601
+ else {
3602
+ // object or custom field node
3603
+ if (directives !== undefined && directives.length > 0) {
3604
+ const customDirectiveNode = directives.find(isCustomDirective);
3605
+ if (customDirectiveNode === undefined) {
3606
+ // transform non client-side directives
3607
+ luvioNode.directives = directives.map((directive) => transform$2(directive, transformState));
3608
+ }
3609
+ else {
3610
+ if (customDirectiveNode.name.value === CUSTOM_DIRECTIVE_CONNECTION) {
3611
+ luvioNode = {
3612
+ kind: NODE_KIND_CUSTOM_FIELD_SELECTION,
3613
+ name: name.value,
3614
+ type: NODE_TYPE_CONNECTION,
3615
+ luvioSelections: [],
3616
+ };
3617
+ }
3618
+ else if (customDirectiveNode.name.value === CUSTOM_DIRECTIVE_RESOURCE) {
3619
+ luvioNode = {
3620
+ kind: NODE_KIND_CUSTOM_FIELD_SELECTION,
3621
+ name: name.value,
3622
+ type: customDirectiveNode.arguments[0].value.value,
3623
+ luvioSelections: [],
3624
+ };
3625
+ }
3626
+ }
3627
+ }
3628
+ if (fieldArgs !== undefined && fieldArgs.length > 0) {
3629
+ const returnArguments = [];
3630
+ for (var index = 0; index < fieldArgs.length; index++) {
3631
+ const value = transform$1(fieldArgs[index], transformState);
3632
+ returnArguments.push(value);
3633
+ }
3634
+ luvioNode.arguments = returnArguments;
3635
+ }
3636
+ }
3637
+ if (alias !== undefined) {
3638
+ luvioNode.alias = alias.value;
3639
+ }
3640
+ return luvioNode;
3641
+ }
3642
+
3643
+ function transform$4(node, transformState) {
3644
+ const { kind, name: { value }, directives, } = node;
3645
+ const luvioNode = {
3646
+ kind,
3647
+ name: value,
3648
+ };
3649
+ if (directives !== undefined && directives.length > 0) {
3650
+ luvioNode.directives = directives.map((directive) => transform$2(directive, transformState));
3651
+ }
3652
+ return luvioNode;
3653
+ }
3654
+
3655
+ function transform$5(node, transformState) {
3656
+ const { kind: nodeKind, typeCondition, directives } = node;
3657
+ const luvioNode = {
3658
+ kind: nodeKind,
3659
+ luvioSelections: [],
3660
+ };
3661
+ if (typeCondition !== undefined) {
3662
+ luvioNode.typeCondition = {
3663
+ kind: typeCondition.kind,
3664
+ name: typeCondition.name.value,
3665
+ };
3666
+ }
3667
+ if (directives !== undefined && directives.length > 0) {
3668
+ luvioNode.directives = directives.map((directive) => transform$2(directive, transformState));
3669
+ }
3670
+ return luvioNode;
3671
+ }
3672
+
3673
+ function selectionSetVisitor(ast, luvioSelectionPath, transformState) {
3674
+ const visitor = {
3675
+ enter(node) {
3676
+ let selectionNode;
3677
+ switch (node.kind) {
3678
+ case NODE_KIND_FIELD: {
3679
+ const fieldNode = transform$3(node, transformState);
3680
+ selectionNode = fieldNode;
3681
+ break;
3682
+ }
3683
+ case NODE_KIND_FRAGMENT_SPREAD:
3684
+ selectionNode = transform$4(node, transformState);
3685
+ break;
3686
+ case NODE_KIND_INLINE_FRAGMENT:
3687
+ selectionNode = transform$5(node, transformState);
3688
+ break;
3689
+ }
3690
+ if (selectionNode !== undefined) {
3691
+ const parentNode = luvioSelectionPath[luvioSelectionPath.length - 1];
3692
+ if (parentNode.kind === NODE_KIND_OBJECT_FIELD_SELECTION ||
3693
+ parentNode.kind === NODE_KIND_CUSTOM_FIELD_SELECTION ||
3694
+ parentNode.kind === NODE_KIND_INLINE_FRAGMENT) {
3695
+ parentNode.luvioSelections.push(selectionNode);
3696
+ }
3697
+ luvioSelectionPath.push(selectionNode);
3698
+ }
3699
+ },
3700
+ leave(node) {
3701
+ switch (node.kind) {
3702
+ case NODE_KIND_FIELD:
3703
+ case NODE_KIND_FRAGMENT_SPREAD:
3704
+ case NODE_KIND_INLINE_FRAGMENT:
3705
+ luvioSelectionPath.pop();
3706
+ break;
3707
+ }
3708
+ },
3709
+ };
3710
+ visit(ast, visitor);
3711
+ }
3712
+
3713
+ function transform$6(node) {
3714
+ if (isNamedTypeNode(node)) {
3715
+ return {
3716
+ kind: NODE_KIND_NAMED_TYPE,
3717
+ name: node.name.value,
3718
+ };
3719
+ }
3720
+ else if (isListTypeNode(node)) {
3721
+ return {
3722
+ kind: NODE_KIND_LIST_TYPE,
3723
+ type: transform$6(node.type),
3724
+ };
3725
+ }
3726
+ else if (isNonNullTypeNode(node)) {
3727
+ if (isNamedTypeNode(node.type)) {
3728
+ return {
3729
+ kind: NODE_KIND_NON_NULL_TYPE,
3730
+ type: {
3731
+ kind: NODE_KIND_NAMED_TYPE,
3732
+ name: node.type.name.value,
3733
+ },
3734
+ };
3735
+ }
3736
+ else if (isListTypeNode(node.type)) {
3737
+ return {
3738
+ kind: NODE_KIND_NON_NULL_TYPE,
3739
+ type: {
3740
+ kind: NODE_KIND_LIST_TYPE,
3741
+ type: transform$6(node.type.type),
3742
+ },
3743
+ };
3744
+ }
3745
+ else {
3746
+ throw new Error('Unsupported NonNullTypeNode');
3747
+ }
3748
+ }
3749
+ else {
3750
+ throw new Error('Unsupported TypeNode');
3751
+ }
3752
+ }
3753
+
3754
+ function transform$7(variableDefinitions, transformState) {
3755
+ const { kind, variable: { kind: variableKind, name: { value: variableName }, }, type, defaultValue, } = variableDefinitions;
3756
+ const ret = {
3757
+ kind,
3758
+ variable: {
3759
+ kind: variableKind,
3760
+ name: variableName,
3761
+ },
3762
+ type: transform$6(type),
3763
+ };
3764
+ if (defaultValue !== undefined) {
3765
+ const value = transform(defaultValue, transformState);
3766
+ ret.defaultValue = value;
3767
+ }
3768
+ // TODO: transform directives
3769
+ return ret;
3770
+ }
3771
+
3772
+ function transform$8(node) {
3773
+ const queryRoot = {
3774
+ kind: 'ObjectFieldSelection',
3775
+ name: 'query',
3776
+ luvioSelections: [],
3777
+ };
3778
+ const currentNodePath = [queryRoot];
3779
+ const transformState = {
3780
+ variablesUsed: {},
3781
+ };
3782
+ selectionSetVisitor(node, currentNodePath, transformState);
3783
+ const operationDefinition = {
3784
+ kind: 'OperationDefinition',
3785
+ operation: 'query',
3786
+ luvioSelections: queryRoot.luvioSelections,
3787
+ };
3788
+ if (node.name !== undefined) {
3789
+ operationDefinition.name = node.name.value;
3790
+ }
3791
+ const { variableDefinitions, directives } = node;
3792
+ if (variableDefinitions !== undefined && variableDefinitions.length > 0) {
3793
+ operationDefinition.variableDefinitions = variableDefinitions.map((variableDefinition) => transform$7(variableDefinition, transformState));
3794
+ }
3795
+ if (directives !== undefined && directives.length > 0) {
3796
+ operationDefinition.directives = directives.map((node) => transform$2(node, transformState));
3797
+ }
3798
+ validateVariables(variableDefinitions, transformState);
3799
+ return operationDefinition;
3800
+ }
3801
+ function validateVariables(variableDefinitions, transformState) {
3802
+ const variablesDefined = {};
3803
+ if (variableDefinitions !== undefined) {
3804
+ for (let i = 0, len = variableDefinitions.length; i < len; i++) {
3805
+ const definedVariableName = variableDefinitions[i].variable.name.value;
3806
+ variablesDefined[definedVariableName] = true;
3807
+ if (transformState.variablesUsed[definedVariableName] === undefined) {
3808
+ if (process.env.NODE_ENV !== 'production') {
3809
+ throw new Error(`Variable $${definedVariableName} was defined but never used.`);
3810
+ }
3811
+ }
3812
+ }
3813
+ }
3814
+ const usedVariableKeys = Object.keys(transformState.variablesUsed);
3815
+ for (let i = 0, len = usedVariableKeys.length; i < len; i++) {
3816
+ if (variablesDefined[usedVariableKeys[i]] !== true) {
3817
+ if (process.env.NODE_ENV !== 'production') {
3818
+ throw new Error(`Variable $${usedVariableKeys[i]} was used but never defined.`);
3819
+ }
3820
+ }
3821
+ }
3822
+ }
3823
+
3824
+ function transform$9(node) {
3825
+ const { operation } = node;
3826
+ if (operation === 'query') {
3827
+ return transform$8(node);
3828
+ }
3829
+ throw new Error(`Unsupported ${operation} operation. Only query operation is supported`);
3830
+ }
3831
+
3832
+ function transform$a(node) {
3833
+ const { kind: nodeKind, name: { value: nodeName }, typeCondition: { kind: typeKind, name: { value: typeName }, }, directives, } = node;
3834
+ // dummy root node
3835
+ const fragmentRoot = {
3836
+ kind: NODE_KIND_OBJECT_FIELD_SELECTION,
3837
+ name: 'fragment',
3838
+ luvioSelections: [],
3839
+ };
3840
+ const currentNodePath = [fragmentRoot];
3841
+ const transformState = { variablesUsed: {} };
3842
+ selectionSetVisitor(node, currentNodePath, transformState);
3843
+ const luvioNode = {
3844
+ kind: nodeKind,
3845
+ name: nodeName,
3846
+ typeCondition: {
3847
+ kind: typeKind,
3848
+ name: typeName,
3849
+ },
3850
+ luvioSelections: fragmentRoot.luvioSelections,
3851
+ };
3852
+ if (directives !== undefined && directives.length > 0) {
3853
+ luvioNode.directives = directives.map((node) => transform$2(node, transformState));
3854
+ }
3855
+ return luvioNode;
3856
+ }
3857
+
3858
+ function transform$b(root) {
3859
+ const { kind, definitions } = root;
3860
+ const luvioDefinitions = [];
3861
+ for (let i = 0; i < definitions.length; i++) {
3862
+ const definition = definitions[i];
3863
+ if (isOperationDefinitionNode(definition)) {
3864
+ luvioDefinitions.push(transform$9(definition));
3865
+ }
3866
+ else if (isFragmentDefinitionNode(definition)) {
3867
+ luvioDefinitions.push(transform$a(definition));
3868
+ }
3869
+ else {
3870
+ if (process.env.NODE_ENV !== 'production') {
3871
+ throw new Error(`Unsupported ${definition.kind} definition. Only OperationDefinition and FragmentDefinition are supported in a GraphQL Document`);
3872
+ }
3873
+ }
3874
+ }
3875
+ return {
3876
+ kind,
3877
+ definitions: luvioDefinitions,
3878
+ };
3879
+ }
3880
+
3881
+ function parseAndVisit(source) {
3882
+ // TODO: handle generic <Type>
3883
+ const ast = parse(source);
3884
+ return transform$b(ast);
3885
+ }
3886
+
3887
+ exports.parseAndVisit = parseAndVisit;