@bcrumbs.net/bc-api 0.0.19 → 0.0.21

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