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