@bcrumbs.net/bc-api 0.0.34 → 0.0.35

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