msw 0.36.5 → 0.38.1
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/README.md +3 -1
- package/lib/esm/fetch-deps.js +14 -12
- package/lib/esm/graphql-deps.js +1980 -1804
- package/lib/esm/index.js +60 -45
- package/lib/esm/mockServiceWorker.js +1 -1
- package/lib/iife/index.js +3 -3
- package/lib/iife/mockServiceWorker.js +1 -1
- package/lib/types/graphql.d.ts +6 -6
- package/lib/types/handlers/RequestHandler.d.ts +2 -2
- package/lib/types/response.d.ts +1 -1
- package/lib/types/setupWorker/glossary.d.ts +1 -1
- package/lib/types/utils/logging/prepareResponse.d.ts +2 -2
- package/lib/types/utils/request/onUnhandledRequest.d.ts +5 -1
- package/lib/types/utils/request/parseBody.d.ts +1 -1
- package/lib/umd/index.js +17091 -14331
- package/lib/umd/mockServiceWorker.js +1 -1
- package/native/lib/index.js +2026 -1833
- package/node/lib/index.js +2026 -1833
- package/package.json +23 -24
package/node/lib/index.js
CHANGED
|
@@ -2069,7 +2069,6 @@ var serialize_1 = serialize;
|
|
|
2069
2069
|
|
|
2070
2070
|
var decode = decodeURIComponent;
|
|
2071
2071
|
var encode = encodeURIComponent;
|
|
2072
|
-
var pairSplitRegExp = /; */;
|
|
2073
2072
|
|
|
2074
2073
|
/**
|
|
2075
2074
|
* RegExp to match field-content in RFC 7230 sec 3.2
|
|
@@ -2100,28 +2099,29 @@ function parse$2(str, options) {
|
|
|
2100
2099
|
|
|
2101
2100
|
var obj = {};
|
|
2102
2101
|
var opt = options || {};
|
|
2103
|
-
var pairs = str.split(
|
|
2102
|
+
var pairs = str.split(';');
|
|
2104
2103
|
var dec = opt.decode || decode;
|
|
2105
2104
|
|
|
2106
2105
|
for (var i = 0; i < pairs.length; i++) {
|
|
2107
2106
|
var pair = pairs[i];
|
|
2108
|
-
var
|
|
2107
|
+
var index = pair.indexOf('=');
|
|
2109
2108
|
|
|
2110
2109
|
// skip things that don't look like key=value
|
|
2111
|
-
if (
|
|
2110
|
+
if (index < 0) {
|
|
2112
2111
|
continue;
|
|
2113
2112
|
}
|
|
2114
2113
|
|
|
2115
|
-
var key = pair.
|
|
2116
|
-
var val = pair.substr(++eq_idx, pair.length).trim();
|
|
2117
|
-
|
|
2118
|
-
// quoted values
|
|
2119
|
-
if ('"' == val[0]) {
|
|
2120
|
-
val = val.slice(1, -1);
|
|
2121
|
-
}
|
|
2114
|
+
var key = pair.substring(0, index).trim();
|
|
2122
2115
|
|
|
2123
2116
|
// only assign once
|
|
2124
2117
|
if (undefined == obj[key]) {
|
|
2118
|
+
var val = pair.substring(index + 1, pair.length).trim();
|
|
2119
|
+
|
|
2120
|
+
// quoted values
|
|
2121
|
+
if (val[0] === '"') {
|
|
2122
|
+
val = val.slice(1, -1);
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
2125
|
obj[key] = tryDecode(val, dec);
|
|
2126
2126
|
}
|
|
2127
2127
|
}
|
|
@@ -3277,20 +3277,33 @@ var jsLevenshtein = (function()
|
|
|
3277
3277
|
};
|
|
3278
3278
|
})();
|
|
3279
3279
|
|
|
3280
|
-
function
|
|
3280
|
+
function devAssert(condition, message) {
|
|
3281
|
+
const booleanCondition = Boolean(condition);
|
|
3282
|
+
|
|
3283
|
+
if (!booleanCondition) {
|
|
3284
|
+
throw new Error(message);
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3281
3287
|
|
|
3282
3288
|
/**
|
|
3283
3289
|
* Return true if `value` is object-like. A value is object-like if it's not
|
|
3284
3290
|
* `null` and has a `typeof` result of "object".
|
|
3285
3291
|
*/
|
|
3286
3292
|
function isObjectLike(value) {
|
|
3287
|
-
return
|
|
3293
|
+
return typeof value == 'object' && value !== null;
|
|
3288
3294
|
}
|
|
3289
3295
|
|
|
3290
|
-
|
|
3296
|
+
function invariant(condition, message) {
|
|
3297
|
+
const booleanCondition = Boolean(condition);
|
|
3291
3298
|
|
|
3292
|
-
|
|
3299
|
+
if (!booleanCondition) {
|
|
3300
|
+
throw new Error(
|
|
3301
|
+
message != null ? message : 'Unexpected invariant triggered.',
|
|
3302
|
+
);
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3293
3305
|
|
|
3306
|
+
const LineRegExp = /\r\n|[\n\r]/g;
|
|
3294
3307
|
/**
|
|
3295
3308
|
* Represents a location in a Source.
|
|
3296
3309
|
*/
|
|
@@ -3300,115 +3313,107 @@ var SYMBOL_TO_STRING_TAG = typeof Symbol === 'function' && Symbol.toStringTag !=
|
|
|
3300
3313
|
* line and column as a SourceLocation.
|
|
3301
3314
|
*/
|
|
3302
3315
|
function getLocation(source, position) {
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3316
|
+
let lastLineStart = 0;
|
|
3317
|
+
let line = 1;
|
|
3318
|
+
|
|
3319
|
+
for (const match of source.body.matchAll(LineRegExp)) {
|
|
3320
|
+
typeof match.index === 'number' || invariant(false);
|
|
3307
3321
|
|
|
3308
|
-
|
|
3322
|
+
if (match.index >= position) {
|
|
3323
|
+
break;
|
|
3324
|
+
}
|
|
3325
|
+
|
|
3326
|
+
lastLineStart = match.index + match[0].length;
|
|
3309
3327
|
line += 1;
|
|
3310
|
-
column = position + 1 - (match.index + match[0].length);
|
|
3311
3328
|
}
|
|
3312
3329
|
|
|
3313
3330
|
return {
|
|
3314
|
-
line
|
|
3315
|
-
column:
|
|
3331
|
+
line,
|
|
3332
|
+
column: position + 1 - lastLineStart,
|
|
3316
3333
|
};
|
|
3317
3334
|
}
|
|
3318
3335
|
|
|
3319
3336
|
/**
|
|
3320
3337
|
* Render a helpful description of the location in the GraphQL Source document.
|
|
3321
3338
|
*/
|
|
3322
|
-
|
|
3323
3339
|
function printLocation(location) {
|
|
3324
|
-
return printSourceLocation(
|
|
3340
|
+
return printSourceLocation(
|
|
3341
|
+
location.source,
|
|
3342
|
+
getLocation(location.source, location.start),
|
|
3343
|
+
);
|
|
3325
3344
|
}
|
|
3326
3345
|
/**
|
|
3327
3346
|
* Render a helpful description of the location in the GraphQL Source document.
|
|
3328
3347
|
*/
|
|
3329
3348
|
|
|
3330
3349
|
function printSourceLocation(source, sourceLocation) {
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3350
|
+
const firstLineColumnOffset = source.locationOffset.column - 1;
|
|
3351
|
+
const body = ''.padStart(firstLineColumnOffset) + source.body;
|
|
3352
|
+
const lineIndex = sourceLocation.line - 1;
|
|
3353
|
+
const lineOffset = source.locationOffset.line - 1;
|
|
3354
|
+
const lineNum = sourceLocation.line + lineOffset;
|
|
3355
|
+
const columnOffset = sourceLocation.line === 1 ? firstLineColumnOffset : 0;
|
|
3356
|
+
const columnNum = sourceLocation.column + columnOffset;
|
|
3357
|
+
const locationStr = `${source.name}:${lineNum}:${columnNum}\n`;
|
|
3358
|
+
const lines = body.split(/\r\n|[\n\r]/g);
|
|
3359
|
+
const locationLine = lines[lineIndex]; // Special case for minified documents
|
|
3341
3360
|
|
|
3342
3361
|
if (locationLine.length > 120) {
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3362
|
+
const subLineIndex = Math.floor(columnNum / 80);
|
|
3363
|
+
const subLineColumnNum = columnNum % 80;
|
|
3364
|
+
const subLines = [];
|
|
3346
3365
|
|
|
3347
|
-
for (
|
|
3366
|
+
for (let i = 0; i < locationLine.length; i += 80) {
|
|
3348
3367
|
subLines.push(locationLine.slice(i, i + 80));
|
|
3349
3368
|
}
|
|
3350
3369
|
|
|
3351
|
-
return
|
|
3352
|
-
|
|
3353
|
-
|
|
3370
|
+
return (
|
|
3371
|
+
locationStr +
|
|
3372
|
+
printPrefixedLines([
|
|
3373
|
+
[`${lineNum} |`, subLines[0]],
|
|
3374
|
+
...subLines.slice(1, subLineIndex + 1).map((subLine) => ['|', subLine]),
|
|
3375
|
+
['|', '^'.padStart(subLineColumnNum)],
|
|
3376
|
+
['|', subLines[subLineIndex + 1]],
|
|
3377
|
+
])
|
|
3378
|
+
);
|
|
3354
3379
|
}
|
|
3355
3380
|
|
|
3356
|
-
return
|
|
3357
|
-
|
|
3381
|
+
return (
|
|
3382
|
+
locationStr +
|
|
3383
|
+
printPrefixedLines([
|
|
3384
|
+
// Lines specified like this: ["prefix", "string"],
|
|
3385
|
+
[`${lineNum - 1} |`, lines[lineIndex - 1]],
|
|
3386
|
+
[`${lineNum} |`, locationLine],
|
|
3387
|
+
['|', '^'.padStart(columnNum)],
|
|
3388
|
+
[`${lineNum + 1} |`, lines[lineIndex + 1]],
|
|
3389
|
+
])
|
|
3390
|
+
);
|
|
3358
3391
|
}
|
|
3359
3392
|
|
|
3360
3393
|
function printPrefixedLines(lines) {
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
var padLen = Math.max.apply(Math, existingLines.map(function (_ref2) {
|
|
3367
|
-
var prefix = _ref2[0];
|
|
3368
|
-
return prefix.length;
|
|
3369
|
-
}));
|
|
3370
|
-
return existingLines.map(function (_ref3) {
|
|
3371
|
-
var prefix = _ref3[0],
|
|
3372
|
-
line = _ref3[1];
|
|
3373
|
-
return leftPad(padLen, prefix) + (line ? ' | ' + line : ' |');
|
|
3374
|
-
}).join('\n');
|
|
3375
|
-
}
|
|
3376
|
-
|
|
3377
|
-
function whitespace(len) {
|
|
3378
|
-
return Array(len + 1).join(' ');
|
|
3379
|
-
}
|
|
3380
|
-
|
|
3381
|
-
function leftPad(len, str) {
|
|
3382
|
-
return whitespace(len - str.length) + str;
|
|
3394
|
+
const existingLines = lines.filter(([_, line]) => line !== undefined);
|
|
3395
|
+
const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
|
|
3396
|
+
return existingLines
|
|
3397
|
+
.map(([prefix, line]) => prefix.padStart(padLen) + (line ? ' ' + line : ''))
|
|
3398
|
+
.join('\n');
|
|
3383
3399
|
}
|
|
3384
3400
|
|
|
3385
|
-
function
|
|
3386
|
-
|
|
3387
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3388
|
-
|
|
3389
|
-
function _defineProperties$1(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
3390
|
-
|
|
3391
|
-
function _createClass$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1(Constructor, staticProps); return Constructor; }
|
|
3392
|
-
|
|
3393
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
3394
|
-
|
|
3395
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
3396
|
-
|
|
3397
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof$2(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
3398
|
-
|
|
3399
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
3401
|
+
function toNormalizedArgs(args) {
|
|
3402
|
+
const firstArg = args[0];
|
|
3400
3403
|
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3404
|
+
if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
|
|
3405
|
+
return {
|
|
3406
|
+
nodes: firstArg,
|
|
3407
|
+
source: args[1],
|
|
3408
|
+
positions: args[2],
|
|
3409
|
+
path: args[3],
|
|
3410
|
+
originalError: args[4],
|
|
3411
|
+
extensions: args[5],
|
|
3412
|
+
};
|
|
3413
|
+
}
|
|
3410
3414
|
|
|
3411
|
-
|
|
3415
|
+
return firstArg;
|
|
3416
|
+
}
|
|
3412
3417
|
/**
|
|
3413
3418
|
* A GraphQLError describes an Error found during the parse, validate, or
|
|
3414
3419
|
* execute phases of performing a GraphQL operation. In addition to a message
|
|
@@ -3416,21 +3421,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
3416
3421
|
* GraphQL document and/or execution result that correspond to the Error.
|
|
3417
3422
|
*/
|
|
3418
3423
|
|
|
3419
|
-
|
|
3420
|
-
_inherits(GraphQLError, _Error);
|
|
3421
|
-
|
|
3422
|
-
var _super = _createSuper(GraphQLError);
|
|
3423
|
-
|
|
3424
|
-
/**
|
|
3425
|
-
* A message describing the Error for debugging purposes.
|
|
3426
|
-
*
|
|
3427
|
-
* Enumerable, and appears in the result of JSON.stringify().
|
|
3428
|
-
*
|
|
3429
|
-
* Note: should be treated as readonly, despite invariant usage.
|
|
3430
|
-
*/
|
|
3431
|
-
|
|
3424
|
+
class GraphQLError extends Error {
|
|
3432
3425
|
/**
|
|
3433
|
-
* An array of { line, column } locations within the source GraphQL document
|
|
3426
|
+
* An array of `{ line, column }` locations within the source GraphQL document
|
|
3434
3427
|
* which correspond to this error.
|
|
3435
3428
|
*
|
|
3436
3429
|
* Errors during validation often contain multiple locations, for example to
|
|
@@ -3470,184 +3463,163 @@ var GraphQLError = /*#__PURE__*/function (_Error) {
|
|
|
3470
3463
|
/**
|
|
3471
3464
|
* Extension fields to add to the formatted error.
|
|
3472
3465
|
*/
|
|
3473
|
-
function GraphQLError(message, nodes, source, positions, path, originalError, extensions) {
|
|
3474
|
-
var _locations2, _source2, _positions2, _extensions2;
|
|
3475
|
-
|
|
3476
|
-
var _this;
|
|
3477
|
-
|
|
3478
|
-
_classCallCheck(this, GraphQLError);
|
|
3479
|
-
|
|
3480
|
-
_this = _super.call(this, message); // Compute list of blame nodes.
|
|
3481
|
-
|
|
3482
|
-
var _nodes = Array.isArray(nodes) ? nodes.length !== 0 ? nodes : undefined : nodes ? [nodes] : undefined; // Compute locations in the source for the given nodes/positions.
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
var _source = source;
|
|
3486
|
-
|
|
3487
|
-
if (!_source && _nodes) {
|
|
3488
|
-
var _nodes$0$loc;
|
|
3489
|
-
|
|
3490
|
-
_source = (_nodes$0$loc = _nodes[0].loc) === null || _nodes$0$loc === void 0 ? void 0 : _nodes$0$loc.source;
|
|
3491
|
-
}
|
|
3492
|
-
|
|
3493
|
-
var _positions = positions;
|
|
3494
|
-
|
|
3495
|
-
if (!_positions && _nodes) {
|
|
3496
|
-
_positions = _nodes.reduce(function (list, node) {
|
|
3497
|
-
if (node.loc) {
|
|
3498
|
-
list.push(node.loc.start);
|
|
3499
|
-
}
|
|
3500
|
-
|
|
3501
|
-
return list;
|
|
3502
|
-
}, []);
|
|
3503
|
-
}
|
|
3504
|
-
|
|
3505
|
-
if (_positions && _positions.length === 0) {
|
|
3506
|
-
_positions = undefined;
|
|
3507
|
-
}
|
|
3508
|
-
|
|
3509
|
-
var _locations;
|
|
3510
|
-
|
|
3511
|
-
if (positions && source) {
|
|
3512
|
-
_locations = positions.map(function (pos) {
|
|
3513
|
-
return getLocation(source, pos);
|
|
3514
|
-
});
|
|
3515
|
-
} else if (_nodes) {
|
|
3516
|
-
_locations = _nodes.reduce(function (list, node) {
|
|
3517
|
-
if (node.loc) {
|
|
3518
|
-
list.push(getLocation(node.loc.source, node.loc.start));
|
|
3519
|
-
}
|
|
3520
|
-
|
|
3521
|
-
return list;
|
|
3522
|
-
}, []);
|
|
3523
|
-
}
|
|
3524
3466
|
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3467
|
+
/**
|
|
3468
|
+
* @deprecated Please use the `GraphQLErrorArgs` constructor overload instead.
|
|
3469
|
+
*/
|
|
3470
|
+
constructor(message, ...rawArgs) {
|
|
3471
|
+
var _this$nodes, _nodeLocations$, _ref;
|
|
3472
|
+
|
|
3473
|
+
const { nodes, source, positions, path, originalError, extensions } =
|
|
3474
|
+
toNormalizedArgs(rawArgs);
|
|
3475
|
+
super(message);
|
|
3476
|
+
this.name = 'GraphQLError';
|
|
3477
|
+
this.path = path !== null && path !== void 0 ? path : undefined;
|
|
3478
|
+
this.originalError =
|
|
3479
|
+
originalError !== null && originalError !== void 0
|
|
3480
|
+
? originalError
|
|
3481
|
+
: undefined; // Compute list of blame nodes.
|
|
3482
|
+
|
|
3483
|
+
this.nodes = undefinedIfEmpty(
|
|
3484
|
+
Array.isArray(nodes) ? nodes : nodes ? [nodes] : undefined,
|
|
3485
|
+
);
|
|
3486
|
+
const nodeLocations = undefinedIfEmpty(
|
|
3487
|
+
(_this$nodes = this.nodes) === null || _this$nodes === void 0
|
|
3488
|
+
? void 0
|
|
3489
|
+
: _this$nodes.map((node) => node.loc).filter((loc) => loc != null),
|
|
3490
|
+
); // Compute locations in the source for the given nodes/positions.
|
|
3491
|
+
|
|
3492
|
+
this.source =
|
|
3493
|
+
source !== null && source !== void 0
|
|
3494
|
+
? source
|
|
3495
|
+
: nodeLocations === null || nodeLocations === void 0
|
|
3496
|
+
? void 0
|
|
3497
|
+
: (_nodeLocations$ = nodeLocations[0]) === null ||
|
|
3498
|
+
_nodeLocations$ === void 0
|
|
3499
|
+
? void 0
|
|
3500
|
+
: _nodeLocations$.source;
|
|
3501
|
+
this.positions =
|
|
3502
|
+
positions !== null && positions !== void 0
|
|
3503
|
+
? positions
|
|
3504
|
+
: nodeLocations === null || nodeLocations === void 0
|
|
3505
|
+
? void 0
|
|
3506
|
+
: nodeLocations.map((loc) => loc.start);
|
|
3507
|
+
this.locations =
|
|
3508
|
+
positions && source
|
|
3509
|
+
? positions.map((pos) => getLocation(source, pos))
|
|
3510
|
+
: nodeLocations === null || nodeLocations === void 0
|
|
3511
|
+
? void 0
|
|
3512
|
+
: nodeLocations.map((loc) => getLocation(loc.source, loc.start));
|
|
3513
|
+
const originalExtensions = isObjectLike(
|
|
3514
|
+
originalError === null || originalError === void 0
|
|
3515
|
+
? void 0
|
|
3516
|
+
: originalError.extensions,
|
|
3517
|
+
)
|
|
3518
|
+
? originalError === null || originalError === void 0
|
|
3519
|
+
? void 0
|
|
3520
|
+
: originalError.extensions
|
|
3521
|
+
: undefined;
|
|
3522
|
+
this.extensions =
|
|
3523
|
+
(_ref =
|
|
3524
|
+
extensions !== null && extensions !== void 0
|
|
3525
|
+
? extensions
|
|
3526
|
+
: originalExtensions) !== null && _ref !== void 0
|
|
3527
|
+
? _ref
|
|
3528
|
+
: Object.create(null); // Only properties prescribed by the spec should be enumerable.
|
|
3529
|
+
// Keep the rest as non-enumerable.
|
|
3530
|
+
|
|
3531
|
+
Object.defineProperties(this, {
|
|
3539
3532
|
message: {
|
|
3540
|
-
|
|
3541
|
-
// By being enumerable, JSON.stringify will include `message` in the
|
|
3542
|
-
// resulting output. This ensures that the simplest possible GraphQL
|
|
3543
|
-
// service adheres to the spec.
|
|
3533
|
+
writable: true,
|
|
3544
3534
|
enumerable: true,
|
|
3545
|
-
writable: true
|
|
3546
3535
|
},
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
// in JSON.stringify() when not provided.
|
|
3550
|
-
value: (_locations2 = _locations) !== null && _locations2 !== void 0 ? _locations2 : undefined,
|
|
3551
|
-
// By being enumerable, JSON.stringify will include `locations` in the
|
|
3552
|
-
// resulting output. This ensures that the simplest possible GraphQL
|
|
3553
|
-
// service adheres to the spec.
|
|
3554
|
-
enumerable: _locations != null
|
|
3555
|
-
},
|
|
3556
|
-
path: {
|
|
3557
|
-
// Coercing falsy values to undefined ensures they will not be included
|
|
3558
|
-
// in JSON.stringify() when not provided.
|
|
3559
|
-
value: path !== null && path !== void 0 ? path : undefined,
|
|
3560
|
-
// By being enumerable, JSON.stringify will include `path` in the
|
|
3561
|
-
// resulting output. This ensures that the simplest possible GraphQL
|
|
3562
|
-
// service adheres to the spec.
|
|
3563
|
-
enumerable: path != null
|
|
3536
|
+
name: {
|
|
3537
|
+
enumerable: false,
|
|
3564
3538
|
},
|
|
3565
3539
|
nodes: {
|
|
3566
|
-
|
|
3540
|
+
enumerable: false,
|
|
3567
3541
|
},
|
|
3568
3542
|
source: {
|
|
3569
|
-
|
|
3543
|
+
enumerable: false,
|
|
3570
3544
|
},
|
|
3571
3545
|
positions: {
|
|
3572
|
-
|
|
3546
|
+
enumerable: false,
|
|
3573
3547
|
},
|
|
3574
3548
|
originalError: {
|
|
3575
|
-
|
|
3549
|
+
enumerable: false,
|
|
3576
3550
|
},
|
|
3577
|
-
extensions: {
|
|
3578
|
-
// Coercing falsy values to undefined ensures they will not be included
|
|
3579
|
-
// in JSON.stringify() when not provided.
|
|
3580
|
-
value: (_extensions2 = _extensions) !== null && _extensions2 !== void 0 ? _extensions2 : undefined,
|
|
3581
|
-
// By being enumerable, JSON.stringify will include `path` in the
|
|
3582
|
-
// resulting output. This ensures that the simplest possible GraphQL
|
|
3583
|
-
// service adheres to the spec.
|
|
3584
|
-
enumerable: _extensions != null
|
|
3585
|
-
}
|
|
3586
3551
|
}); // Include (non-enumerable) stack trace.
|
|
3587
3552
|
|
|
3588
|
-
|
|
3589
|
-
|
|
3553
|
+
/* c8 ignore start */
|
|
3554
|
+
// FIXME: https://github.com/graphql/graphql-js/issues/2317
|
|
3555
|
+
|
|
3556
|
+
if (
|
|
3557
|
+
originalError !== null &&
|
|
3558
|
+
originalError !== void 0 &&
|
|
3559
|
+
originalError.stack
|
|
3560
|
+
) {
|
|
3561
|
+
Object.defineProperty(this, 'stack', {
|
|
3590
3562
|
value: originalError.stack,
|
|
3591
3563
|
writable: true,
|
|
3592
|
-
configurable: true
|
|
3564
|
+
configurable: true,
|
|
3593
3565
|
});
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
if (Error.captureStackTrace) {
|
|
3599
|
-
Error.captureStackTrace(_assertThisInitialized(_this), GraphQLError);
|
|
3566
|
+
} else if (Error.captureStackTrace) {
|
|
3567
|
+
Error.captureStackTrace(this, GraphQLError);
|
|
3600
3568
|
} else {
|
|
3601
|
-
Object.defineProperty(
|
|
3569
|
+
Object.defineProperty(this, 'stack', {
|
|
3602
3570
|
value: Error().stack,
|
|
3603
3571
|
writable: true,
|
|
3604
|
-
configurable: true
|
|
3572
|
+
configurable: true,
|
|
3605
3573
|
});
|
|
3606
3574
|
}
|
|
3575
|
+
/* c8 ignore stop */
|
|
3576
|
+
}
|
|
3607
3577
|
|
|
3608
|
-
|
|
3578
|
+
get [Symbol.toStringTag]() {
|
|
3579
|
+
return 'GraphQLError';
|
|
3609
3580
|
}
|
|
3610
3581
|
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3582
|
+
toString() {
|
|
3583
|
+
let output = this.message;
|
|
3584
|
+
|
|
3585
|
+
if (this.nodes) {
|
|
3586
|
+
for (const node of this.nodes) {
|
|
3587
|
+
if (node.loc) {
|
|
3588
|
+
output += '\n\n' + printLocation(node.loc);
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
} else if (this.source && this.locations) {
|
|
3592
|
+
for (const location of this.locations) {
|
|
3593
|
+
output += '\n\n' + printSourceLocation(this.source, location);
|
|
3594
|
+
}
|
|
3622
3595
|
}
|
|
3623
|
-
}]);
|
|
3624
3596
|
|
|
3625
|
-
|
|
3626
|
-
}
|
|
3627
|
-
/**
|
|
3628
|
-
* Prints a GraphQLError to a string, representing useful location information
|
|
3629
|
-
* about the error's position in the source.
|
|
3630
|
-
*/
|
|
3597
|
+
return output;
|
|
3598
|
+
}
|
|
3631
3599
|
|
|
3632
|
-
|
|
3633
|
-
|
|
3600
|
+
toJSON() {
|
|
3601
|
+
const formattedError = {
|
|
3602
|
+
message: this.message,
|
|
3603
|
+
};
|
|
3634
3604
|
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3605
|
+
if (this.locations != null) {
|
|
3606
|
+
formattedError.locations = this.locations;
|
|
3607
|
+
}
|
|
3638
3608
|
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
}
|
|
3609
|
+
if (this.path != null) {
|
|
3610
|
+
formattedError.path = this.path;
|
|
3642
3611
|
}
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
output += '\n\n' + printSourceLocation(error.source, location);
|
|
3612
|
+
|
|
3613
|
+
if (this.extensions != null && Object.keys(this.extensions).length > 0) {
|
|
3614
|
+
formattedError.extensions = this.extensions;
|
|
3647
3615
|
}
|
|
3616
|
+
|
|
3617
|
+
return formattedError;
|
|
3648
3618
|
}
|
|
3619
|
+
}
|
|
3649
3620
|
|
|
3650
|
-
|
|
3621
|
+
function undefinedIfEmpty(array) {
|
|
3622
|
+
return array === undefined || array.length === 0 ? undefined : array;
|
|
3651
3623
|
}
|
|
3652
3624
|
|
|
3653
3625
|
/**
|
|
@@ -3656,103 +3628,16 @@ function printError(error) {
|
|
|
3656
3628
|
*/
|
|
3657
3629
|
|
|
3658
3630
|
function syntaxError(source, position, description) {
|
|
3659
|
-
return new GraphQLError(
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
/**
|
|
3663
|
-
* The set of allowed kind values for AST nodes.
|
|
3664
|
-
*/
|
|
3665
|
-
var Kind = Object.freeze({
|
|
3666
|
-
// Name
|
|
3667
|
-
NAME: 'Name',
|
|
3668
|
-
// Document
|
|
3669
|
-
DOCUMENT: 'Document',
|
|
3670
|
-
OPERATION_DEFINITION: 'OperationDefinition',
|
|
3671
|
-
VARIABLE_DEFINITION: 'VariableDefinition',
|
|
3672
|
-
SELECTION_SET: 'SelectionSet',
|
|
3673
|
-
FIELD: 'Field',
|
|
3674
|
-
ARGUMENT: 'Argument',
|
|
3675
|
-
// Fragments
|
|
3676
|
-
FRAGMENT_SPREAD: 'FragmentSpread',
|
|
3677
|
-
INLINE_FRAGMENT: 'InlineFragment',
|
|
3678
|
-
FRAGMENT_DEFINITION: 'FragmentDefinition',
|
|
3679
|
-
// Values
|
|
3680
|
-
VARIABLE: 'Variable',
|
|
3681
|
-
INT: 'IntValue',
|
|
3682
|
-
FLOAT: 'FloatValue',
|
|
3683
|
-
STRING: 'StringValue',
|
|
3684
|
-
BOOLEAN: 'BooleanValue',
|
|
3685
|
-
NULL: 'NullValue',
|
|
3686
|
-
ENUM: 'EnumValue',
|
|
3687
|
-
LIST: 'ListValue',
|
|
3688
|
-
OBJECT: 'ObjectValue',
|
|
3689
|
-
OBJECT_FIELD: 'ObjectField',
|
|
3690
|
-
// Directives
|
|
3691
|
-
DIRECTIVE: 'Directive',
|
|
3692
|
-
// Types
|
|
3693
|
-
NAMED_TYPE: 'NamedType',
|
|
3694
|
-
LIST_TYPE: 'ListType',
|
|
3695
|
-
NON_NULL_TYPE: 'NonNullType',
|
|
3696
|
-
// Type System Definitions
|
|
3697
|
-
SCHEMA_DEFINITION: 'SchemaDefinition',
|
|
3698
|
-
OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition',
|
|
3699
|
-
// Type Definitions
|
|
3700
|
-
SCALAR_TYPE_DEFINITION: 'ScalarTypeDefinition',
|
|
3701
|
-
OBJECT_TYPE_DEFINITION: 'ObjectTypeDefinition',
|
|
3702
|
-
FIELD_DEFINITION: 'FieldDefinition',
|
|
3703
|
-
INPUT_VALUE_DEFINITION: 'InputValueDefinition',
|
|
3704
|
-
INTERFACE_TYPE_DEFINITION: 'InterfaceTypeDefinition',
|
|
3705
|
-
UNION_TYPE_DEFINITION: 'UnionTypeDefinition',
|
|
3706
|
-
ENUM_TYPE_DEFINITION: 'EnumTypeDefinition',
|
|
3707
|
-
ENUM_VALUE_DEFINITION: 'EnumValueDefinition',
|
|
3708
|
-
INPUT_OBJECT_TYPE_DEFINITION: 'InputObjectTypeDefinition',
|
|
3709
|
-
// Directive Definitions
|
|
3710
|
-
DIRECTIVE_DEFINITION: 'DirectiveDefinition',
|
|
3711
|
-
// Type System Extensions
|
|
3712
|
-
SCHEMA_EXTENSION: 'SchemaExtension',
|
|
3713
|
-
// Type Extensions
|
|
3714
|
-
SCALAR_TYPE_EXTENSION: 'ScalarTypeExtension',
|
|
3715
|
-
OBJECT_TYPE_EXTENSION: 'ObjectTypeExtension',
|
|
3716
|
-
INTERFACE_TYPE_EXTENSION: 'InterfaceTypeExtension',
|
|
3717
|
-
UNION_TYPE_EXTENSION: 'UnionTypeExtension',
|
|
3718
|
-
ENUM_TYPE_EXTENSION: 'EnumTypeExtension',
|
|
3719
|
-
INPUT_OBJECT_TYPE_EXTENSION: 'InputObjectTypeExtension'
|
|
3720
|
-
});
|
|
3721
|
-
/**
|
|
3722
|
-
* The enum type representing the possible kind values of AST nodes.
|
|
3723
|
-
*/
|
|
3724
|
-
|
|
3725
|
-
function invariant(condition, message) {
|
|
3726
|
-
var booleanCondition = Boolean(condition); // istanbul ignore else (See transformation done in './resources/inlineInvariant.js')
|
|
3727
|
-
|
|
3728
|
-
if (!booleanCondition) {
|
|
3729
|
-
throw new Error(message != null ? message : 'Unexpected invariant triggered.');
|
|
3730
|
-
}
|
|
3731
|
-
}
|
|
3732
|
-
|
|
3733
|
-
// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
3734
|
-
var nodejsCustomInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined;
|
|
3735
|
-
var nodejsCustomInspectSymbol$1 = nodejsCustomInspectSymbol;
|
|
3736
|
-
|
|
3737
|
-
/**
|
|
3738
|
-
* The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`
|
|
3739
|
-
*/
|
|
3740
|
-
|
|
3741
|
-
function defineInspect(classObject) {
|
|
3742
|
-
var fn = classObject.prototype.toJSON;
|
|
3743
|
-
typeof fn === 'function' || invariant(0);
|
|
3744
|
-
classObject.prototype.inspect = fn; // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
3745
|
-
|
|
3746
|
-
if (nodejsCustomInspectSymbol$1) {
|
|
3747
|
-
classObject.prototype[nodejsCustomInspectSymbol$1] = fn;
|
|
3748
|
-
}
|
|
3631
|
+
return new GraphQLError(`Syntax Error: ${description}`, undefined, source, [
|
|
3632
|
+
position,
|
|
3633
|
+
]);
|
|
3749
3634
|
}
|
|
3750
3635
|
|
|
3751
3636
|
/**
|
|
3752
3637
|
* Contains a range of UTF-8 character offsets and token references that
|
|
3753
3638
|
* identify the region of the source from which the AST derived.
|
|
3754
3639
|
*/
|
|
3755
|
-
|
|
3640
|
+
class Location {
|
|
3756
3641
|
/**
|
|
3757
3642
|
* The character offset at which this Node begins.
|
|
3758
3643
|
*/
|
|
@@ -3772,7 +3657,7 @@ var Location = /*#__PURE__*/function () {
|
|
|
3772
3657
|
/**
|
|
3773
3658
|
* The Source document the AST represents.
|
|
3774
3659
|
*/
|
|
3775
|
-
|
|
3660
|
+
constructor(startToken, endToken, source) {
|
|
3776
3661
|
this.start = startToken.start;
|
|
3777
3662
|
this.end = endToken.end;
|
|
3778
3663
|
this.startToken = startToken;
|
|
@@ -3780,25 +3665,23 @@ var Location = /*#__PURE__*/function () {
|
|
|
3780
3665
|
this.source = source;
|
|
3781
3666
|
}
|
|
3782
3667
|
|
|
3783
|
-
|
|
3668
|
+
get [Symbol.toStringTag]() {
|
|
3669
|
+
return 'Location';
|
|
3670
|
+
}
|
|
3784
3671
|
|
|
3785
|
-
|
|
3672
|
+
toJSON() {
|
|
3786
3673
|
return {
|
|
3787
3674
|
start: this.start,
|
|
3788
|
-
end: this.end
|
|
3675
|
+
end: this.end,
|
|
3789
3676
|
};
|
|
3790
|
-
}
|
|
3791
|
-
|
|
3792
|
-
return Location;
|
|
3793
|
-
}(); // Print a simplified form when appearing in `inspect` and `util.inspect`.
|
|
3794
|
-
|
|
3795
|
-
defineInspect(Location);
|
|
3677
|
+
}
|
|
3678
|
+
}
|
|
3796
3679
|
/**
|
|
3797
3680
|
* Represents a range of characters represented by a lexical token
|
|
3798
3681
|
* within a Source.
|
|
3799
3682
|
*/
|
|
3800
3683
|
|
|
3801
|
-
|
|
3684
|
+
class Token {
|
|
3802
3685
|
/**
|
|
3803
3686
|
* The kind of Token.
|
|
3804
3687
|
*/
|
|
@@ -3821,6 +3704,9 @@ var Token = /*#__PURE__*/function () {
|
|
|
3821
3704
|
|
|
3822
3705
|
/**
|
|
3823
3706
|
* For non-punctuation tokens, represents the interpreted value of the token.
|
|
3707
|
+
*
|
|
3708
|
+
* Note: is undefined for punctuation tokens, but typed as string for
|
|
3709
|
+
* convenience in the parser.
|
|
3824
3710
|
*/
|
|
3825
3711
|
|
|
3826
3712
|
/**
|
|
@@ -3828,403 +3714,288 @@ var Token = /*#__PURE__*/function () {
|
|
|
3828
3714
|
* including ignored tokens. <SOF> is always the first node and <EOF>
|
|
3829
3715
|
* the last.
|
|
3830
3716
|
*/
|
|
3831
|
-
|
|
3717
|
+
constructor(kind, start, end, line, column, value) {
|
|
3832
3718
|
this.kind = kind;
|
|
3833
3719
|
this.start = start;
|
|
3834
3720
|
this.end = end;
|
|
3835
3721
|
this.line = line;
|
|
3836
|
-
this.column = column;
|
|
3722
|
+
this.column = column; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
3723
|
+
|
|
3837
3724
|
this.value = value;
|
|
3838
|
-
this.prev =
|
|
3725
|
+
this.prev = null;
|
|
3839
3726
|
this.next = null;
|
|
3840
3727
|
}
|
|
3841
3728
|
|
|
3842
|
-
|
|
3729
|
+
get [Symbol.toStringTag]() {
|
|
3730
|
+
return 'Token';
|
|
3731
|
+
}
|
|
3843
3732
|
|
|
3844
|
-
|
|
3733
|
+
toJSON() {
|
|
3845
3734
|
return {
|
|
3846
3735
|
kind: this.kind,
|
|
3847
3736
|
value: this.value,
|
|
3848
3737
|
line: this.line,
|
|
3849
|
-
column: this.column
|
|
3738
|
+
column: this.column,
|
|
3850
3739
|
};
|
|
3851
|
-
}
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
/** Name */
|
|
3743
|
+
|
|
3744
|
+
let OperationTypeNode;
|
|
3852
3745
|
|
|
3853
|
-
|
|
3854
|
-
|
|
3746
|
+
(function (OperationTypeNode) {
|
|
3747
|
+
OperationTypeNode['QUERY'] = 'query';
|
|
3748
|
+
OperationTypeNode['MUTATION'] = 'mutation';
|
|
3749
|
+
OperationTypeNode['SUBSCRIPTION'] = 'subscription';
|
|
3750
|
+
})(OperationTypeNode || (OperationTypeNode = {}));
|
|
3855
3751
|
|
|
3856
|
-
defineInspect(Token);
|
|
3857
3752
|
/**
|
|
3858
|
-
* The
|
|
3753
|
+
* The set of allowed directive location values.
|
|
3754
|
+
*/
|
|
3755
|
+
let DirectiveLocation;
|
|
3756
|
+
/**
|
|
3757
|
+
* The enum type representing the directive location values.
|
|
3758
|
+
*
|
|
3759
|
+
* @deprecated Please use `DirectiveLocation`. Will be remove in v17.
|
|
3859
3760
|
*/
|
|
3860
3761
|
|
|
3762
|
+
(function (DirectiveLocation) {
|
|
3763
|
+
DirectiveLocation['QUERY'] = 'QUERY';
|
|
3764
|
+
DirectiveLocation['MUTATION'] = 'MUTATION';
|
|
3765
|
+
DirectiveLocation['SUBSCRIPTION'] = 'SUBSCRIPTION';
|
|
3766
|
+
DirectiveLocation['FIELD'] = 'FIELD';
|
|
3767
|
+
DirectiveLocation['FRAGMENT_DEFINITION'] = 'FRAGMENT_DEFINITION';
|
|
3768
|
+
DirectiveLocation['FRAGMENT_SPREAD'] = 'FRAGMENT_SPREAD';
|
|
3769
|
+
DirectiveLocation['INLINE_FRAGMENT'] = 'INLINE_FRAGMENT';
|
|
3770
|
+
DirectiveLocation['VARIABLE_DEFINITION'] = 'VARIABLE_DEFINITION';
|
|
3771
|
+
DirectiveLocation['SCHEMA'] = 'SCHEMA';
|
|
3772
|
+
DirectiveLocation['SCALAR'] = 'SCALAR';
|
|
3773
|
+
DirectiveLocation['OBJECT'] = 'OBJECT';
|
|
3774
|
+
DirectiveLocation['FIELD_DEFINITION'] = 'FIELD_DEFINITION';
|
|
3775
|
+
DirectiveLocation['ARGUMENT_DEFINITION'] = 'ARGUMENT_DEFINITION';
|
|
3776
|
+
DirectiveLocation['INTERFACE'] = 'INTERFACE';
|
|
3777
|
+
DirectiveLocation['UNION'] = 'UNION';
|
|
3778
|
+
DirectiveLocation['ENUM'] = 'ENUM';
|
|
3779
|
+
DirectiveLocation['ENUM_VALUE'] = 'ENUM_VALUE';
|
|
3780
|
+
DirectiveLocation['INPUT_OBJECT'] = 'INPUT_OBJECT';
|
|
3781
|
+
DirectiveLocation['INPUT_FIELD_DEFINITION'] = 'INPUT_FIELD_DEFINITION';
|
|
3782
|
+
})(DirectiveLocation || (DirectiveLocation = {}));
|
|
3783
|
+
|
|
3861
3784
|
/**
|
|
3862
|
-
*
|
|
3863
|
-
* lexer emits.
|
|
3785
|
+
* The set of allowed kind values for AST nodes.
|
|
3864
3786
|
*/
|
|
3865
|
-
|
|
3866
|
-
SOF: '<SOF>',
|
|
3867
|
-
EOF: '<EOF>',
|
|
3868
|
-
BANG: '!',
|
|
3869
|
-
DOLLAR: '$',
|
|
3870
|
-
AMP: '&',
|
|
3871
|
-
PAREN_L: '(',
|
|
3872
|
-
PAREN_R: ')',
|
|
3873
|
-
SPREAD: '...',
|
|
3874
|
-
COLON: ':',
|
|
3875
|
-
EQUALS: '=',
|
|
3876
|
-
AT: '@',
|
|
3877
|
-
BRACKET_L: '[',
|
|
3878
|
-
BRACKET_R: ']',
|
|
3879
|
-
BRACE_L: '{',
|
|
3880
|
-
PIPE: '|',
|
|
3881
|
-
BRACE_R: '}',
|
|
3882
|
-
NAME: 'Name',
|
|
3883
|
-
INT: 'Int',
|
|
3884
|
-
FLOAT: 'Float',
|
|
3885
|
-
STRING: 'String',
|
|
3886
|
-
BLOCK_STRING: 'BlockString',
|
|
3887
|
-
COMMENT: 'Comment'
|
|
3888
|
-
});
|
|
3787
|
+
let Kind;
|
|
3889
3788
|
/**
|
|
3890
|
-
* The enum type representing the
|
|
3789
|
+
* The enum type representing the possible kind values of AST nodes.
|
|
3790
|
+
*
|
|
3791
|
+
* @deprecated Please use `Kind`. Will be remove in v17.
|
|
3891
3792
|
*/
|
|
3892
3793
|
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3794
|
+
(function (Kind) {
|
|
3795
|
+
Kind['NAME'] = 'Name';
|
|
3796
|
+
Kind['DOCUMENT'] = 'Document';
|
|
3797
|
+
Kind['OPERATION_DEFINITION'] = 'OperationDefinition';
|
|
3798
|
+
Kind['VARIABLE_DEFINITION'] = 'VariableDefinition';
|
|
3799
|
+
Kind['SELECTION_SET'] = 'SelectionSet';
|
|
3800
|
+
Kind['FIELD'] = 'Field';
|
|
3801
|
+
Kind['ARGUMENT'] = 'Argument';
|
|
3802
|
+
Kind['FRAGMENT_SPREAD'] = 'FragmentSpread';
|
|
3803
|
+
Kind['INLINE_FRAGMENT'] = 'InlineFragment';
|
|
3804
|
+
Kind['FRAGMENT_DEFINITION'] = 'FragmentDefinition';
|
|
3805
|
+
Kind['VARIABLE'] = 'Variable';
|
|
3806
|
+
Kind['INT'] = 'IntValue';
|
|
3807
|
+
Kind['FLOAT'] = 'FloatValue';
|
|
3808
|
+
Kind['STRING'] = 'StringValue';
|
|
3809
|
+
Kind['BOOLEAN'] = 'BooleanValue';
|
|
3810
|
+
Kind['NULL'] = 'NullValue';
|
|
3811
|
+
Kind['ENUM'] = 'EnumValue';
|
|
3812
|
+
Kind['LIST'] = 'ListValue';
|
|
3813
|
+
Kind['OBJECT'] = 'ObjectValue';
|
|
3814
|
+
Kind['OBJECT_FIELD'] = 'ObjectField';
|
|
3815
|
+
Kind['DIRECTIVE'] = 'Directive';
|
|
3816
|
+
Kind['NAMED_TYPE'] = 'NamedType';
|
|
3817
|
+
Kind['LIST_TYPE'] = 'ListType';
|
|
3818
|
+
Kind['NON_NULL_TYPE'] = 'NonNullType';
|
|
3819
|
+
Kind['SCHEMA_DEFINITION'] = 'SchemaDefinition';
|
|
3820
|
+
Kind['OPERATION_TYPE_DEFINITION'] = 'OperationTypeDefinition';
|
|
3821
|
+
Kind['SCALAR_TYPE_DEFINITION'] = 'ScalarTypeDefinition';
|
|
3822
|
+
Kind['OBJECT_TYPE_DEFINITION'] = 'ObjectTypeDefinition';
|
|
3823
|
+
Kind['FIELD_DEFINITION'] = 'FieldDefinition';
|
|
3824
|
+
Kind['INPUT_VALUE_DEFINITION'] = 'InputValueDefinition';
|
|
3825
|
+
Kind['INTERFACE_TYPE_DEFINITION'] = 'InterfaceTypeDefinition';
|
|
3826
|
+
Kind['UNION_TYPE_DEFINITION'] = 'UnionTypeDefinition';
|
|
3827
|
+
Kind['ENUM_TYPE_DEFINITION'] = 'EnumTypeDefinition';
|
|
3828
|
+
Kind['ENUM_VALUE_DEFINITION'] = 'EnumValueDefinition';
|
|
3829
|
+
Kind['INPUT_OBJECT_TYPE_DEFINITION'] = 'InputObjectTypeDefinition';
|
|
3830
|
+
Kind['DIRECTIVE_DEFINITION'] = 'DirectiveDefinition';
|
|
3831
|
+
Kind['SCHEMA_EXTENSION'] = 'SchemaExtension';
|
|
3832
|
+
Kind['SCALAR_TYPE_EXTENSION'] = 'ScalarTypeExtension';
|
|
3833
|
+
Kind['OBJECT_TYPE_EXTENSION'] = 'ObjectTypeExtension';
|
|
3834
|
+
Kind['INTERFACE_TYPE_EXTENSION'] = 'InterfaceTypeExtension';
|
|
3835
|
+
Kind['UNION_TYPE_EXTENSION'] = 'UnionTypeExtension';
|
|
3836
|
+
Kind['ENUM_TYPE_EXTENSION'] = 'EnumTypeExtension';
|
|
3837
|
+
Kind['INPUT_OBJECT_TYPE_EXTENSION'] = 'InputObjectTypeExtension';
|
|
3838
|
+
})(Kind || (Kind = {}));
|
|
3839
|
+
|
|
3896
3840
|
/**
|
|
3897
|
-
*
|
|
3841
|
+
* ```
|
|
3842
|
+
* WhiteSpace ::
|
|
3843
|
+
* - "Horizontal Tab (U+0009)"
|
|
3844
|
+
* - "Space (U+0020)"
|
|
3845
|
+
* ```
|
|
3846
|
+
* @internal
|
|
3898
3847
|
*/
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
return formatValue(value, []);
|
|
3848
|
+
function isWhiteSpace(code) {
|
|
3849
|
+
return code === 0x0009 || code === 0x0020;
|
|
3902
3850
|
}
|
|
3851
|
+
/**
|
|
3852
|
+
* ```
|
|
3853
|
+
* Digit :: one of
|
|
3854
|
+
* - `0` `1` `2` `3` `4` `5` `6` `7` `8` `9`
|
|
3855
|
+
* ```
|
|
3856
|
+
* @internal
|
|
3857
|
+
*/
|
|
3903
3858
|
|
|
3904
|
-
function
|
|
3905
|
-
|
|
3906
|
-
case 'string':
|
|
3907
|
-
return JSON.stringify(value);
|
|
3908
|
-
|
|
3909
|
-
case 'function':
|
|
3910
|
-
return value.name ? "[function ".concat(value.name, "]") : '[function]';
|
|
3911
|
-
|
|
3912
|
-
case 'object':
|
|
3913
|
-
if (value === null) {
|
|
3914
|
-
return 'null';
|
|
3915
|
-
}
|
|
3916
|
-
|
|
3917
|
-
return formatObjectValue(value, seenValues);
|
|
3918
|
-
|
|
3919
|
-
default:
|
|
3920
|
-
return String(value);
|
|
3921
|
-
}
|
|
3859
|
+
function isDigit(code) {
|
|
3860
|
+
return code >= 0x0030 && code <= 0x0039;
|
|
3922
3861
|
}
|
|
3862
|
+
/**
|
|
3863
|
+
* ```
|
|
3864
|
+
* Letter :: one of
|
|
3865
|
+
* - `A` `B` `C` `D` `E` `F` `G` `H` `I` `J` `K` `L` `M`
|
|
3866
|
+
* - `N` `O` `P` `Q` `R` `S` `T` `U` `V` `W` `X` `Y` `Z`
|
|
3867
|
+
* - `a` `b` `c` `d` `e` `f` `g` `h` `i` `j` `k` `l` `m`
|
|
3868
|
+
* - `n` `o` `p` `q` `r` `s` `t` `u` `v` `w` `x` `y` `z`
|
|
3869
|
+
* ```
|
|
3870
|
+
* @internal
|
|
3871
|
+
*/
|
|
3923
3872
|
|
|
3924
|
-
function
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
var seenValues = [].concat(previouslySeenValues, [value]);
|
|
3930
|
-
var customInspectFn = getCustomFn(value);
|
|
3931
|
-
|
|
3932
|
-
if (customInspectFn !== undefined) {
|
|
3933
|
-
var customValue = customInspectFn.call(value); // check for infinite recursion
|
|
3934
|
-
|
|
3935
|
-
if (customValue !== value) {
|
|
3936
|
-
return typeof customValue === 'string' ? customValue : formatValue(customValue, seenValues);
|
|
3937
|
-
}
|
|
3938
|
-
} else if (Array.isArray(value)) {
|
|
3939
|
-
return formatArray(value, seenValues);
|
|
3940
|
-
}
|
|
3941
|
-
|
|
3942
|
-
return formatObject(value, seenValues);
|
|
3873
|
+
function isLetter(code) {
|
|
3874
|
+
return (
|
|
3875
|
+
(code >= 0x0061 && code <= 0x007a) || // A-Z
|
|
3876
|
+
(code >= 0x0041 && code <= 0x005a) // a-z
|
|
3877
|
+
);
|
|
3943
3878
|
}
|
|
3879
|
+
/**
|
|
3880
|
+
* ```
|
|
3881
|
+
* NameStart ::
|
|
3882
|
+
* - Letter
|
|
3883
|
+
* - `_`
|
|
3884
|
+
* ```
|
|
3885
|
+
* @internal
|
|
3886
|
+
*/
|
|
3944
3887
|
|
|
3945
|
-
function
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
if (keys.length === 0) {
|
|
3949
|
-
return '{}';
|
|
3950
|
-
}
|
|
3951
|
-
|
|
3952
|
-
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
|
3953
|
-
return '[' + getObjectTag(object) + ']';
|
|
3954
|
-
}
|
|
3955
|
-
|
|
3956
|
-
var properties = keys.map(function (key) {
|
|
3957
|
-
var value = formatValue(object[key], seenValues);
|
|
3958
|
-
return key + ': ' + value;
|
|
3959
|
-
});
|
|
3960
|
-
return '{ ' + properties.join(', ') + ' }';
|
|
3888
|
+
function isNameStart(code) {
|
|
3889
|
+
return isLetter(code) || code === 0x005f;
|
|
3961
3890
|
}
|
|
3891
|
+
/**
|
|
3892
|
+
* ```
|
|
3893
|
+
* NameContinue ::
|
|
3894
|
+
* - Letter
|
|
3895
|
+
* - Digit
|
|
3896
|
+
* - `_`
|
|
3897
|
+
* ```
|
|
3898
|
+
* @internal
|
|
3899
|
+
*/
|
|
3962
3900
|
|
|
3963
|
-
function
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
}
|
|
3967
|
-
|
|
3968
|
-
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
|
3969
|
-
return '[Array]';
|
|
3970
|
-
}
|
|
3971
|
-
|
|
3972
|
-
var len = Math.min(MAX_ARRAY_LENGTH, array.length);
|
|
3973
|
-
var remaining = array.length - len;
|
|
3974
|
-
var items = [];
|
|
3975
|
-
|
|
3976
|
-
for (var i = 0; i < len; ++i) {
|
|
3977
|
-
items.push(formatValue(array[i], seenValues));
|
|
3978
|
-
}
|
|
3901
|
+
function isNameContinue(code) {
|
|
3902
|
+
return isLetter(code) || isDigit(code) || code === 0x005f;
|
|
3903
|
+
}
|
|
3979
3904
|
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3905
|
+
/**
|
|
3906
|
+
* Produces the value of a block string from its parsed raw value, similar to
|
|
3907
|
+
* CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc.
|
|
3908
|
+
*
|
|
3909
|
+
* This implements the GraphQL spec's BlockStringValue() static algorithm.
|
|
3910
|
+
*
|
|
3911
|
+
* @internal
|
|
3912
|
+
*/
|
|
3985
3913
|
|
|
3986
|
-
|
|
3987
|
-
|
|
3914
|
+
function dedentBlockStringLines(lines) {
|
|
3915
|
+
var _firstNonEmptyLine2;
|
|
3988
3916
|
|
|
3989
|
-
|
|
3990
|
-
|
|
3917
|
+
let commonIndent = Number.MAX_SAFE_INTEGER;
|
|
3918
|
+
let firstNonEmptyLine = null;
|
|
3919
|
+
let lastNonEmptyLine = -1;
|
|
3991
3920
|
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
}
|
|
3921
|
+
for (let i = 0; i < lines.length; ++i) {
|
|
3922
|
+
var _firstNonEmptyLine;
|
|
3995
3923
|
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
}
|
|
3999
|
-
}
|
|
3924
|
+
const line = lines[i];
|
|
3925
|
+
const indent = leadingWhitespace(line);
|
|
4000
3926
|
|
|
4001
|
-
|
|
4002
|
-
|
|
3927
|
+
if (indent === line.length) {
|
|
3928
|
+
continue; // skip empty lines
|
|
3929
|
+
}
|
|
4003
3930
|
|
|
4004
|
-
|
|
4005
|
-
|
|
3931
|
+
firstNonEmptyLine =
|
|
3932
|
+
(_firstNonEmptyLine = firstNonEmptyLine) !== null &&
|
|
3933
|
+
_firstNonEmptyLine !== void 0
|
|
3934
|
+
? _firstNonEmptyLine
|
|
3935
|
+
: i;
|
|
3936
|
+
lastNonEmptyLine = i;
|
|
4006
3937
|
|
|
4007
|
-
if (
|
|
4008
|
-
|
|
3938
|
+
if (i !== 0 && indent < commonIndent) {
|
|
3939
|
+
commonIndent = indent;
|
|
4009
3940
|
}
|
|
4010
3941
|
}
|
|
4011
3942
|
|
|
4012
|
-
return
|
|
3943
|
+
return lines // Remove common indentation from all lines but first.
|
|
3944
|
+
.map((line, i) => (i === 0 ? line : line.slice(commonIndent))) // Remove leading and trailing blank lines.
|
|
3945
|
+
.slice(
|
|
3946
|
+
(_firstNonEmptyLine2 = firstNonEmptyLine) !== null &&
|
|
3947
|
+
_firstNonEmptyLine2 !== void 0
|
|
3948
|
+
? _firstNonEmptyLine2
|
|
3949
|
+
: 0,
|
|
3950
|
+
lastNonEmptyLine + 1,
|
|
3951
|
+
);
|
|
4013
3952
|
}
|
|
4014
3953
|
|
|
4015
|
-
function
|
|
4016
|
-
|
|
3954
|
+
function leadingWhitespace(str) {
|
|
3955
|
+
let i = 0;
|
|
4017
3956
|
|
|
4018
|
-
|
|
4019
|
-
|
|
3957
|
+
while (i < str.length && isWhiteSpace(str.charCodeAt(i))) {
|
|
3958
|
+
++i;
|
|
4020
3959
|
}
|
|
3960
|
+
|
|
3961
|
+
return i;
|
|
4021
3962
|
}
|
|
4022
3963
|
|
|
4023
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4024
3964
|
/**
|
|
4025
|
-
*
|
|
4026
|
-
*
|
|
3965
|
+
* An exported enum describing the different kinds of tokens that the
|
|
3966
|
+
* lexer emits.
|
|
3967
|
+
*/
|
|
3968
|
+
let TokenKind;
|
|
3969
|
+
/**
|
|
3970
|
+
* The enum type representing the token kinds values.
|
|
3971
|
+
*
|
|
3972
|
+
* @deprecated Please use `TokenKind`. Will be remove in v17.
|
|
4027
3973
|
*/
|
|
4028
3974
|
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
return false;
|
|
4055
|
-
};
|
|
4056
|
-
|
|
4057
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
4058
|
-
|
|
4059
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
4060
|
-
|
|
4061
|
-
/**
|
|
4062
|
-
* A representation of source input to GraphQL. The `name` and `locationOffset` parameters are
|
|
4063
|
-
* optional, but they are useful for clients who store GraphQL documents in source files.
|
|
4064
|
-
* For example, if the GraphQL input starts at line 40 in a file named `Foo.graphql`, it might
|
|
4065
|
-
* be useful for `name` to be `"Foo.graphql"` and location to be `{ line: 40, column: 1 }`.
|
|
4066
|
-
* The `line` and `column` properties in `locationOffset` are 1-indexed.
|
|
4067
|
-
*/
|
|
4068
|
-
var Source = /*#__PURE__*/function () {
|
|
4069
|
-
function Source(body) {
|
|
4070
|
-
var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GraphQL request';
|
|
4071
|
-
var locationOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
4072
|
-
line: 1,
|
|
4073
|
-
column: 1
|
|
4074
|
-
};
|
|
4075
|
-
typeof body === 'string' || devAssert(0, "Body must be a string. Received: ".concat(inspect(body), "."));
|
|
4076
|
-
this.body = body;
|
|
4077
|
-
this.name = name;
|
|
4078
|
-
this.locationOffset = locationOffset;
|
|
4079
|
-
this.locationOffset.line > 0 || devAssert(0, 'line in locationOffset is 1-indexed and must be positive.');
|
|
4080
|
-
this.locationOffset.column > 0 || devAssert(0, 'column in locationOffset is 1-indexed and must be positive.');
|
|
4081
|
-
} // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
_createClass(Source, [{
|
|
4085
|
-
key: SYMBOL_TO_STRING_TAG,
|
|
4086
|
-
get: function get() {
|
|
4087
|
-
return 'Source';
|
|
4088
|
-
}
|
|
4089
|
-
}]);
|
|
4090
|
-
|
|
4091
|
-
return Source;
|
|
4092
|
-
}();
|
|
4093
|
-
/**
|
|
4094
|
-
* Test if the given value is a Source object.
|
|
4095
|
-
*
|
|
4096
|
-
* @internal
|
|
4097
|
-
*/
|
|
4098
|
-
|
|
4099
|
-
// eslint-disable-next-line no-redeclare
|
|
4100
|
-
function isSource(source) {
|
|
4101
|
-
return instanceOf(source, Source);
|
|
4102
|
-
}
|
|
4103
|
-
|
|
4104
|
-
/**
|
|
4105
|
-
* The set of allowed directive location values.
|
|
4106
|
-
*/
|
|
4107
|
-
var DirectiveLocation = Object.freeze({
|
|
4108
|
-
// Request Definitions
|
|
4109
|
-
QUERY: 'QUERY',
|
|
4110
|
-
MUTATION: 'MUTATION',
|
|
4111
|
-
SUBSCRIPTION: 'SUBSCRIPTION',
|
|
4112
|
-
FIELD: 'FIELD',
|
|
4113
|
-
FRAGMENT_DEFINITION: 'FRAGMENT_DEFINITION',
|
|
4114
|
-
FRAGMENT_SPREAD: 'FRAGMENT_SPREAD',
|
|
4115
|
-
INLINE_FRAGMENT: 'INLINE_FRAGMENT',
|
|
4116
|
-
VARIABLE_DEFINITION: 'VARIABLE_DEFINITION',
|
|
4117
|
-
// Type System Definitions
|
|
4118
|
-
SCHEMA: 'SCHEMA',
|
|
4119
|
-
SCALAR: 'SCALAR',
|
|
4120
|
-
OBJECT: 'OBJECT',
|
|
4121
|
-
FIELD_DEFINITION: 'FIELD_DEFINITION',
|
|
4122
|
-
ARGUMENT_DEFINITION: 'ARGUMENT_DEFINITION',
|
|
4123
|
-
INTERFACE: 'INTERFACE',
|
|
4124
|
-
UNION: 'UNION',
|
|
4125
|
-
ENUM: 'ENUM',
|
|
4126
|
-
ENUM_VALUE: 'ENUM_VALUE',
|
|
4127
|
-
INPUT_OBJECT: 'INPUT_OBJECT',
|
|
4128
|
-
INPUT_FIELD_DEFINITION: 'INPUT_FIELD_DEFINITION'
|
|
4129
|
-
});
|
|
4130
|
-
/**
|
|
4131
|
-
* The enum type representing the directive location values.
|
|
4132
|
-
*/
|
|
4133
|
-
|
|
4134
|
-
/**
|
|
4135
|
-
* Produces the value of a block string from its parsed raw value, similar to
|
|
4136
|
-
* CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc.
|
|
4137
|
-
*
|
|
4138
|
-
* This implements the GraphQL spec's BlockStringValue() static algorithm.
|
|
4139
|
-
*
|
|
4140
|
-
* @internal
|
|
4141
|
-
*/
|
|
4142
|
-
function dedentBlockStringValue(rawString) {
|
|
4143
|
-
// Expand a block string's raw value into independent lines.
|
|
4144
|
-
var lines = rawString.split(/\r\n|[\n\r]/g); // Remove common indentation from all lines but first.
|
|
4145
|
-
|
|
4146
|
-
var commonIndent = getBlockStringIndentation(rawString);
|
|
4147
|
-
|
|
4148
|
-
if (commonIndent !== 0) {
|
|
4149
|
-
for (var i = 1; i < lines.length; i++) {
|
|
4150
|
-
lines[i] = lines[i].slice(commonIndent);
|
|
4151
|
-
}
|
|
4152
|
-
} // Remove leading and trailing blank lines.
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
var startLine = 0;
|
|
4156
|
-
|
|
4157
|
-
while (startLine < lines.length && isBlank(lines[startLine])) {
|
|
4158
|
-
++startLine;
|
|
4159
|
-
}
|
|
4160
|
-
|
|
4161
|
-
var endLine = lines.length;
|
|
4162
|
-
|
|
4163
|
-
while (endLine > startLine && isBlank(lines[endLine - 1])) {
|
|
4164
|
-
--endLine;
|
|
4165
|
-
} // Return a string of the lines joined with U+000A.
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
return lines.slice(startLine, endLine).join('\n');
|
|
4169
|
-
}
|
|
4170
|
-
|
|
4171
|
-
function isBlank(str) {
|
|
4172
|
-
for (var i = 0; i < str.length; ++i) {
|
|
4173
|
-
if (str[i] !== ' ' && str[i] !== '\t') {
|
|
4174
|
-
return false;
|
|
4175
|
-
}
|
|
4176
|
-
}
|
|
4177
|
-
|
|
4178
|
-
return true;
|
|
4179
|
-
}
|
|
4180
|
-
/**
|
|
4181
|
-
* @internal
|
|
4182
|
-
*/
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
function getBlockStringIndentation(value) {
|
|
4186
|
-
var _commonIndent;
|
|
4187
|
-
|
|
4188
|
-
var isFirstLine = true;
|
|
4189
|
-
var isEmptyLine = true;
|
|
4190
|
-
var indent = 0;
|
|
4191
|
-
var commonIndent = null;
|
|
4192
|
-
|
|
4193
|
-
for (var i = 0; i < value.length; ++i) {
|
|
4194
|
-
switch (value.charCodeAt(i)) {
|
|
4195
|
-
case 13:
|
|
4196
|
-
// \r
|
|
4197
|
-
if (value.charCodeAt(i + 1) === 10) {
|
|
4198
|
-
++i; // skip \r\n as one symbol
|
|
4199
|
-
}
|
|
4200
|
-
|
|
4201
|
-
// falls through
|
|
4202
|
-
|
|
4203
|
-
case 10:
|
|
4204
|
-
// \n
|
|
4205
|
-
isFirstLine = false;
|
|
4206
|
-
isEmptyLine = true;
|
|
4207
|
-
indent = 0;
|
|
4208
|
-
break;
|
|
4209
|
-
|
|
4210
|
-
case 9: // \t
|
|
4211
|
-
|
|
4212
|
-
case 32:
|
|
4213
|
-
// <space>
|
|
4214
|
-
++indent;
|
|
4215
|
-
break;
|
|
4216
|
-
|
|
4217
|
-
default:
|
|
4218
|
-
if (isEmptyLine && !isFirstLine && (commonIndent === null || indent < commonIndent)) {
|
|
4219
|
-
commonIndent = indent;
|
|
4220
|
-
}
|
|
4221
|
-
|
|
4222
|
-
isEmptyLine = false;
|
|
4223
|
-
}
|
|
4224
|
-
}
|
|
4225
|
-
|
|
4226
|
-
return (_commonIndent = commonIndent) !== null && _commonIndent !== void 0 ? _commonIndent : 0;
|
|
4227
|
-
}
|
|
3975
|
+
(function (TokenKind) {
|
|
3976
|
+
TokenKind['SOF'] = '<SOF>';
|
|
3977
|
+
TokenKind['EOF'] = '<EOF>';
|
|
3978
|
+
TokenKind['BANG'] = '!';
|
|
3979
|
+
TokenKind['DOLLAR'] = '$';
|
|
3980
|
+
TokenKind['AMP'] = '&';
|
|
3981
|
+
TokenKind['PAREN_L'] = '(';
|
|
3982
|
+
TokenKind['PAREN_R'] = ')';
|
|
3983
|
+
TokenKind['SPREAD'] = '...';
|
|
3984
|
+
TokenKind['COLON'] = ':';
|
|
3985
|
+
TokenKind['EQUALS'] = '=';
|
|
3986
|
+
TokenKind['AT'] = '@';
|
|
3987
|
+
TokenKind['BRACKET_L'] = '[';
|
|
3988
|
+
TokenKind['BRACKET_R'] = ']';
|
|
3989
|
+
TokenKind['BRACE_L'] = '{';
|
|
3990
|
+
TokenKind['PIPE'] = '|';
|
|
3991
|
+
TokenKind['BRACE_R'] = '}';
|
|
3992
|
+
TokenKind['NAME'] = 'Name';
|
|
3993
|
+
TokenKind['INT'] = 'Int';
|
|
3994
|
+
TokenKind['FLOAT'] = 'Float';
|
|
3995
|
+
TokenKind['STRING'] = 'String';
|
|
3996
|
+
TokenKind['BLOCK_STRING'] = 'BlockString';
|
|
3997
|
+
TokenKind['COMMENT'] = 'Comment';
|
|
3998
|
+
})(TokenKind || (TokenKind = {}));
|
|
4228
3999
|
|
|
4229
4000
|
/**
|
|
4230
4001
|
* Given a Source object, creates a Lexer for that source.
|
|
@@ -4235,7 +4006,7 @@ function getBlockStringIndentation(value) {
|
|
|
4235
4006
|
* whenever called.
|
|
4236
4007
|
*/
|
|
4237
4008
|
|
|
4238
|
-
|
|
4009
|
+
class Lexer {
|
|
4239
4010
|
/**
|
|
4240
4011
|
* The previously focused non-ignored token.
|
|
4241
4012
|
*/
|
|
@@ -4251,64 +4022,143 @@ var Lexer = /*#__PURE__*/function () {
|
|
|
4251
4022
|
/**
|
|
4252
4023
|
* The character offset at which the current line begins.
|
|
4253
4024
|
*/
|
|
4254
|
-
|
|
4255
|
-
|
|
4025
|
+
constructor(source) {
|
|
4026
|
+
const startOfFileToken = new Token(TokenKind.SOF, 0, 0, 0, 0);
|
|
4256
4027
|
this.source = source;
|
|
4257
4028
|
this.lastToken = startOfFileToken;
|
|
4258
4029
|
this.token = startOfFileToken;
|
|
4259
4030
|
this.line = 1;
|
|
4260
4031
|
this.lineStart = 0;
|
|
4261
4032
|
}
|
|
4033
|
+
|
|
4034
|
+
get [Symbol.toStringTag]() {
|
|
4035
|
+
return 'Lexer';
|
|
4036
|
+
}
|
|
4262
4037
|
/**
|
|
4263
4038
|
* Advances the token stream to the next non-ignored token.
|
|
4264
4039
|
*/
|
|
4265
4040
|
|
|
4266
|
-
|
|
4267
|
-
var _proto = Lexer.prototype;
|
|
4268
|
-
|
|
4269
|
-
_proto.advance = function advance() {
|
|
4041
|
+
advance() {
|
|
4270
4042
|
this.lastToken = this.token;
|
|
4271
|
-
|
|
4043
|
+
const token = (this.token = this.lookahead());
|
|
4272
4044
|
return token;
|
|
4273
4045
|
}
|
|
4274
4046
|
/**
|
|
4275
4047
|
* Looks ahead and returns the next non-ignored token, but does not change
|
|
4276
4048
|
* the state of Lexer.
|
|
4277
4049
|
*/
|
|
4278
|
-
;
|
|
4279
4050
|
|
|
4280
|
-
|
|
4281
|
-
|
|
4051
|
+
lookahead() {
|
|
4052
|
+
let token = this.token;
|
|
4282
4053
|
|
|
4283
4054
|
if (token.kind !== TokenKind.EOF) {
|
|
4284
4055
|
do {
|
|
4285
|
-
|
|
4056
|
+
if (token.next) {
|
|
4057
|
+
token = token.next;
|
|
4058
|
+
} else {
|
|
4059
|
+
// Read the next token and form a link in the token linked-list.
|
|
4060
|
+
const nextToken = readNextToken(this, token.end); // @ts-expect-error next is only mutable during parsing.
|
|
4286
4061
|
|
|
4287
|
-
|
|
4288
|
-
|
|
4062
|
+
token.next = nextToken; // @ts-expect-error prev is only mutable during parsing.
|
|
4063
|
+
|
|
4064
|
+
nextToken.prev = token;
|
|
4065
|
+
token = nextToken;
|
|
4066
|
+
}
|
|
4289
4067
|
} while (token.kind === TokenKind.COMMENT);
|
|
4290
4068
|
}
|
|
4291
4069
|
|
|
4292
4070
|
return token;
|
|
4293
|
-
}
|
|
4294
|
-
|
|
4295
|
-
return Lexer;
|
|
4296
|
-
}();
|
|
4071
|
+
}
|
|
4072
|
+
}
|
|
4297
4073
|
/**
|
|
4298
4074
|
* @internal
|
|
4299
4075
|
*/
|
|
4300
4076
|
|
|
4301
4077
|
function isPunctuatorTokenKind(kind) {
|
|
4302
|
-
return
|
|
4078
|
+
return (
|
|
4079
|
+
kind === TokenKind.BANG ||
|
|
4080
|
+
kind === TokenKind.DOLLAR ||
|
|
4081
|
+
kind === TokenKind.AMP ||
|
|
4082
|
+
kind === TokenKind.PAREN_L ||
|
|
4083
|
+
kind === TokenKind.PAREN_R ||
|
|
4084
|
+
kind === TokenKind.SPREAD ||
|
|
4085
|
+
kind === TokenKind.COLON ||
|
|
4086
|
+
kind === TokenKind.EQUALS ||
|
|
4087
|
+
kind === TokenKind.AT ||
|
|
4088
|
+
kind === TokenKind.BRACKET_L ||
|
|
4089
|
+
kind === TokenKind.BRACKET_R ||
|
|
4090
|
+
kind === TokenKind.BRACE_L ||
|
|
4091
|
+
kind === TokenKind.PIPE ||
|
|
4092
|
+
kind === TokenKind.BRACE_R
|
|
4093
|
+
);
|
|
4303
4094
|
}
|
|
4095
|
+
/**
|
|
4096
|
+
* A Unicode scalar value is any Unicode code point except surrogate code
|
|
4097
|
+
* points. In other words, the inclusive ranges of values 0x0000 to 0xD7FF and
|
|
4098
|
+
* 0xE000 to 0x10FFFF.
|
|
4099
|
+
*
|
|
4100
|
+
* SourceCharacter ::
|
|
4101
|
+
* - "Any Unicode scalar value"
|
|
4102
|
+
*/
|
|
4304
4103
|
|
|
4305
|
-
function
|
|
4306
|
-
return (
|
|
4307
|
-
|
|
4308
|
-
code < 0x007f ? JSON.stringify(String.fromCharCode(code)) : // Otherwise print the escaped form.
|
|
4309
|
-
"\"\\u".concat(('00' + code.toString(16).toUpperCase()).slice(-4), "\"")
|
|
4104
|
+
function isUnicodeScalarValue(code) {
|
|
4105
|
+
return (
|
|
4106
|
+
(code >= 0x0000 && code <= 0xd7ff) || (code >= 0xe000 && code <= 0x10ffff)
|
|
4310
4107
|
);
|
|
4311
4108
|
}
|
|
4109
|
+
/**
|
|
4110
|
+
* The GraphQL specification defines source text as a sequence of unicode scalar
|
|
4111
|
+
* values (which Unicode defines to exclude surrogate code points). However
|
|
4112
|
+
* JavaScript defines strings as a sequence of UTF-16 code units which may
|
|
4113
|
+
* include surrogates. A surrogate pair is a valid source character as it
|
|
4114
|
+
* encodes a supplementary code point (above U+FFFF), but unpaired surrogate
|
|
4115
|
+
* code points are not valid source characters.
|
|
4116
|
+
*/
|
|
4117
|
+
|
|
4118
|
+
function isSupplementaryCodePoint(body, location) {
|
|
4119
|
+
return (
|
|
4120
|
+
isLeadingSurrogate(body.charCodeAt(location)) &&
|
|
4121
|
+
isTrailingSurrogate(body.charCodeAt(location + 1))
|
|
4122
|
+
);
|
|
4123
|
+
}
|
|
4124
|
+
|
|
4125
|
+
function isLeadingSurrogate(code) {
|
|
4126
|
+
return code >= 0xd800 && code <= 0xdbff;
|
|
4127
|
+
}
|
|
4128
|
+
|
|
4129
|
+
function isTrailingSurrogate(code) {
|
|
4130
|
+
return code >= 0xdc00 && code <= 0xdfff;
|
|
4131
|
+
}
|
|
4132
|
+
/**
|
|
4133
|
+
* Prints the code point (or end of file reference) at a given location in a
|
|
4134
|
+
* source for use in error messages.
|
|
4135
|
+
*
|
|
4136
|
+
* Printable ASCII is printed quoted, while other points are printed in Unicode
|
|
4137
|
+
* code point form (ie. U+1234).
|
|
4138
|
+
*/
|
|
4139
|
+
|
|
4140
|
+
function printCodePointAt(lexer, location) {
|
|
4141
|
+
const code = lexer.source.body.codePointAt(location);
|
|
4142
|
+
|
|
4143
|
+
if (code === undefined) {
|
|
4144
|
+
return TokenKind.EOF;
|
|
4145
|
+
} else if (code >= 0x0020 && code <= 0x007e) {
|
|
4146
|
+
// Printable ASCII
|
|
4147
|
+
const char = String.fromCodePoint(code);
|
|
4148
|
+
return char === '"' ? "'\"'" : `"${char}"`;
|
|
4149
|
+
} // Unicode code point
|
|
4150
|
+
|
|
4151
|
+
return 'U+' + code.toString(16).toUpperCase().padStart(4, '0');
|
|
4152
|
+
}
|
|
4153
|
+
/**
|
|
4154
|
+
* Create a token with line and column location information.
|
|
4155
|
+
*/
|
|
4156
|
+
|
|
4157
|
+
function createToken(lexer, kind, start, end, value) {
|
|
4158
|
+
const line = lexer.line;
|
|
4159
|
+
const col = 1 + start - lexer.lineStart;
|
|
4160
|
+
return new Token(kind, start, end, line, col, value);
|
|
4161
|
+
}
|
|
4312
4162
|
/**
|
|
4313
4163
|
* Gets the next token from the source starting at the given position.
|
|
4314
4164
|
*
|
|
@@ -4317,586 +4167,947 @@ function printCharCode(code) {
|
|
|
4317
4167
|
* complicated tokens.
|
|
4318
4168
|
*/
|
|
4319
4169
|
|
|
4170
|
+
function readNextToken(lexer, start) {
|
|
4171
|
+
const body = lexer.source.body;
|
|
4172
|
+
const bodyLength = body.length;
|
|
4173
|
+
let position = start;
|
|
4320
4174
|
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
var body = source.body;
|
|
4324
|
-
var bodyLength = body.length;
|
|
4325
|
-
var pos = prev.end;
|
|
4326
|
-
|
|
4327
|
-
while (pos < bodyLength) {
|
|
4328
|
-
var code = body.charCodeAt(pos);
|
|
4329
|
-
var _line = lexer.line;
|
|
4330
|
-
|
|
4331
|
-
var _col = 1 + pos - lexer.lineStart; // SourceCharacter
|
|
4332
|
-
|
|
4175
|
+
while (position < bodyLength) {
|
|
4176
|
+
const code = body.charCodeAt(position); // SourceCharacter
|
|
4333
4177
|
|
|
4334
4178
|
switch (code) {
|
|
4179
|
+
// Ignored ::
|
|
4180
|
+
// - UnicodeBOM
|
|
4181
|
+
// - WhiteSpace
|
|
4182
|
+
// - LineTerminator
|
|
4183
|
+
// - Comment
|
|
4184
|
+
// - Comma
|
|
4185
|
+
//
|
|
4186
|
+
// UnicodeBOM :: "Byte Order Mark (U+FEFF)"
|
|
4187
|
+
//
|
|
4188
|
+
// WhiteSpace ::
|
|
4189
|
+
// - "Horizontal Tab (U+0009)"
|
|
4190
|
+
// - "Space (U+0020)"
|
|
4191
|
+
//
|
|
4192
|
+
// Comma :: ,
|
|
4335
4193
|
case 0xfeff: // <BOM>
|
|
4336
4194
|
|
|
4337
|
-
case
|
|
4195
|
+
case 0x0009: // \t
|
|
4338
4196
|
|
|
4339
|
-
case
|
|
4197
|
+
case 0x0020: // <space>
|
|
4340
4198
|
|
|
4341
|
-
case
|
|
4342
|
-
//
|
|
4343
|
-
++
|
|
4199
|
+
case 0x002c:
|
|
4200
|
+
// ,
|
|
4201
|
+
++position;
|
|
4344
4202
|
continue;
|
|
4203
|
+
// LineTerminator ::
|
|
4204
|
+
// - "New Line (U+000A)"
|
|
4205
|
+
// - "Carriage Return (U+000D)" [lookahead != "New Line (U+000A)"]
|
|
4206
|
+
// - "Carriage Return (U+000D)" "New Line (U+000A)"
|
|
4345
4207
|
|
|
4346
|
-
case
|
|
4347
|
-
//
|
|
4348
|
-
++
|
|
4208
|
+
case 0x000a:
|
|
4209
|
+
// \n
|
|
4210
|
+
++position;
|
|
4349
4211
|
++lexer.line;
|
|
4350
|
-
lexer.lineStart =
|
|
4212
|
+
lexer.lineStart = position;
|
|
4351
4213
|
continue;
|
|
4352
4214
|
|
|
4353
|
-
case
|
|
4354
|
-
//
|
|
4355
|
-
if (body.charCodeAt(
|
|
4356
|
-
|
|
4215
|
+
case 0x000d:
|
|
4216
|
+
// \r
|
|
4217
|
+
if (body.charCodeAt(position + 1) === 0x000a) {
|
|
4218
|
+
position += 2;
|
|
4357
4219
|
} else {
|
|
4358
|
-
++
|
|
4220
|
+
++position;
|
|
4359
4221
|
}
|
|
4360
4222
|
|
|
4361
4223
|
++lexer.line;
|
|
4362
|
-
lexer.lineStart =
|
|
4224
|
+
lexer.lineStart = position;
|
|
4363
4225
|
continue;
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4226
|
+
// Comment
|
|
4227
|
+
|
|
4228
|
+
case 0x0023:
|
|
4229
|
+
// #
|
|
4230
|
+
return readComment(lexer, position);
|
|
4231
|
+
// Token ::
|
|
4232
|
+
// - Punctuator
|
|
4233
|
+
// - Name
|
|
4234
|
+
// - IntValue
|
|
4235
|
+
// - FloatValue
|
|
4236
|
+
// - StringValue
|
|
4237
|
+
//
|
|
4238
|
+
// Punctuator :: one of ! $ & ( ) ... : = @ [ ] { | }
|
|
4239
|
+
|
|
4240
|
+
case 0x0021:
|
|
4241
|
+
// !
|
|
4242
|
+
return createToken(lexer, TokenKind.BANG, position, position + 1);
|
|
4243
|
+
|
|
4244
|
+
case 0x0024:
|
|
4245
|
+
// $
|
|
4246
|
+
return createToken(lexer, TokenKind.DOLLAR, position, position + 1);
|
|
4247
|
+
|
|
4248
|
+
case 0x0026:
|
|
4249
|
+
// &
|
|
4250
|
+
return createToken(lexer, TokenKind.AMP, position, position + 1);
|
|
4251
|
+
|
|
4252
|
+
case 0x0028:
|
|
4253
|
+
// (
|
|
4254
|
+
return createToken(lexer, TokenKind.PAREN_L, position, position + 1);
|
|
4255
|
+
|
|
4256
|
+
case 0x0029:
|
|
4257
|
+
// )
|
|
4258
|
+
return createToken(lexer, TokenKind.PAREN_R, position, position + 1);
|
|
4259
|
+
|
|
4260
|
+
case 0x002e:
|
|
4261
|
+
// .
|
|
4262
|
+
if (
|
|
4263
|
+
body.charCodeAt(position + 1) === 0x002e &&
|
|
4264
|
+
body.charCodeAt(position + 2) === 0x002e
|
|
4265
|
+
) {
|
|
4266
|
+
return createToken(lexer, TokenKind.SPREAD, position, position + 3);
|
|
4393
4267
|
}
|
|
4394
4268
|
|
|
4395
4269
|
break;
|
|
4396
4270
|
|
|
4397
|
-
case
|
|
4398
|
-
//
|
|
4399
|
-
return
|
|
4271
|
+
case 0x003a:
|
|
4272
|
+
// :
|
|
4273
|
+
return createToken(lexer, TokenKind.COLON, position, position + 1);
|
|
4400
4274
|
|
|
4401
|
-
case
|
|
4402
|
-
//
|
|
4403
|
-
return
|
|
4275
|
+
case 0x003d:
|
|
4276
|
+
// =
|
|
4277
|
+
return createToken(lexer, TokenKind.EQUALS, position, position + 1);
|
|
4404
4278
|
|
|
4405
|
-
case
|
|
4406
|
-
//
|
|
4407
|
-
return
|
|
4279
|
+
case 0x0040:
|
|
4280
|
+
// @
|
|
4281
|
+
return createToken(lexer, TokenKind.AT, position, position + 1);
|
|
4408
4282
|
|
|
4409
|
-
case
|
|
4410
|
-
//
|
|
4411
|
-
return
|
|
4283
|
+
case 0x005b:
|
|
4284
|
+
// [
|
|
4285
|
+
return createToken(lexer, TokenKind.BRACKET_L, position, position + 1);
|
|
4412
4286
|
|
|
4413
|
-
case
|
|
4414
|
-
//
|
|
4415
|
-
return
|
|
4287
|
+
case 0x005d:
|
|
4288
|
+
// ]
|
|
4289
|
+
return createToken(lexer, TokenKind.BRACKET_R, position, position + 1);
|
|
4416
4290
|
|
|
4417
|
-
case
|
|
4291
|
+
case 0x007b:
|
|
4418
4292
|
// {
|
|
4419
|
-
return
|
|
4293
|
+
return createToken(lexer, TokenKind.BRACE_L, position, position + 1);
|
|
4420
4294
|
|
|
4421
|
-
case
|
|
4295
|
+
case 0x007c:
|
|
4422
4296
|
// |
|
|
4423
|
-
return
|
|
4297
|
+
return createToken(lexer, TokenKind.PIPE, position, position + 1);
|
|
4424
4298
|
|
|
4425
|
-
case
|
|
4299
|
+
case 0x007d:
|
|
4426
4300
|
// }
|
|
4427
|
-
return
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4301
|
+
return createToken(lexer, TokenKind.BRACE_R, position, position + 1);
|
|
4302
|
+
// StringValue
|
|
4303
|
+
|
|
4304
|
+
case 0x0022:
|
|
4305
|
+
// "
|
|
4306
|
+
if (
|
|
4307
|
+
body.charCodeAt(position + 1) === 0x0022 &&
|
|
4308
|
+
body.charCodeAt(position + 2) === 0x0022
|
|
4309
|
+
) {
|
|
4310
|
+
return readBlockString(lexer, position);
|
|
4433
4311
|
}
|
|
4434
4312
|
|
|
4435
|
-
return readString(
|
|
4436
|
-
|
|
4437
|
-
case 45: // -
|
|
4438
|
-
|
|
4439
|
-
case 48: // 0
|
|
4313
|
+
return readString(lexer, position);
|
|
4314
|
+
} // IntValue | FloatValue (Digit | -)
|
|
4440
4315
|
|
|
4441
|
-
|
|
4316
|
+
if (isDigit(code) || code === 0x002d) {
|
|
4317
|
+
return readNumber(lexer, position, code);
|
|
4318
|
+
} // Name
|
|
4442
4319
|
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
case 52: // 4
|
|
4448
|
-
|
|
4449
|
-
case 53: // 5
|
|
4320
|
+
if (isNameStart(code)) {
|
|
4321
|
+
return readName(lexer, position);
|
|
4322
|
+
}
|
|
4450
4323
|
|
|
4451
|
-
|
|
4324
|
+
throw syntaxError(
|
|
4325
|
+
lexer.source,
|
|
4326
|
+
position,
|
|
4327
|
+
code === 0x0027
|
|
4328
|
+
? 'Unexpected single quote character (\'), did you mean to use a double quote (")?'
|
|
4329
|
+
: isUnicodeScalarValue(code) || isSupplementaryCodePoint(body, position)
|
|
4330
|
+
? `Unexpected character: ${printCodePointAt(lexer, position)}.`
|
|
4331
|
+
: `Invalid character: ${printCodePointAt(lexer, position)}.`,
|
|
4332
|
+
);
|
|
4333
|
+
}
|
|
4452
4334
|
|
|
4453
|
-
|
|
4335
|
+
return createToken(lexer, TokenKind.EOF, bodyLength, bodyLength);
|
|
4336
|
+
}
|
|
4337
|
+
/**
|
|
4338
|
+
* Reads a comment token from the source file.
|
|
4339
|
+
*
|
|
4340
|
+
* ```
|
|
4341
|
+
* Comment :: # CommentChar* [lookahead != CommentChar]
|
|
4342
|
+
*
|
|
4343
|
+
* CommentChar :: SourceCharacter but not LineTerminator
|
|
4344
|
+
* ```
|
|
4345
|
+
*/
|
|
4454
4346
|
|
|
4455
|
-
|
|
4347
|
+
function readComment(lexer, start) {
|
|
4348
|
+
const body = lexer.source.body;
|
|
4349
|
+
const bodyLength = body.length;
|
|
4350
|
+
let position = start + 1;
|
|
4456
4351
|
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
return readNumber(source, pos, code, _line, _col, prev);
|
|
4352
|
+
while (position < bodyLength) {
|
|
4353
|
+
const code = body.charCodeAt(position); // LineTerminator (\n | \r)
|
|
4460
4354
|
|
|
4461
|
-
|
|
4355
|
+
if (code === 0x000a || code === 0x000d) {
|
|
4356
|
+
break;
|
|
4357
|
+
} // SourceCharacter
|
|
4462
4358
|
|
|
4463
|
-
|
|
4359
|
+
if (isUnicodeScalarValue(code)) {
|
|
4360
|
+
++position;
|
|
4361
|
+
} else if (isSupplementaryCodePoint(body, position)) {
|
|
4362
|
+
position += 2;
|
|
4363
|
+
} else {
|
|
4364
|
+
break;
|
|
4365
|
+
}
|
|
4366
|
+
}
|
|
4464
4367
|
|
|
4465
|
-
|
|
4368
|
+
return createToken(
|
|
4369
|
+
lexer,
|
|
4370
|
+
TokenKind.COMMENT,
|
|
4371
|
+
start,
|
|
4372
|
+
position,
|
|
4373
|
+
body.slice(start + 1, position),
|
|
4374
|
+
);
|
|
4375
|
+
}
|
|
4376
|
+
/**
|
|
4377
|
+
* Reads a number token from the source file, either a FloatValue or an IntValue
|
|
4378
|
+
* depending on whether a FractionalPart or ExponentPart is encountered.
|
|
4379
|
+
*
|
|
4380
|
+
* ```
|
|
4381
|
+
* IntValue :: IntegerPart [lookahead != {Digit, `.`, NameStart}]
|
|
4382
|
+
*
|
|
4383
|
+
* IntegerPart ::
|
|
4384
|
+
* - NegativeSign? 0
|
|
4385
|
+
* - NegativeSign? NonZeroDigit Digit*
|
|
4386
|
+
*
|
|
4387
|
+
* NegativeSign :: -
|
|
4388
|
+
*
|
|
4389
|
+
* NonZeroDigit :: Digit but not `0`
|
|
4390
|
+
*
|
|
4391
|
+
* FloatValue ::
|
|
4392
|
+
* - IntegerPart FractionalPart ExponentPart [lookahead != {Digit, `.`, NameStart}]
|
|
4393
|
+
* - IntegerPart FractionalPart [lookahead != {Digit, `.`, NameStart}]
|
|
4394
|
+
* - IntegerPart ExponentPart [lookahead != {Digit, `.`, NameStart}]
|
|
4395
|
+
*
|
|
4396
|
+
* FractionalPart :: . Digit+
|
|
4397
|
+
*
|
|
4398
|
+
* ExponentPart :: ExponentIndicator Sign? Digit+
|
|
4399
|
+
*
|
|
4400
|
+
* ExponentIndicator :: one of `e` `E`
|
|
4401
|
+
*
|
|
4402
|
+
* Sign :: one of + -
|
|
4403
|
+
* ```
|
|
4404
|
+
*/
|
|
4466
4405
|
|
|
4467
|
-
|
|
4406
|
+
function readNumber(lexer, start, firstCode) {
|
|
4407
|
+
const body = lexer.source.body;
|
|
4408
|
+
let position = start;
|
|
4409
|
+
let code = firstCode;
|
|
4410
|
+
let isFloat = false; // NegativeSign (-)
|
|
4468
4411
|
|
|
4469
|
-
|
|
4412
|
+
if (code === 0x002d) {
|
|
4413
|
+
code = body.charCodeAt(++position);
|
|
4414
|
+
} // Zero (0)
|
|
4470
4415
|
|
|
4471
|
-
|
|
4416
|
+
if (code === 0x0030) {
|
|
4417
|
+
code = body.charCodeAt(++position);
|
|
4472
4418
|
|
|
4473
|
-
|
|
4419
|
+
if (isDigit(code)) {
|
|
4420
|
+
throw syntaxError(
|
|
4421
|
+
lexer.source,
|
|
4422
|
+
position,
|
|
4423
|
+
`Invalid number, unexpected digit after 0: ${printCodePointAt(
|
|
4424
|
+
lexer,
|
|
4425
|
+
position,
|
|
4426
|
+
)}.`,
|
|
4427
|
+
);
|
|
4428
|
+
}
|
|
4429
|
+
} else {
|
|
4430
|
+
position = readDigits(lexer, position, code);
|
|
4431
|
+
code = body.charCodeAt(position);
|
|
4432
|
+
} // Full stop (.)
|
|
4474
4433
|
|
|
4475
|
-
|
|
4434
|
+
if (code === 0x002e) {
|
|
4435
|
+
isFloat = true;
|
|
4436
|
+
code = body.charCodeAt(++position);
|
|
4437
|
+
position = readDigits(lexer, position, code);
|
|
4438
|
+
code = body.charCodeAt(position);
|
|
4439
|
+
} // E e
|
|
4476
4440
|
|
|
4477
|
-
|
|
4441
|
+
if (code === 0x0045 || code === 0x0065) {
|
|
4442
|
+
isFloat = true;
|
|
4443
|
+
code = body.charCodeAt(++position); // + -
|
|
4478
4444
|
|
|
4479
|
-
|
|
4445
|
+
if (code === 0x002b || code === 0x002d) {
|
|
4446
|
+
code = body.charCodeAt(++position);
|
|
4447
|
+
}
|
|
4480
4448
|
|
|
4481
|
-
|
|
4449
|
+
position = readDigits(lexer, position, code);
|
|
4450
|
+
code = body.charCodeAt(position);
|
|
4451
|
+
} // Numbers cannot be followed by . or NameStart
|
|
4482
4452
|
|
|
4483
|
-
|
|
4453
|
+
if (code === 0x002e || isNameStart(code)) {
|
|
4454
|
+
throw syntaxError(
|
|
4455
|
+
lexer.source,
|
|
4456
|
+
position,
|
|
4457
|
+
`Invalid number, expected digit but got: ${printCodePointAt(
|
|
4458
|
+
lexer,
|
|
4459
|
+
position,
|
|
4460
|
+
)}.`,
|
|
4461
|
+
);
|
|
4462
|
+
}
|
|
4484
4463
|
|
|
4485
|
-
|
|
4464
|
+
return createToken(
|
|
4465
|
+
lexer,
|
|
4466
|
+
isFloat ? TokenKind.FLOAT : TokenKind.INT,
|
|
4467
|
+
start,
|
|
4468
|
+
position,
|
|
4469
|
+
body.slice(start, position),
|
|
4470
|
+
);
|
|
4471
|
+
}
|
|
4472
|
+
/**
|
|
4473
|
+
* Returns the new position in the source after reading one or more digits.
|
|
4474
|
+
*/
|
|
4486
4475
|
|
|
4487
|
-
|
|
4476
|
+
function readDigits(lexer, start, firstCode) {
|
|
4477
|
+
if (!isDigit(firstCode)) {
|
|
4478
|
+
throw syntaxError(
|
|
4479
|
+
lexer.source,
|
|
4480
|
+
start,
|
|
4481
|
+
`Invalid number, expected digit but got: ${printCodePointAt(
|
|
4482
|
+
lexer,
|
|
4483
|
+
start,
|
|
4484
|
+
)}.`,
|
|
4485
|
+
);
|
|
4486
|
+
}
|
|
4488
4487
|
|
|
4489
|
-
|
|
4488
|
+
const body = lexer.source.body;
|
|
4489
|
+
let position = start + 1; // +1 to skip first firstCode
|
|
4490
4490
|
|
|
4491
|
-
|
|
4491
|
+
while (isDigit(body.charCodeAt(position))) {
|
|
4492
|
+
++position;
|
|
4493
|
+
}
|
|
4492
4494
|
|
|
4493
|
-
|
|
4495
|
+
return position;
|
|
4496
|
+
}
|
|
4497
|
+
/**
|
|
4498
|
+
* Reads a single-quote string token from the source file.
|
|
4499
|
+
*
|
|
4500
|
+
* ```
|
|
4501
|
+
* StringValue ::
|
|
4502
|
+
* - `""` [lookahead != `"`]
|
|
4503
|
+
* - `"` StringCharacter+ `"`
|
|
4504
|
+
*
|
|
4505
|
+
* StringCharacter ::
|
|
4506
|
+
* - SourceCharacter but not `"` or `\` or LineTerminator
|
|
4507
|
+
* - `\u` EscapedUnicode
|
|
4508
|
+
* - `\` EscapedCharacter
|
|
4509
|
+
*
|
|
4510
|
+
* EscapedUnicode ::
|
|
4511
|
+
* - `{` HexDigit+ `}`
|
|
4512
|
+
* - HexDigit HexDigit HexDigit HexDigit
|
|
4513
|
+
*
|
|
4514
|
+
* EscapedCharacter :: one of `"` `\` `/` `b` `f` `n` `r` `t`
|
|
4515
|
+
* ```
|
|
4516
|
+
*/
|
|
4494
4517
|
|
|
4495
|
-
|
|
4518
|
+
function readString(lexer, start) {
|
|
4519
|
+
const body = lexer.source.body;
|
|
4520
|
+
const bodyLength = body.length;
|
|
4521
|
+
let position = start + 1;
|
|
4522
|
+
let chunkStart = position;
|
|
4523
|
+
let value = '';
|
|
4496
4524
|
|
|
4497
|
-
|
|
4525
|
+
while (position < bodyLength) {
|
|
4526
|
+
const code = body.charCodeAt(position); // Closing Quote (")
|
|
4498
4527
|
|
|
4499
|
-
|
|
4528
|
+
if (code === 0x0022) {
|
|
4529
|
+
value += body.slice(chunkStart, position);
|
|
4530
|
+
return createToken(lexer, TokenKind.STRING, start, position + 1, value);
|
|
4531
|
+
} // Escape Sequence (\)
|
|
4500
4532
|
|
|
4501
|
-
|
|
4533
|
+
if (code === 0x005c) {
|
|
4534
|
+
value += body.slice(chunkStart, position);
|
|
4535
|
+
const escape =
|
|
4536
|
+
body.charCodeAt(position + 1) === 0x0075 // u
|
|
4537
|
+
? body.charCodeAt(position + 2) === 0x007b // {
|
|
4538
|
+
? readEscapedUnicodeVariableWidth(lexer, position)
|
|
4539
|
+
: readEscapedUnicodeFixedWidth(lexer, position)
|
|
4540
|
+
: readEscapedCharacter(lexer, position);
|
|
4541
|
+
value += escape.value;
|
|
4542
|
+
position += escape.size;
|
|
4543
|
+
chunkStart = position;
|
|
4544
|
+
continue;
|
|
4545
|
+
} // LineTerminator (\n | \r)
|
|
4502
4546
|
|
|
4503
|
-
|
|
4547
|
+
if (code === 0x000a || code === 0x000d) {
|
|
4548
|
+
break;
|
|
4549
|
+
} // SourceCharacter
|
|
4504
4550
|
|
|
4505
|
-
|
|
4551
|
+
if (isUnicodeScalarValue(code)) {
|
|
4552
|
+
++position;
|
|
4553
|
+
} else if (isSupplementaryCodePoint(body, position)) {
|
|
4554
|
+
position += 2;
|
|
4555
|
+
} else {
|
|
4556
|
+
throw syntaxError(
|
|
4557
|
+
lexer.source,
|
|
4558
|
+
position,
|
|
4559
|
+
`Invalid character within String: ${printCodePointAt(
|
|
4560
|
+
lexer,
|
|
4561
|
+
position,
|
|
4562
|
+
)}.`,
|
|
4563
|
+
);
|
|
4564
|
+
}
|
|
4565
|
+
}
|
|
4506
4566
|
|
|
4507
|
-
|
|
4567
|
+
throw syntaxError(lexer.source, position, 'Unterminated string.');
|
|
4568
|
+
} // The string value and lexed size of an escape sequence.
|
|
4508
4569
|
|
|
4509
|
-
|
|
4570
|
+
function readEscapedUnicodeVariableWidth(lexer, position) {
|
|
4571
|
+
const body = lexer.source.body;
|
|
4572
|
+
let point = 0;
|
|
4573
|
+
let size = 3; // Cannot be larger than 12 chars (\u{00000000}).
|
|
4510
4574
|
|
|
4511
|
-
|
|
4575
|
+
while (size < 12) {
|
|
4576
|
+
const code = body.charCodeAt(position + size++); // Closing Brace (})
|
|
4512
4577
|
|
|
4513
|
-
|
|
4578
|
+
if (code === 0x007d) {
|
|
4579
|
+
// Must be at least 5 chars (\u{0}) and encode a Unicode scalar value.
|
|
4580
|
+
if (size < 5 || !isUnicodeScalarValue(point)) {
|
|
4581
|
+
break;
|
|
4582
|
+
}
|
|
4514
4583
|
|
|
4515
|
-
|
|
4584
|
+
return {
|
|
4585
|
+
value: String.fromCodePoint(point),
|
|
4586
|
+
size,
|
|
4587
|
+
};
|
|
4588
|
+
} // Append this hex digit to the code point.
|
|
4516
4589
|
|
|
4517
|
-
|
|
4590
|
+
point = (point << 4) | readHexDigit(code);
|
|
4518
4591
|
|
|
4519
|
-
|
|
4592
|
+
if (point < 0) {
|
|
4593
|
+
break;
|
|
4594
|
+
}
|
|
4595
|
+
}
|
|
4520
4596
|
|
|
4521
|
-
|
|
4597
|
+
throw syntaxError(
|
|
4598
|
+
lexer.source,
|
|
4599
|
+
position,
|
|
4600
|
+
`Invalid Unicode escape sequence: "${body.slice(
|
|
4601
|
+
position,
|
|
4602
|
+
position + size,
|
|
4603
|
+
)}".`,
|
|
4604
|
+
);
|
|
4605
|
+
}
|
|
4522
4606
|
|
|
4523
|
-
|
|
4607
|
+
function readEscapedUnicodeFixedWidth(lexer, position) {
|
|
4608
|
+
const body = lexer.source.body;
|
|
4609
|
+
const code = read16BitHexCode(body, position + 2);
|
|
4524
4610
|
|
|
4525
|
-
|
|
4611
|
+
if (isUnicodeScalarValue(code)) {
|
|
4612
|
+
return {
|
|
4613
|
+
value: String.fromCodePoint(code),
|
|
4614
|
+
size: 6,
|
|
4615
|
+
};
|
|
4616
|
+
} // GraphQL allows JSON-style surrogate pair escape sequences, but only when
|
|
4617
|
+
// a valid pair is formed.
|
|
4618
|
+
|
|
4619
|
+
if (isLeadingSurrogate(code)) {
|
|
4620
|
+
// \u
|
|
4621
|
+
if (
|
|
4622
|
+
body.charCodeAt(position + 6) === 0x005c &&
|
|
4623
|
+
body.charCodeAt(position + 7) === 0x0075
|
|
4624
|
+
) {
|
|
4625
|
+
const trailingCode = read16BitHexCode(body, position + 8);
|
|
4626
|
+
|
|
4627
|
+
if (isTrailingSurrogate(trailingCode)) {
|
|
4628
|
+
// JavaScript defines strings as a sequence of UTF-16 code units and
|
|
4629
|
+
// encodes Unicode code points above U+FFFF using a surrogate pair of
|
|
4630
|
+
// code units. Since this is a surrogate pair escape sequence, just
|
|
4631
|
+
// include both codes into the JavaScript string value. Had JavaScript
|
|
4632
|
+
// not been internally based on UTF-16, then this surrogate pair would
|
|
4633
|
+
// be decoded to retrieve the supplementary code point.
|
|
4634
|
+
return {
|
|
4635
|
+
value: String.fromCodePoint(code, trailingCode),
|
|
4636
|
+
size: 12,
|
|
4637
|
+
};
|
|
4638
|
+
}
|
|
4639
|
+
}
|
|
4640
|
+
}
|
|
4526
4641
|
|
|
4527
|
-
|
|
4642
|
+
throw syntaxError(
|
|
4643
|
+
lexer.source,
|
|
4644
|
+
position,
|
|
4645
|
+
`Invalid Unicode escape sequence: "${body.slice(position, position + 6)}".`,
|
|
4646
|
+
);
|
|
4647
|
+
}
|
|
4648
|
+
/**
|
|
4649
|
+
* Reads four hexadecimal characters and returns the positive integer that 16bit
|
|
4650
|
+
* hexadecimal string represents. For example, "000f" will return 15, and "dead"
|
|
4651
|
+
* will return 57005.
|
|
4652
|
+
*
|
|
4653
|
+
* Returns a negative number if any char was not a valid hexadecimal digit.
|
|
4654
|
+
*/
|
|
4528
4655
|
|
|
4529
|
-
|
|
4656
|
+
function read16BitHexCode(body, position) {
|
|
4657
|
+
// readHexDigit() returns -1 on error. ORing a negative value with any other
|
|
4658
|
+
// value always produces a negative value.
|
|
4659
|
+
return (
|
|
4660
|
+
(readHexDigit(body.charCodeAt(position)) << 12) |
|
|
4661
|
+
(readHexDigit(body.charCodeAt(position + 1)) << 8) |
|
|
4662
|
+
(readHexDigit(body.charCodeAt(position + 2)) << 4) |
|
|
4663
|
+
readHexDigit(body.charCodeAt(position + 3))
|
|
4664
|
+
);
|
|
4665
|
+
}
|
|
4666
|
+
/**
|
|
4667
|
+
* Reads a hexadecimal character and returns its positive integer value (0-15).
|
|
4668
|
+
*
|
|
4669
|
+
* '0' becomes 0, '9' becomes 9
|
|
4670
|
+
* 'A' becomes 10, 'F' becomes 15
|
|
4671
|
+
* 'a' becomes 10, 'f' becomes 15
|
|
4672
|
+
*
|
|
4673
|
+
* Returns -1 if the provided character code was not a valid hexadecimal digit.
|
|
4674
|
+
*
|
|
4675
|
+
* HexDigit :: one of
|
|
4676
|
+
* - `0` `1` `2` `3` `4` `5` `6` `7` `8` `9`
|
|
4677
|
+
* - `A` `B` `C` `D` `E` `F`
|
|
4678
|
+
* - `a` `b` `c` `d` `e` `f`
|
|
4679
|
+
*/
|
|
4530
4680
|
|
|
4531
|
-
|
|
4681
|
+
function readHexDigit(code) {
|
|
4682
|
+
return code >= 0x0030 && code <= 0x0039 // 0-9
|
|
4683
|
+
? code - 0x0030
|
|
4684
|
+
: code >= 0x0041 && code <= 0x0046 // A-F
|
|
4685
|
+
? code - 0x0037
|
|
4686
|
+
: code >= 0x0061 && code <= 0x0066 // a-f
|
|
4687
|
+
? code - 0x0057
|
|
4688
|
+
: -1;
|
|
4689
|
+
}
|
|
4690
|
+
/**
|
|
4691
|
+
* | Escaped Character | Code Point | Character Name |
|
|
4692
|
+
* | ----------------- | ---------- | ---------------------------- |
|
|
4693
|
+
* | `"` | U+0022 | double quote |
|
|
4694
|
+
* | `\` | U+005C | reverse solidus (back slash) |
|
|
4695
|
+
* | `/` | U+002F | solidus (forward slash) |
|
|
4696
|
+
* | `b` | U+0008 | backspace |
|
|
4697
|
+
* | `f` | U+000C | form feed |
|
|
4698
|
+
* | `n` | U+000A | line feed (new line) |
|
|
4699
|
+
* | `r` | U+000D | carriage return |
|
|
4700
|
+
* | `t` | U+0009 | horizontal tab |
|
|
4701
|
+
*/
|
|
4532
4702
|
|
|
4533
|
-
|
|
4703
|
+
function readEscapedCharacter(lexer, position) {
|
|
4704
|
+
const body = lexer.source.body;
|
|
4705
|
+
const code = body.charCodeAt(position + 1);
|
|
4534
4706
|
|
|
4535
|
-
|
|
4707
|
+
switch (code) {
|
|
4708
|
+
case 0x0022:
|
|
4709
|
+
// "
|
|
4710
|
+
return {
|
|
4711
|
+
value: '\u0022',
|
|
4712
|
+
size: 2,
|
|
4713
|
+
};
|
|
4536
4714
|
|
|
4537
|
-
|
|
4715
|
+
case 0x005c:
|
|
4716
|
+
// \
|
|
4717
|
+
return {
|
|
4718
|
+
value: '\u005c',
|
|
4719
|
+
size: 2,
|
|
4720
|
+
};
|
|
4538
4721
|
|
|
4539
|
-
|
|
4722
|
+
case 0x002f:
|
|
4723
|
+
// /
|
|
4724
|
+
return {
|
|
4725
|
+
value: '\u002f',
|
|
4726
|
+
size: 2,
|
|
4727
|
+
};
|
|
4540
4728
|
|
|
4541
|
-
|
|
4729
|
+
case 0x0062:
|
|
4730
|
+
// b
|
|
4731
|
+
return {
|
|
4732
|
+
value: '\u0008',
|
|
4733
|
+
size: 2,
|
|
4734
|
+
};
|
|
4542
4735
|
|
|
4543
|
-
|
|
4736
|
+
case 0x0066:
|
|
4737
|
+
// f
|
|
4738
|
+
return {
|
|
4739
|
+
value: '\u000c',
|
|
4740
|
+
size: 2,
|
|
4741
|
+
};
|
|
4544
4742
|
|
|
4545
|
-
|
|
4743
|
+
case 0x006e:
|
|
4744
|
+
// n
|
|
4745
|
+
return {
|
|
4746
|
+
value: '\u000a',
|
|
4747
|
+
size: 2,
|
|
4748
|
+
};
|
|
4546
4749
|
|
|
4547
|
-
|
|
4750
|
+
case 0x0072:
|
|
4751
|
+
// r
|
|
4752
|
+
return {
|
|
4753
|
+
value: '\u000d',
|
|
4754
|
+
size: 2,
|
|
4755
|
+
};
|
|
4548
4756
|
|
|
4549
|
-
|
|
4757
|
+
case 0x0074:
|
|
4758
|
+
// t
|
|
4759
|
+
return {
|
|
4760
|
+
value: '\u0009',
|
|
4761
|
+
size: 2,
|
|
4762
|
+
};
|
|
4763
|
+
}
|
|
4550
4764
|
|
|
4551
|
-
|
|
4765
|
+
throw syntaxError(
|
|
4766
|
+
lexer.source,
|
|
4767
|
+
position,
|
|
4768
|
+
`Invalid character escape sequence: "${body.slice(
|
|
4769
|
+
position,
|
|
4770
|
+
position + 2,
|
|
4771
|
+
)}".`,
|
|
4772
|
+
);
|
|
4773
|
+
}
|
|
4774
|
+
/**
|
|
4775
|
+
* Reads a block string token from the source file.
|
|
4776
|
+
*
|
|
4777
|
+
* ```
|
|
4778
|
+
* StringValue ::
|
|
4779
|
+
* - `"""` BlockStringCharacter* `"""`
|
|
4780
|
+
*
|
|
4781
|
+
* BlockStringCharacter ::
|
|
4782
|
+
* - SourceCharacter but not `"""` or `\"""`
|
|
4783
|
+
* - `\"""`
|
|
4784
|
+
* ```
|
|
4785
|
+
*/
|
|
4552
4786
|
|
|
4553
|
-
|
|
4787
|
+
function readBlockString(lexer, start) {
|
|
4788
|
+
const body = lexer.source.body;
|
|
4789
|
+
const bodyLength = body.length;
|
|
4790
|
+
let lineStart = lexer.lineStart;
|
|
4791
|
+
let position = start + 3;
|
|
4792
|
+
let chunkStart = position;
|
|
4793
|
+
let currentLine = '';
|
|
4794
|
+
const blockLines = [];
|
|
4795
|
+
|
|
4796
|
+
while (position < bodyLength) {
|
|
4797
|
+
const code = body.charCodeAt(position); // Closing Triple-Quote (""")
|
|
4798
|
+
|
|
4799
|
+
if (
|
|
4800
|
+
code === 0x0022 &&
|
|
4801
|
+
body.charCodeAt(position + 1) === 0x0022 &&
|
|
4802
|
+
body.charCodeAt(position + 2) === 0x0022
|
|
4803
|
+
) {
|
|
4804
|
+
currentLine += body.slice(chunkStart, position);
|
|
4805
|
+
blockLines.push(currentLine);
|
|
4806
|
+
const token = createToken(
|
|
4807
|
+
lexer,
|
|
4808
|
+
TokenKind.BLOCK_STRING,
|
|
4809
|
+
start,
|
|
4810
|
+
position + 3, // Return a string of the lines joined with U+000A.
|
|
4811
|
+
dedentBlockStringLines(blockLines).join('\n'),
|
|
4812
|
+
);
|
|
4813
|
+
lexer.line += blockLines.length - 1;
|
|
4814
|
+
lexer.lineStart = lineStart;
|
|
4815
|
+
return token;
|
|
4816
|
+
} // Escaped Triple-Quote (\""")
|
|
4554
4817
|
|
|
4555
|
-
|
|
4818
|
+
if (
|
|
4819
|
+
code === 0x005c &&
|
|
4820
|
+
body.charCodeAt(position + 1) === 0x0022 &&
|
|
4821
|
+
body.charCodeAt(position + 2) === 0x0022 &&
|
|
4822
|
+
body.charCodeAt(position + 3) === 0x0022
|
|
4823
|
+
) {
|
|
4824
|
+
currentLine += body.slice(chunkStart, position);
|
|
4825
|
+
chunkStart = position + 1; // skip only slash
|
|
4556
4826
|
|
|
4557
|
-
|
|
4827
|
+
position += 4;
|
|
4828
|
+
continue;
|
|
4829
|
+
} // LineTerminator
|
|
4558
4830
|
|
|
4559
|
-
|
|
4831
|
+
if (code === 0x000a || code === 0x000d) {
|
|
4832
|
+
currentLine += body.slice(chunkStart, position);
|
|
4833
|
+
blockLines.push(currentLine);
|
|
4560
4834
|
|
|
4561
|
-
|
|
4835
|
+
if (code === 0x000d && body.charCodeAt(position + 1) === 0x000a) {
|
|
4836
|
+
position += 2;
|
|
4837
|
+
} else {
|
|
4838
|
+
++position;
|
|
4839
|
+
}
|
|
4562
4840
|
|
|
4563
|
-
|
|
4841
|
+
currentLine = '';
|
|
4842
|
+
chunkStart = position;
|
|
4843
|
+
lineStart = position;
|
|
4844
|
+
continue;
|
|
4845
|
+
} // SourceCharacter
|
|
4564
4846
|
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4847
|
+
if (isUnicodeScalarValue(code)) {
|
|
4848
|
+
++position;
|
|
4849
|
+
} else if (isSupplementaryCodePoint(body, position)) {
|
|
4850
|
+
position += 2;
|
|
4851
|
+
} else {
|
|
4852
|
+
throw syntaxError(
|
|
4853
|
+
lexer.source,
|
|
4854
|
+
position,
|
|
4855
|
+
`Invalid character within String: ${printCodePointAt(
|
|
4856
|
+
lexer,
|
|
4857
|
+
position,
|
|
4858
|
+
)}.`,
|
|
4859
|
+
);
|
|
4568
4860
|
}
|
|
4569
|
-
|
|
4570
|
-
throw syntaxError(source, pos, unexpectedCharacterMessage(code));
|
|
4571
4861
|
}
|
|
4572
4862
|
|
|
4573
|
-
|
|
4574
|
-
var col = 1 + pos - lexer.lineStart;
|
|
4575
|
-
return new Token(TokenKind.EOF, bodyLength, bodyLength, line, col, prev);
|
|
4863
|
+
throw syntaxError(lexer.source, position, 'Unterminated string.');
|
|
4576
4864
|
}
|
|
4577
4865
|
/**
|
|
4578
|
-
*
|
|
4866
|
+
* Reads an alphanumeric + underscore name from the source.
|
|
4867
|
+
*
|
|
4868
|
+
* ```
|
|
4869
|
+
* Name ::
|
|
4870
|
+
* - NameStart NameContinue* [lookahead != NameContinue]
|
|
4871
|
+
* ```
|
|
4579
4872
|
*/
|
|
4580
4873
|
|
|
4874
|
+
function readName(lexer, start) {
|
|
4875
|
+
const body = lexer.source.body;
|
|
4876
|
+
const bodyLength = body.length;
|
|
4877
|
+
let position = start + 1;
|
|
4581
4878
|
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
return "Cannot contain the invalid character ".concat(printCharCode(code), ".");
|
|
4585
|
-
}
|
|
4879
|
+
while (position < bodyLength) {
|
|
4880
|
+
const code = body.charCodeAt(position);
|
|
4586
4881
|
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4882
|
+
if (isNameContinue(code)) {
|
|
4883
|
+
++position;
|
|
4884
|
+
} else {
|
|
4885
|
+
break;
|
|
4886
|
+
}
|
|
4590
4887
|
}
|
|
4591
4888
|
|
|
4592
|
-
return
|
|
4889
|
+
return createToken(
|
|
4890
|
+
lexer,
|
|
4891
|
+
TokenKind.NAME,
|
|
4892
|
+
start,
|
|
4893
|
+
position,
|
|
4894
|
+
body.slice(start, position),
|
|
4895
|
+
);
|
|
4593
4896
|
}
|
|
4594
|
-
/**
|
|
4595
|
-
* Reads a comment token from the source file.
|
|
4596
|
-
*
|
|
4597
|
-
* #[\u0009\u0020-\uFFFF]*
|
|
4598
|
-
*/
|
|
4599
4897
|
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
var body = source.body;
|
|
4603
|
-
var code;
|
|
4604
|
-
var position = start;
|
|
4605
|
-
|
|
4606
|
-
do {
|
|
4607
|
-
code = body.charCodeAt(++position);
|
|
4608
|
-
} while (!isNaN(code) && ( // SourceCharacter but not LineTerminator
|
|
4609
|
-
code > 0x001f || code === 0x0009));
|
|
4610
|
-
|
|
4611
|
-
return new Token(TokenKind.COMMENT, start, position, line, col, prev, body.slice(start + 1, position));
|
|
4612
|
-
}
|
|
4898
|
+
const MAX_ARRAY_LENGTH = 10;
|
|
4899
|
+
const MAX_RECURSIVE_DEPTH = 2;
|
|
4613
4900
|
/**
|
|
4614
|
-
*
|
|
4615
|
-
* or an int depending on whether a decimal point appears.
|
|
4616
|
-
*
|
|
4617
|
-
* Int: -?(0|[1-9][0-9]*)
|
|
4618
|
-
* Float: -?(0|[1-9][0-9]*)(\.[0-9]+)?((E|e)(+|-)?[0-9]+)?
|
|
4901
|
+
* Used to print values in error messages.
|
|
4619
4902
|
*/
|
|
4620
4903
|
|
|
4904
|
+
function inspect(value) {
|
|
4905
|
+
return formatValue(value, []);
|
|
4906
|
+
}
|
|
4621
4907
|
|
|
4622
|
-
function
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
var isFloat = false;
|
|
4908
|
+
function formatValue(value, seenValues) {
|
|
4909
|
+
switch (typeof value) {
|
|
4910
|
+
case 'string':
|
|
4911
|
+
return JSON.stringify(value);
|
|
4627
4912
|
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
code = body.charCodeAt(++position);
|
|
4631
|
-
}
|
|
4913
|
+
case 'function':
|
|
4914
|
+
return value.name ? `[function ${value.name}]` : '[function]';
|
|
4632
4915
|
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
code = body.charCodeAt(++position);
|
|
4916
|
+
case 'object':
|
|
4917
|
+
return formatObjectValue(value, seenValues);
|
|
4636
4918
|
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
}
|
|
4640
|
-
} else {
|
|
4641
|
-
position = readDigits(source, position, code);
|
|
4642
|
-
code = body.charCodeAt(position);
|
|
4919
|
+
default:
|
|
4920
|
+
return String(value);
|
|
4643
4921
|
}
|
|
4922
|
+
}
|
|
4644
4923
|
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
code = body.charCodeAt(++position);
|
|
4649
|
-
position = readDigits(source, position, code);
|
|
4650
|
-
code = body.charCodeAt(position);
|
|
4924
|
+
function formatObjectValue(value, previouslySeenValues) {
|
|
4925
|
+
if (value === null) {
|
|
4926
|
+
return 'null';
|
|
4651
4927
|
}
|
|
4652
4928
|
|
|
4653
|
-
if (
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
code = body.charCodeAt(++position);
|
|
4657
|
-
|
|
4658
|
-
if (code === 43 || code === 45) {
|
|
4659
|
-
// + -
|
|
4660
|
-
code = body.charCodeAt(++position);
|
|
4661
|
-
}
|
|
4929
|
+
if (previouslySeenValues.includes(value)) {
|
|
4930
|
+
return '[Circular]';
|
|
4931
|
+
}
|
|
4662
4932
|
|
|
4663
|
-
|
|
4664
|
-
code = body.charCodeAt(position);
|
|
4665
|
-
} // Numbers cannot be followed by . or NameStart
|
|
4933
|
+
const seenValues = [...previouslySeenValues, value];
|
|
4666
4934
|
|
|
4935
|
+
if (isJSONable(value)) {
|
|
4936
|
+
const jsonValue = value.toJSON(); // check for infinite recursion
|
|
4667
4937
|
|
|
4668
|
-
|
|
4669
|
-
|
|
4938
|
+
if (jsonValue !== value) {
|
|
4939
|
+
return typeof jsonValue === 'string'
|
|
4940
|
+
? jsonValue
|
|
4941
|
+
: formatValue(jsonValue, seenValues);
|
|
4942
|
+
}
|
|
4943
|
+
} else if (Array.isArray(value)) {
|
|
4944
|
+
return formatArray(value, seenValues);
|
|
4670
4945
|
}
|
|
4671
4946
|
|
|
4672
|
-
return
|
|
4947
|
+
return formatObject(value, seenValues);
|
|
4673
4948
|
}
|
|
4674
|
-
/**
|
|
4675
|
-
* Returns the new position in the source after reading digits.
|
|
4676
|
-
*/
|
|
4677
|
-
|
|
4678
4949
|
|
|
4679
|
-
function
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
var code = firstCode;
|
|
4950
|
+
function isJSONable(value) {
|
|
4951
|
+
return typeof value.toJSON === 'function';
|
|
4952
|
+
}
|
|
4683
4953
|
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
do {
|
|
4687
|
-
code = body.charCodeAt(++position);
|
|
4688
|
-
} while (code >= 48 && code <= 57); // 0 - 9
|
|
4954
|
+
function formatObject(object, seenValues) {
|
|
4955
|
+
const entries = Object.entries(object);
|
|
4689
4956
|
|
|
4957
|
+
if (entries.length === 0) {
|
|
4958
|
+
return '{}';
|
|
4959
|
+
}
|
|
4690
4960
|
|
|
4691
|
-
|
|
4961
|
+
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
|
4962
|
+
return '[' + getObjectTag(object) + ']';
|
|
4692
4963
|
}
|
|
4693
4964
|
|
|
4694
|
-
|
|
4965
|
+
const properties = entries.map(
|
|
4966
|
+
([key, value]) => key + ': ' + formatValue(value, seenValues),
|
|
4967
|
+
);
|
|
4968
|
+
return '{ ' + properties.join(', ') + ' }';
|
|
4695
4969
|
}
|
|
4696
|
-
/**
|
|
4697
|
-
* Reads a string token from the source file.
|
|
4698
|
-
*
|
|
4699
|
-
* "([^"\\\u000A\u000D]|(\\(u[0-9a-fA-F]{4}|["\\/bfnrt])))*"
|
|
4700
|
-
*/
|
|
4701
4970
|
|
|
4971
|
+
function formatArray(array, seenValues) {
|
|
4972
|
+
if (array.length === 0) {
|
|
4973
|
+
return '[]';
|
|
4974
|
+
}
|
|
4702
4975
|
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
var chunkStart = position;
|
|
4707
|
-
var code = 0;
|
|
4708
|
-
var value = '';
|
|
4709
|
-
|
|
4710
|
-
while (position < body.length && !isNaN(code = body.charCodeAt(position)) && // not LineTerminator
|
|
4711
|
-
code !== 0x000a && code !== 0x000d) {
|
|
4712
|
-
// Closing Quote (")
|
|
4713
|
-
if (code === 34) {
|
|
4714
|
-
value += body.slice(chunkStart, position);
|
|
4715
|
-
return new Token(TokenKind.STRING, start, position + 1, line, col, prev, value);
|
|
4716
|
-
} // SourceCharacter
|
|
4976
|
+
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
|
4977
|
+
return '[Array]';
|
|
4978
|
+
}
|
|
4717
4979
|
|
|
4980
|
+
const len = Math.min(MAX_ARRAY_LENGTH, array.length);
|
|
4981
|
+
const remaining = array.length - len;
|
|
4982
|
+
const items = [];
|
|
4718
4983
|
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4984
|
+
for (let i = 0; i < len; ++i) {
|
|
4985
|
+
items.push(formatValue(array[i], seenValues));
|
|
4986
|
+
}
|
|
4722
4987
|
|
|
4723
|
-
|
|
4988
|
+
if (remaining === 1) {
|
|
4989
|
+
items.push('... 1 more item');
|
|
4990
|
+
} else if (remaining > 1) {
|
|
4991
|
+
items.push(`... ${remaining} more items`);
|
|
4992
|
+
}
|
|
4724
4993
|
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
value += body.slice(chunkStart, position - 1);
|
|
4728
|
-
code = body.charCodeAt(position);
|
|
4729
|
-
|
|
4730
|
-
switch (code) {
|
|
4731
|
-
case 34:
|
|
4732
|
-
value += '"';
|
|
4733
|
-
break;
|
|
4734
|
-
|
|
4735
|
-
case 47:
|
|
4736
|
-
value += '/';
|
|
4737
|
-
break;
|
|
4738
|
-
|
|
4739
|
-
case 92:
|
|
4740
|
-
value += '\\';
|
|
4741
|
-
break;
|
|
4742
|
-
|
|
4743
|
-
case 98:
|
|
4744
|
-
value += '\b';
|
|
4745
|
-
break;
|
|
4746
|
-
|
|
4747
|
-
case 102:
|
|
4748
|
-
value += '\f';
|
|
4749
|
-
break;
|
|
4750
|
-
|
|
4751
|
-
case 110:
|
|
4752
|
-
value += '\n';
|
|
4753
|
-
break;
|
|
4754
|
-
|
|
4755
|
-
case 114:
|
|
4756
|
-
value += '\r';
|
|
4757
|
-
break;
|
|
4758
|
-
|
|
4759
|
-
case 116:
|
|
4760
|
-
value += '\t';
|
|
4761
|
-
break;
|
|
4762
|
-
|
|
4763
|
-
case 117:
|
|
4764
|
-
{
|
|
4765
|
-
// uXXXX
|
|
4766
|
-
var charCode = uniCharCode(body.charCodeAt(position + 1), body.charCodeAt(position + 2), body.charCodeAt(position + 3), body.charCodeAt(position + 4));
|
|
4767
|
-
|
|
4768
|
-
if (charCode < 0) {
|
|
4769
|
-
var invalidSequence = body.slice(position + 1, position + 5);
|
|
4770
|
-
throw syntaxError(source, position, "Invalid character escape sequence: \\u".concat(invalidSequence, "."));
|
|
4771
|
-
}
|
|
4994
|
+
return '[' + items.join(', ') + ']';
|
|
4995
|
+
}
|
|
4772
4996
|
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4997
|
+
function getObjectTag(object) {
|
|
4998
|
+
const tag = Object.prototype.toString
|
|
4999
|
+
.call(object)
|
|
5000
|
+
.replace(/^\[object /, '')
|
|
5001
|
+
.replace(/]$/, '');
|
|
4777
5002
|
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
}
|
|
5003
|
+
if (tag === 'Object' && typeof object.constructor === 'function') {
|
|
5004
|
+
const name = object.constructor.name;
|
|
4781
5005
|
|
|
4782
|
-
|
|
4783
|
-
|
|
5006
|
+
if (typeof name === 'string' && name !== '') {
|
|
5007
|
+
return name;
|
|
4784
5008
|
}
|
|
4785
5009
|
}
|
|
4786
5010
|
|
|
4787
|
-
|
|
5011
|
+
return tag;
|
|
4788
5012
|
}
|
|
5013
|
+
|
|
4789
5014
|
/**
|
|
4790
|
-
*
|
|
4791
|
-
*
|
|
4792
|
-
*
|
|
5015
|
+
* A replacement for instanceof which includes an error warning when multi-realm
|
|
5016
|
+
* constructors are detected.
|
|
5017
|
+
* See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
|
|
5018
|
+
* See: https://webpack.js.org/guides/production/
|
|
4793
5019
|
*/
|
|
4794
5020
|
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
var rawValue = '';
|
|
4802
|
-
|
|
4803
|
-
while (position < body.length && !isNaN(code = body.charCodeAt(position))) {
|
|
4804
|
-
// Closing Triple-Quote (""")
|
|
4805
|
-
if (code === 34 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34) {
|
|
4806
|
-
rawValue += body.slice(chunkStart, position);
|
|
4807
|
-
return new Token(TokenKind.BLOCK_STRING, start, position + 3, line, col, prev, dedentBlockStringValue(rawValue));
|
|
4808
|
-
} // SourceCharacter
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
|
|
4812
|
-
throw syntaxError(source, position, "Invalid character within String: ".concat(printCharCode(code), "."));
|
|
4813
|
-
}
|
|
4814
|
-
|
|
4815
|
-
if (code === 10) {
|
|
4816
|
-
// new line
|
|
4817
|
-
++position;
|
|
4818
|
-
++lexer.line;
|
|
4819
|
-
lexer.lineStart = position;
|
|
4820
|
-
} else if (code === 13) {
|
|
4821
|
-
// carriage return
|
|
4822
|
-
if (body.charCodeAt(position + 1) === 10) {
|
|
4823
|
-
position += 2;
|
|
4824
|
-
} else {
|
|
4825
|
-
++position;
|
|
5021
|
+
const instanceOf =
|
|
5022
|
+
/* c8 ignore next 5 */
|
|
5023
|
+
// FIXME: https://github.com/graphql/graphql-js/issues/2317
|
|
5024
|
+
process.env.NODE_ENV === 'production'
|
|
5025
|
+
? function instanceOf(value, constructor) {
|
|
5026
|
+
return value instanceof constructor;
|
|
4826
5027
|
}
|
|
5028
|
+
: function instanceOf(value, constructor) {
|
|
5029
|
+
if (value instanceof constructor) {
|
|
5030
|
+
return true;
|
|
5031
|
+
}
|
|
4827
5032
|
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
5033
|
+
if (typeof value === 'object' && value !== null) {
|
|
5034
|
+
var _value$constructor;
|
|
5035
|
+
|
|
5036
|
+
// Prefer Symbol.toStringTag since it is immune to minification.
|
|
5037
|
+
const className = constructor.prototype[Symbol.toStringTag];
|
|
5038
|
+
const valueClassName = // We still need to support constructor's name to detect conflicts with older versions of this library.
|
|
5039
|
+
Symbol.toStringTag in value // @ts-expect-error TS bug see, https://github.com/microsoft/TypeScript/issues/38009
|
|
5040
|
+
? value[Symbol.toStringTag]
|
|
5041
|
+
: (_value$constructor = value.constructor) === null ||
|
|
5042
|
+
_value$constructor === void 0
|
|
5043
|
+
? void 0
|
|
5044
|
+
: _value$constructor.name;
|
|
5045
|
+
|
|
5046
|
+
if (className === valueClassName) {
|
|
5047
|
+
const stringifiedValue = inspect(value);
|
|
5048
|
+
throw new Error(`Cannot use ${className} "${stringifiedValue}" from another module or realm.
|
|
5049
|
+
|
|
5050
|
+
Ensure that there is only one instance of "graphql" in the node_modules
|
|
5051
|
+
directory. If different versions of "graphql" are the dependencies of other
|
|
5052
|
+
relied on modules, use "resolutions" to ensure only one version is installed.
|
|
5053
|
+
|
|
5054
|
+
https://yarnpkg.com/en/docs/selective-version-resolutions
|
|
5055
|
+
|
|
5056
|
+
Duplicate "graphql" modules cannot be used at the same time since different
|
|
5057
|
+
versions may have different capabilities and behavior. The data from one
|
|
5058
|
+
version used in the function from another could produce confusing and
|
|
5059
|
+
spurious results.`);
|
|
5060
|
+
}
|
|
5061
|
+
}
|
|
4852
5062
|
|
|
5063
|
+
return false;
|
|
5064
|
+
};
|
|
4853
5065
|
|
|
4854
|
-
function uniCharCode(a, b, c, d) {
|
|
4855
|
-
return char2hex(a) << 12 | char2hex(b) << 8 | char2hex(c) << 4 | char2hex(d);
|
|
4856
|
-
}
|
|
4857
5066
|
/**
|
|
4858
|
-
*
|
|
4859
|
-
*
|
|
4860
|
-
*
|
|
4861
|
-
*
|
|
4862
|
-
*
|
|
4863
|
-
* Returns -1 on error.
|
|
5067
|
+
* A representation of source input to GraphQL. The `name` and `locationOffset` parameters are
|
|
5068
|
+
* optional, but they are useful for clients who store GraphQL documents in source files.
|
|
5069
|
+
* For example, if the GraphQL input starts at line 40 in a file named `Foo.graphql`, it might
|
|
5070
|
+
* be useful for `name` to be `"Foo.graphql"` and location to be `{ line: 40, column: 1 }`.
|
|
5071
|
+
* The `line` and `column` properties in `locationOffset` are 1-indexed.
|
|
4864
5072
|
*/
|
|
5073
|
+
class Source {
|
|
5074
|
+
constructor(
|
|
5075
|
+
body,
|
|
5076
|
+
name = 'GraphQL request',
|
|
5077
|
+
locationOffset = {
|
|
5078
|
+
line: 1,
|
|
5079
|
+
column: 1,
|
|
5080
|
+
},
|
|
5081
|
+
) {
|
|
5082
|
+
typeof body === 'string' ||
|
|
5083
|
+
devAssert(false, `Body must be a string. Received: ${inspect(body)}.`);
|
|
5084
|
+
this.body = body;
|
|
5085
|
+
this.name = name;
|
|
5086
|
+
this.locationOffset = locationOffset;
|
|
5087
|
+
this.locationOffset.line > 0 ||
|
|
5088
|
+
devAssert(
|
|
5089
|
+
false,
|
|
5090
|
+
'line in locationOffset is 1-indexed and must be positive.',
|
|
5091
|
+
);
|
|
5092
|
+
this.locationOffset.column > 0 ||
|
|
5093
|
+
devAssert(
|
|
5094
|
+
false,
|
|
5095
|
+
'column in locationOffset is 1-indexed and must be positive.',
|
|
5096
|
+
);
|
|
5097
|
+
}
|
|
4865
5098
|
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
: a >= 65 && a <= 70 ? a - 55 // A-F
|
|
4870
|
-
: a >= 97 && a <= 102 ? a - 87 // a-f
|
|
4871
|
-
: -1;
|
|
5099
|
+
get [Symbol.toStringTag]() {
|
|
5100
|
+
return 'Source';
|
|
5101
|
+
}
|
|
4872
5102
|
}
|
|
4873
5103
|
/**
|
|
4874
|
-
*
|
|
5104
|
+
* Test if the given value is a Source object.
|
|
4875
5105
|
*
|
|
4876
|
-
*
|
|
5106
|
+
* @internal
|
|
4877
5107
|
*/
|
|
4878
5108
|
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
var body = source.body;
|
|
4882
|
-
var bodyLength = body.length;
|
|
4883
|
-
var position = start + 1;
|
|
4884
|
-
var code = 0;
|
|
4885
|
-
|
|
4886
|
-
while (position !== bodyLength && !isNaN(code = body.charCodeAt(position)) && (code === 95 || // _
|
|
4887
|
-
code >= 48 && code <= 57 || // 0-9
|
|
4888
|
-
code >= 65 && code <= 90 || // A-Z
|
|
4889
|
-
code >= 97 && code <= 122) // a-z
|
|
4890
|
-
) {
|
|
4891
|
-
++position;
|
|
4892
|
-
}
|
|
4893
|
-
|
|
4894
|
-
return new Token(TokenKind.NAME, start, position, line, col, prev, body.slice(start, position));
|
|
4895
|
-
} // _ A-Z a-z
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
function isNameStart(code) {
|
|
4899
|
-
return code === 95 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
5109
|
+
function isSource(source) {
|
|
5110
|
+
return instanceOf(source, Source);
|
|
4900
5111
|
}
|
|
4901
5112
|
|
|
4902
5113
|
/**
|
|
@@ -4908,7 +5119,7 @@ function isNameStart(code) {
|
|
|
4908
5119
|
* Throws GraphQLError if a syntax error is encountered.
|
|
4909
5120
|
*/
|
|
4910
5121
|
function parse$1(source, options) {
|
|
4911
|
-
|
|
5122
|
+
const parser = new Parser(source, options);
|
|
4912
5123
|
return parser.parseDocument();
|
|
4913
5124
|
}
|
|
4914
5125
|
/**
|
|
@@ -4923,9 +5134,9 @@ function parse$1(source, options) {
|
|
|
4923
5134
|
* @internal
|
|
4924
5135
|
*/
|
|
4925
5136
|
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
5137
|
+
class Parser {
|
|
5138
|
+
constructor(source, options) {
|
|
5139
|
+
const sourceObj = isSource(source) ? source : new Source(source);
|
|
4929
5140
|
this._lexer = new Lexer(sourceObj);
|
|
4930
5141
|
this._options = options;
|
|
4931
5142
|
}
|
|
@@ -4933,30 +5144,27 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4933
5144
|
* Converts a name lex token into a name parse node.
|
|
4934
5145
|
*/
|
|
4935
5146
|
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
_proto.parseName = function parseName() {
|
|
4940
|
-
var token = this.expectToken(TokenKind.NAME);
|
|
4941
|
-
return {
|
|
5147
|
+
parseName() {
|
|
5148
|
+
const token = this.expectToken(TokenKind.NAME);
|
|
5149
|
+
return this.node(token, {
|
|
4942
5150
|
kind: Kind.NAME,
|
|
4943
5151
|
value: token.value,
|
|
4944
|
-
|
|
4945
|
-
};
|
|
5152
|
+
});
|
|
4946
5153
|
} // Implements the parsing rules in the Document section.
|
|
4947
5154
|
|
|
4948
5155
|
/**
|
|
4949
5156
|
* Document : Definition+
|
|
4950
5157
|
*/
|
|
4951
|
-
;
|
|
4952
5158
|
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
return {
|
|
5159
|
+
parseDocument() {
|
|
5160
|
+
return this.node(this._lexer.token, {
|
|
4956
5161
|
kind: Kind.DOCUMENT,
|
|
4957
|
-
definitions: this.many(
|
|
4958
|
-
|
|
4959
|
-
|
|
5162
|
+
definitions: this.many(
|
|
5163
|
+
TokenKind.SOF,
|
|
5164
|
+
this.parseDefinition,
|
|
5165
|
+
TokenKind.EOF,
|
|
5166
|
+
),
|
|
5167
|
+
});
|
|
4960
5168
|
}
|
|
4961
5169
|
/**
|
|
4962
5170
|
* Definition :
|
|
@@ -4967,40 +5175,81 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4967
5175
|
* ExecutableDefinition :
|
|
4968
5176
|
* - OperationDefinition
|
|
4969
5177
|
* - FragmentDefinition
|
|
5178
|
+
*
|
|
5179
|
+
* TypeSystemDefinition :
|
|
5180
|
+
* - SchemaDefinition
|
|
5181
|
+
* - TypeDefinition
|
|
5182
|
+
* - DirectiveDefinition
|
|
5183
|
+
*
|
|
5184
|
+
* TypeDefinition :
|
|
5185
|
+
* - ScalarTypeDefinition
|
|
5186
|
+
* - ObjectTypeDefinition
|
|
5187
|
+
* - InterfaceTypeDefinition
|
|
5188
|
+
* - UnionTypeDefinition
|
|
5189
|
+
* - EnumTypeDefinition
|
|
5190
|
+
* - InputObjectTypeDefinition
|
|
4970
5191
|
*/
|
|
4971
|
-
;
|
|
4972
5192
|
|
|
4973
|
-
|
|
4974
|
-
if (this.peek(TokenKind.
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
case 'mutation':
|
|
4978
|
-
case 'subscription':
|
|
4979
|
-
return this.parseOperationDefinition();
|
|
5193
|
+
parseDefinition() {
|
|
5194
|
+
if (this.peek(TokenKind.BRACE_L)) {
|
|
5195
|
+
return this.parseOperationDefinition();
|
|
5196
|
+
} // Many definitions begin with a description and require a lookahead.
|
|
4980
5197
|
|
|
4981
|
-
|
|
4982
|
-
|
|
5198
|
+
const hasDescription = this.peekDescription();
|
|
5199
|
+
const keywordToken = hasDescription
|
|
5200
|
+
? this._lexer.lookahead()
|
|
5201
|
+
: this._lexer.token;
|
|
4983
5202
|
|
|
5203
|
+
if (keywordToken.kind === TokenKind.NAME) {
|
|
5204
|
+
switch (keywordToken.value) {
|
|
4984
5205
|
case 'schema':
|
|
5206
|
+
return this.parseSchemaDefinition();
|
|
5207
|
+
|
|
4985
5208
|
case 'scalar':
|
|
5209
|
+
return this.parseScalarTypeDefinition();
|
|
5210
|
+
|
|
4986
5211
|
case 'type':
|
|
5212
|
+
return this.parseObjectTypeDefinition();
|
|
5213
|
+
|
|
4987
5214
|
case 'interface':
|
|
5215
|
+
return this.parseInterfaceTypeDefinition();
|
|
5216
|
+
|
|
4988
5217
|
case 'union':
|
|
5218
|
+
return this.parseUnionTypeDefinition();
|
|
5219
|
+
|
|
4989
5220
|
case 'enum':
|
|
5221
|
+
return this.parseEnumTypeDefinition();
|
|
5222
|
+
|
|
4990
5223
|
case 'input':
|
|
5224
|
+
return this.parseInputObjectTypeDefinition();
|
|
5225
|
+
|
|
4991
5226
|
case 'directive':
|
|
4992
|
-
return this.
|
|
5227
|
+
return this.parseDirectiveDefinition();
|
|
5228
|
+
}
|
|
5229
|
+
|
|
5230
|
+
if (hasDescription) {
|
|
5231
|
+
throw syntaxError(
|
|
5232
|
+
this._lexer.source,
|
|
5233
|
+
this._lexer.token.start,
|
|
5234
|
+
'Unexpected description, descriptions are supported only on type definitions.',
|
|
5235
|
+
);
|
|
5236
|
+
}
|
|
5237
|
+
|
|
5238
|
+
switch (keywordToken.value) {
|
|
5239
|
+
case 'query':
|
|
5240
|
+
case 'mutation':
|
|
5241
|
+
case 'subscription':
|
|
5242
|
+
return this.parseOperationDefinition();
|
|
5243
|
+
|
|
5244
|
+
case 'fragment':
|
|
5245
|
+
return this.parseFragmentDefinition();
|
|
4993
5246
|
|
|
4994
5247
|
case 'extend':
|
|
4995
5248
|
return this.parseTypeSystemExtension();
|
|
4996
5249
|
}
|
|
4997
|
-
} else if (this.peek(TokenKind.BRACE_L)) {
|
|
4998
|
-
return this.parseOperationDefinition();
|
|
4999
|
-
} else if (this.peekDescription()) {
|
|
5000
|
-
return this.parseTypeSystemDefinition();
|
|
5001
5250
|
}
|
|
5002
5251
|
|
|
5003
|
-
throw this.unexpected();
|
|
5252
|
+
throw this.unexpected(keywordToken);
|
|
5004
5253
|
} // Implements the parsing rules in the Operations section.
|
|
5005
5254
|
|
|
5006
5255
|
/**
|
|
@@ -5008,57 +5257,53 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5008
5257
|
* - SelectionSet
|
|
5009
5258
|
* - OperationType Name? VariableDefinitions? Directives? SelectionSet
|
|
5010
5259
|
*/
|
|
5011
|
-
;
|
|
5012
5260
|
|
|
5013
|
-
|
|
5014
|
-
|
|
5261
|
+
parseOperationDefinition() {
|
|
5262
|
+
const start = this._lexer.token;
|
|
5015
5263
|
|
|
5016
5264
|
if (this.peek(TokenKind.BRACE_L)) {
|
|
5017
|
-
return {
|
|
5265
|
+
return this.node(start, {
|
|
5018
5266
|
kind: Kind.OPERATION_DEFINITION,
|
|
5019
|
-
operation:
|
|
5267
|
+
operation: OperationTypeNode.QUERY,
|
|
5020
5268
|
name: undefined,
|
|
5021
5269
|
variableDefinitions: [],
|
|
5022
5270
|
directives: [],
|
|
5023
5271
|
selectionSet: this.parseSelectionSet(),
|
|
5024
|
-
|
|
5025
|
-
};
|
|
5272
|
+
});
|
|
5026
5273
|
}
|
|
5027
5274
|
|
|
5028
|
-
|
|
5029
|
-
|
|
5275
|
+
const operation = this.parseOperationType();
|
|
5276
|
+
let name;
|
|
5030
5277
|
|
|
5031
5278
|
if (this.peek(TokenKind.NAME)) {
|
|
5032
5279
|
name = this.parseName();
|
|
5033
5280
|
}
|
|
5034
5281
|
|
|
5035
|
-
return {
|
|
5282
|
+
return this.node(start, {
|
|
5036
5283
|
kind: Kind.OPERATION_DEFINITION,
|
|
5037
|
-
operation
|
|
5038
|
-
name
|
|
5284
|
+
operation,
|
|
5285
|
+
name,
|
|
5039
5286
|
variableDefinitions: this.parseVariableDefinitions(),
|
|
5040
5287
|
directives: this.parseDirectives(false),
|
|
5041
5288
|
selectionSet: this.parseSelectionSet(),
|
|
5042
|
-
|
|
5043
|
-
};
|
|
5289
|
+
});
|
|
5044
5290
|
}
|
|
5045
5291
|
/**
|
|
5046
5292
|
* OperationType : one of query mutation subscription
|
|
5047
5293
|
*/
|
|
5048
|
-
;
|
|
5049
5294
|
|
|
5050
|
-
|
|
5051
|
-
|
|
5295
|
+
parseOperationType() {
|
|
5296
|
+
const operationToken = this.expectToken(TokenKind.NAME);
|
|
5052
5297
|
|
|
5053
5298
|
switch (operationToken.value) {
|
|
5054
5299
|
case 'query':
|
|
5055
|
-
return
|
|
5300
|
+
return OperationTypeNode.QUERY;
|
|
5056
5301
|
|
|
5057
5302
|
case 'mutation':
|
|
5058
|
-
return
|
|
5303
|
+
return OperationTypeNode.MUTATION;
|
|
5059
5304
|
|
|
5060
5305
|
case 'subscription':
|
|
5061
|
-
return
|
|
5306
|
+
return OperationTypeNode.SUBSCRIPTION;
|
|
5062
5307
|
}
|
|
5063
5308
|
|
|
5064
5309
|
throw this.unexpected(operationToken);
|
|
@@ -5066,53 +5311,56 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5066
5311
|
/**
|
|
5067
5312
|
* VariableDefinitions : ( VariableDefinition+ )
|
|
5068
5313
|
*/
|
|
5069
|
-
;
|
|
5070
5314
|
|
|
5071
|
-
|
|
5072
|
-
return this.optionalMany(
|
|
5315
|
+
parseVariableDefinitions() {
|
|
5316
|
+
return this.optionalMany(
|
|
5317
|
+
TokenKind.PAREN_L,
|
|
5318
|
+
this.parseVariableDefinition,
|
|
5319
|
+
TokenKind.PAREN_R,
|
|
5320
|
+
);
|
|
5073
5321
|
}
|
|
5074
5322
|
/**
|
|
5075
5323
|
* VariableDefinition : Variable : Type DefaultValue? Directives[Const]?
|
|
5076
5324
|
*/
|
|
5077
|
-
;
|
|
5078
5325
|
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
return {
|
|
5326
|
+
parseVariableDefinition() {
|
|
5327
|
+
return this.node(this._lexer.token, {
|
|
5082
5328
|
kind: Kind.VARIABLE_DEFINITION,
|
|
5083
5329
|
variable: this.parseVariable(),
|
|
5084
5330
|
type: (this.expectToken(TokenKind.COLON), this.parseTypeReference()),
|
|
5085
|
-
defaultValue: this.expectOptionalToken(TokenKind.EQUALS)
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5331
|
+
defaultValue: this.expectOptionalToken(TokenKind.EQUALS)
|
|
5332
|
+
? this.parseConstValueLiteral()
|
|
5333
|
+
: undefined,
|
|
5334
|
+
directives: this.parseConstDirectives(),
|
|
5335
|
+
});
|
|
5089
5336
|
}
|
|
5090
5337
|
/**
|
|
5091
5338
|
* Variable : $ Name
|
|
5092
5339
|
*/
|
|
5093
|
-
;
|
|
5094
5340
|
|
|
5095
|
-
|
|
5096
|
-
|
|
5341
|
+
parseVariable() {
|
|
5342
|
+
const start = this._lexer.token;
|
|
5097
5343
|
this.expectToken(TokenKind.DOLLAR);
|
|
5098
|
-
return {
|
|
5344
|
+
return this.node(start, {
|
|
5099
5345
|
kind: Kind.VARIABLE,
|
|
5100
5346
|
name: this.parseName(),
|
|
5101
|
-
|
|
5102
|
-
};
|
|
5347
|
+
});
|
|
5103
5348
|
}
|
|
5104
5349
|
/**
|
|
5350
|
+
* ```
|
|
5105
5351
|
* SelectionSet : { Selection+ }
|
|
5352
|
+
* ```
|
|
5106
5353
|
*/
|
|
5107
|
-
;
|
|
5108
5354
|
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
return {
|
|
5355
|
+
parseSelectionSet() {
|
|
5356
|
+
return this.node(this._lexer.token, {
|
|
5112
5357
|
kind: Kind.SELECTION_SET,
|
|
5113
|
-
selections: this.many(
|
|
5114
|
-
|
|
5115
|
-
|
|
5358
|
+
selections: this.many(
|
|
5359
|
+
TokenKind.BRACE_L,
|
|
5360
|
+
this.parseSelection,
|
|
5361
|
+
TokenKind.BRACE_R,
|
|
5362
|
+
),
|
|
5363
|
+
});
|
|
5116
5364
|
}
|
|
5117
5365
|
/**
|
|
5118
5366
|
* Selection :
|
|
@@ -5120,23 +5368,23 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5120
5368
|
* - FragmentSpread
|
|
5121
5369
|
* - InlineFragment
|
|
5122
5370
|
*/
|
|
5123
|
-
;
|
|
5124
5371
|
|
|
5125
|
-
|
|
5126
|
-
return this.peek(TokenKind.SPREAD)
|
|
5372
|
+
parseSelection() {
|
|
5373
|
+
return this.peek(TokenKind.SPREAD)
|
|
5374
|
+
? this.parseFragment()
|
|
5375
|
+
: this.parseField();
|
|
5127
5376
|
}
|
|
5128
5377
|
/**
|
|
5129
5378
|
* Field : Alias? Name Arguments? Directives? SelectionSet?
|
|
5130
5379
|
*
|
|
5131
5380
|
* Alias : Name :
|
|
5132
5381
|
*/
|
|
5133
|
-
;
|
|
5134
5382
|
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5383
|
+
parseField() {
|
|
5384
|
+
const start = this._lexer.token;
|
|
5385
|
+
const nameOrAlias = this.parseName();
|
|
5386
|
+
let alias;
|
|
5387
|
+
let name;
|
|
5140
5388
|
|
|
5141
5389
|
if (this.expectOptionalToken(TokenKind.COLON)) {
|
|
5142
5390
|
alias = nameOrAlias;
|
|
@@ -5145,50 +5393,42 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5145
5393
|
name = nameOrAlias;
|
|
5146
5394
|
}
|
|
5147
5395
|
|
|
5148
|
-
return {
|
|
5396
|
+
return this.node(start, {
|
|
5149
5397
|
kind: Kind.FIELD,
|
|
5150
|
-
alias
|
|
5151
|
-
name
|
|
5398
|
+
alias,
|
|
5399
|
+
name,
|
|
5152
5400
|
arguments: this.parseArguments(false),
|
|
5153
5401
|
directives: this.parseDirectives(false),
|
|
5154
|
-
selectionSet: this.peek(TokenKind.BRACE_L)
|
|
5155
|
-
|
|
5156
|
-
|
|
5402
|
+
selectionSet: this.peek(TokenKind.BRACE_L)
|
|
5403
|
+
? this.parseSelectionSet()
|
|
5404
|
+
: undefined,
|
|
5405
|
+
});
|
|
5157
5406
|
}
|
|
5158
5407
|
/**
|
|
5159
5408
|
* Arguments[Const] : ( Argument[?Const]+ )
|
|
5160
5409
|
*/
|
|
5161
|
-
;
|
|
5162
5410
|
|
|
5163
|
-
|
|
5164
|
-
|
|
5411
|
+
parseArguments(isConst) {
|
|
5412
|
+
const item = isConst ? this.parseConstArgument : this.parseArgument;
|
|
5165
5413
|
return this.optionalMany(TokenKind.PAREN_L, item, TokenKind.PAREN_R);
|
|
5166
5414
|
}
|
|
5167
5415
|
/**
|
|
5168
5416
|
* Argument[Const] : Name : Value[?Const]
|
|
5169
5417
|
*/
|
|
5170
|
-
;
|
|
5171
5418
|
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5419
|
+
parseArgument(isConst = false) {
|
|
5420
|
+
const start = this._lexer.token;
|
|
5421
|
+
const name = this.parseName();
|
|
5175
5422
|
this.expectToken(TokenKind.COLON);
|
|
5176
|
-
return {
|
|
5423
|
+
return this.node(start, {
|
|
5177
5424
|
kind: Kind.ARGUMENT,
|
|
5178
|
-
name
|
|
5179
|
-
value: this.parseValueLiteral(
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
};
|
|
5425
|
+
name,
|
|
5426
|
+
value: this.parseValueLiteral(isConst),
|
|
5427
|
+
});
|
|
5428
|
+
}
|
|
5183
5429
|
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
return {
|
|
5187
|
-
kind: Kind.ARGUMENT,
|
|
5188
|
-
name: this.parseName(),
|
|
5189
|
-
value: (this.expectToken(TokenKind.COLON), this.parseValueLiteral(true)),
|
|
5190
|
-
loc: this.loc(start)
|
|
5191
|
-
};
|
|
5430
|
+
parseConstArgument() {
|
|
5431
|
+
return this.parseArgument(true);
|
|
5192
5432
|
} // Implements the parsing rules in the Fragments section.
|
|
5193
5433
|
|
|
5194
5434
|
/**
|
|
@@ -5198,29 +5438,26 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5198
5438
|
*
|
|
5199
5439
|
* InlineFragment : ... TypeCondition? Directives? SelectionSet
|
|
5200
5440
|
*/
|
|
5201
|
-
;
|
|
5202
5441
|
|
|
5203
|
-
|
|
5204
|
-
|
|
5442
|
+
parseFragment() {
|
|
5443
|
+
const start = this._lexer.token;
|
|
5205
5444
|
this.expectToken(TokenKind.SPREAD);
|
|
5206
|
-
|
|
5445
|
+
const hasTypeCondition = this.expectOptionalKeyword('on');
|
|
5207
5446
|
|
|
5208
5447
|
if (!hasTypeCondition && this.peek(TokenKind.NAME)) {
|
|
5209
|
-
return {
|
|
5448
|
+
return this.node(start, {
|
|
5210
5449
|
kind: Kind.FRAGMENT_SPREAD,
|
|
5211
5450
|
name: this.parseFragmentName(),
|
|
5212
5451
|
directives: this.parseDirectives(false),
|
|
5213
|
-
|
|
5214
|
-
};
|
|
5452
|
+
});
|
|
5215
5453
|
}
|
|
5216
5454
|
|
|
5217
|
-
return {
|
|
5455
|
+
return this.node(start, {
|
|
5218
5456
|
kind: Kind.INLINE_FRAGMENT,
|
|
5219
5457
|
typeCondition: hasTypeCondition ? this.parseNamedType() : undefined,
|
|
5220
5458
|
directives: this.parseDirectives(false),
|
|
5221
5459
|
selectionSet: this.parseSelectionSet(),
|
|
5222
|
-
|
|
5223
|
-
};
|
|
5460
|
+
});
|
|
5224
5461
|
}
|
|
5225
5462
|
/**
|
|
5226
5463
|
* FragmentDefinition :
|
|
@@ -5228,43 +5465,43 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5228
5465
|
*
|
|
5229
5466
|
* TypeCondition : NamedType
|
|
5230
5467
|
*/
|
|
5231
|
-
;
|
|
5232
5468
|
|
|
5233
|
-
|
|
5469
|
+
parseFragmentDefinition() {
|
|
5234
5470
|
var _this$_options;
|
|
5235
5471
|
|
|
5236
|
-
|
|
5237
|
-
this.expectKeyword('fragment'); //
|
|
5472
|
+
const start = this._lexer.token;
|
|
5473
|
+
this.expectKeyword('fragment'); // Legacy support for defining variables within fragments changes
|
|
5238
5474
|
// the grammar of FragmentDefinition:
|
|
5239
5475
|
// - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
|
|
5240
5476
|
|
|
5241
|
-
if (
|
|
5242
|
-
|
|
5477
|
+
if (
|
|
5478
|
+
((_this$_options = this._options) === null || _this$_options === void 0
|
|
5479
|
+
? void 0
|
|
5480
|
+
: _this$_options.allowLegacyFragmentVariables) === true
|
|
5481
|
+
) {
|
|
5482
|
+
return this.node(start, {
|
|
5243
5483
|
kind: Kind.FRAGMENT_DEFINITION,
|
|
5244
5484
|
name: this.parseFragmentName(),
|
|
5245
5485
|
variableDefinitions: this.parseVariableDefinitions(),
|
|
5246
5486
|
typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
|
|
5247
5487
|
directives: this.parseDirectives(false),
|
|
5248
5488
|
selectionSet: this.parseSelectionSet(),
|
|
5249
|
-
|
|
5250
|
-
};
|
|
5489
|
+
});
|
|
5251
5490
|
}
|
|
5252
5491
|
|
|
5253
|
-
return {
|
|
5492
|
+
return this.node(start, {
|
|
5254
5493
|
kind: Kind.FRAGMENT_DEFINITION,
|
|
5255
5494
|
name: this.parseFragmentName(),
|
|
5256
5495
|
typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
|
|
5257
5496
|
directives: this.parseDirectives(false),
|
|
5258
5497
|
selectionSet: this.parseSelectionSet(),
|
|
5259
|
-
|
|
5260
|
-
};
|
|
5498
|
+
});
|
|
5261
5499
|
}
|
|
5262
5500
|
/**
|
|
5263
5501
|
* FragmentName : Name but not `on`
|
|
5264
5502
|
*/
|
|
5265
|
-
;
|
|
5266
5503
|
|
|
5267
|
-
|
|
5504
|
+
parseFragmentName() {
|
|
5268
5505
|
if (this._lexer.token.value === 'on') {
|
|
5269
5506
|
throw this.unexpected();
|
|
5270
5507
|
}
|
|
@@ -5290,10 +5527,9 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5290
5527
|
*
|
|
5291
5528
|
* EnumValue : Name but not `true`, `false` or `null`
|
|
5292
5529
|
*/
|
|
5293
|
-
;
|
|
5294
5530
|
|
|
5295
|
-
|
|
5296
|
-
|
|
5531
|
+
parseValueLiteral(isConst) {
|
|
5532
|
+
const token = this._lexer.token;
|
|
5297
5533
|
|
|
5298
5534
|
switch (token.kind) {
|
|
5299
5535
|
case TokenKind.BRACKET_L:
|
|
@@ -5305,20 +5541,18 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5305
5541
|
case TokenKind.INT:
|
|
5306
5542
|
this._lexer.advance();
|
|
5307
5543
|
|
|
5308
|
-
return {
|
|
5544
|
+
return this.node(token, {
|
|
5309
5545
|
kind: Kind.INT,
|
|
5310
5546
|
value: token.value,
|
|
5311
|
-
|
|
5312
|
-
};
|
|
5547
|
+
});
|
|
5313
5548
|
|
|
5314
5549
|
case TokenKind.FLOAT:
|
|
5315
5550
|
this._lexer.advance();
|
|
5316
5551
|
|
|
5317
|
-
return {
|
|
5552
|
+
return this.node(token, {
|
|
5318
5553
|
kind: Kind.FLOAT,
|
|
5319
5554
|
value: token.value,
|
|
5320
|
-
|
|
5321
|
-
};
|
|
5555
|
+
});
|
|
5322
5556
|
|
|
5323
5557
|
case TokenKind.STRING:
|
|
5324
5558
|
case TokenKind.BLOCK_STRING:
|
|
@@ -5329,124 +5563,118 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5329
5563
|
|
|
5330
5564
|
switch (token.value) {
|
|
5331
5565
|
case 'true':
|
|
5332
|
-
return {
|
|
5566
|
+
return this.node(token, {
|
|
5333
5567
|
kind: Kind.BOOLEAN,
|
|
5334
5568
|
value: true,
|
|
5335
|
-
|
|
5336
|
-
};
|
|
5569
|
+
});
|
|
5337
5570
|
|
|
5338
5571
|
case 'false':
|
|
5339
|
-
return {
|
|
5572
|
+
return this.node(token, {
|
|
5340
5573
|
kind: Kind.BOOLEAN,
|
|
5341
5574
|
value: false,
|
|
5342
|
-
|
|
5343
|
-
};
|
|
5575
|
+
});
|
|
5344
5576
|
|
|
5345
5577
|
case 'null':
|
|
5346
|
-
return {
|
|
5578
|
+
return this.node(token, {
|
|
5347
5579
|
kind: Kind.NULL,
|
|
5348
|
-
|
|
5349
|
-
};
|
|
5580
|
+
});
|
|
5350
5581
|
|
|
5351
5582
|
default:
|
|
5352
|
-
return {
|
|
5583
|
+
return this.node(token, {
|
|
5353
5584
|
kind: Kind.ENUM,
|
|
5354
5585
|
value: token.value,
|
|
5355
|
-
|
|
5356
|
-
};
|
|
5586
|
+
});
|
|
5357
5587
|
}
|
|
5358
5588
|
|
|
5359
5589
|
case TokenKind.DOLLAR:
|
|
5360
|
-
if (
|
|
5361
|
-
|
|
5590
|
+
if (isConst) {
|
|
5591
|
+
this.expectToken(TokenKind.DOLLAR);
|
|
5592
|
+
|
|
5593
|
+
if (this._lexer.token.kind === TokenKind.NAME) {
|
|
5594
|
+
const varName = this._lexer.token.value;
|
|
5595
|
+
throw syntaxError(
|
|
5596
|
+
this._lexer.source,
|
|
5597
|
+
token.start,
|
|
5598
|
+
`Unexpected variable "$${varName}" in constant value.`,
|
|
5599
|
+
);
|
|
5600
|
+
} else {
|
|
5601
|
+
throw this.unexpected(token);
|
|
5602
|
+
}
|
|
5362
5603
|
}
|
|
5363
5604
|
|
|
5364
|
-
|
|
5605
|
+
return this.parseVariable();
|
|
5606
|
+
|
|
5607
|
+
default:
|
|
5608
|
+
throw this.unexpected();
|
|
5365
5609
|
}
|
|
5610
|
+
}
|
|
5366
5611
|
|
|
5367
|
-
|
|
5368
|
-
|
|
5612
|
+
parseConstValueLiteral() {
|
|
5613
|
+
return this.parseValueLiteral(true);
|
|
5614
|
+
}
|
|
5369
5615
|
|
|
5370
|
-
|
|
5371
|
-
|
|
5616
|
+
parseStringLiteral() {
|
|
5617
|
+
const token = this._lexer.token;
|
|
5372
5618
|
|
|
5373
5619
|
this._lexer.advance();
|
|
5374
5620
|
|
|
5375
|
-
return {
|
|
5621
|
+
return this.node(token, {
|
|
5376
5622
|
kind: Kind.STRING,
|
|
5377
5623
|
value: token.value,
|
|
5378
5624
|
block: token.kind === TokenKind.BLOCK_STRING,
|
|
5379
|
-
|
|
5380
|
-
};
|
|
5625
|
+
});
|
|
5381
5626
|
}
|
|
5382
5627
|
/**
|
|
5383
5628
|
* ListValue[Const] :
|
|
5384
5629
|
* - [ ]
|
|
5385
5630
|
* - [ Value[?Const]+ ]
|
|
5386
5631
|
*/
|
|
5387
|
-
;
|
|
5388
|
-
|
|
5389
|
-
_proto.parseList = function parseList(isConst) {
|
|
5390
|
-
var _this = this;
|
|
5391
5632
|
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
var item = function item() {
|
|
5395
|
-
return _this.parseValueLiteral(isConst);
|
|
5396
|
-
};
|
|
5633
|
+
parseList(isConst) {
|
|
5634
|
+
const item = () => this.parseValueLiteral(isConst);
|
|
5397
5635
|
|
|
5398
|
-
return {
|
|
5636
|
+
return this.node(this._lexer.token, {
|
|
5399
5637
|
kind: Kind.LIST,
|
|
5400
5638
|
values: this.any(TokenKind.BRACKET_L, item, TokenKind.BRACKET_R),
|
|
5401
|
-
|
|
5402
|
-
};
|
|
5639
|
+
});
|
|
5403
5640
|
}
|
|
5404
5641
|
/**
|
|
5642
|
+
* ```
|
|
5405
5643
|
* ObjectValue[Const] :
|
|
5406
5644
|
* - { }
|
|
5407
5645
|
* - { ObjectField[?Const]+ }
|
|
5646
|
+
* ```
|
|
5408
5647
|
*/
|
|
5409
|
-
;
|
|
5410
|
-
|
|
5411
|
-
_proto.parseObject = function parseObject(isConst) {
|
|
5412
|
-
var _this2 = this;
|
|
5413
5648
|
|
|
5414
|
-
|
|
5649
|
+
parseObject(isConst) {
|
|
5650
|
+
const item = () => this.parseObjectField(isConst);
|
|
5415
5651
|
|
|
5416
|
-
|
|
5417
|
-
return _this2.parseObjectField(isConst);
|
|
5418
|
-
};
|
|
5419
|
-
|
|
5420
|
-
return {
|
|
5652
|
+
return this.node(this._lexer.token, {
|
|
5421
5653
|
kind: Kind.OBJECT,
|
|
5422
5654
|
fields: this.any(TokenKind.BRACE_L, item, TokenKind.BRACE_R),
|
|
5423
|
-
|
|
5424
|
-
};
|
|
5655
|
+
});
|
|
5425
5656
|
}
|
|
5426
5657
|
/**
|
|
5427
5658
|
* ObjectField[Const] : Name : Value[?Const]
|
|
5428
5659
|
*/
|
|
5429
|
-
;
|
|
5430
5660
|
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5661
|
+
parseObjectField(isConst) {
|
|
5662
|
+
const start = this._lexer.token;
|
|
5663
|
+
const name = this.parseName();
|
|
5434
5664
|
this.expectToken(TokenKind.COLON);
|
|
5435
|
-
return {
|
|
5665
|
+
return this.node(start, {
|
|
5436
5666
|
kind: Kind.OBJECT_FIELD,
|
|
5437
|
-
name
|
|
5667
|
+
name,
|
|
5438
5668
|
value: this.parseValueLiteral(isConst),
|
|
5439
|
-
|
|
5440
|
-
};
|
|
5669
|
+
});
|
|
5441
5670
|
} // Implements the parsing rules in the Directives section.
|
|
5442
5671
|
|
|
5443
5672
|
/**
|
|
5444
5673
|
* Directives[Const] : Directive[?Const]+
|
|
5445
5674
|
*/
|
|
5446
|
-
;
|
|
5447
5675
|
|
|
5448
|
-
|
|
5449
|
-
|
|
5676
|
+
parseDirectives(isConst) {
|
|
5677
|
+
const directives = [];
|
|
5450
5678
|
|
|
5451
5679
|
while (this.peek(TokenKind.AT)) {
|
|
5452
5680
|
directives.push(this.parseDirective(isConst));
|
|
@@ -5454,20 +5682,24 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5454
5682
|
|
|
5455
5683
|
return directives;
|
|
5456
5684
|
}
|
|
5685
|
+
|
|
5686
|
+
parseConstDirectives() {
|
|
5687
|
+
return this.parseDirectives(true);
|
|
5688
|
+
}
|
|
5457
5689
|
/**
|
|
5690
|
+
* ```
|
|
5458
5691
|
* Directive[Const] : @ Name Arguments[?Const]?
|
|
5692
|
+
* ```
|
|
5459
5693
|
*/
|
|
5460
|
-
;
|
|
5461
5694
|
|
|
5462
|
-
|
|
5463
|
-
|
|
5695
|
+
parseDirective(isConst) {
|
|
5696
|
+
const start = this._lexer.token;
|
|
5464
5697
|
this.expectToken(TokenKind.AT);
|
|
5465
|
-
return {
|
|
5698
|
+
return this.node(start, {
|
|
5466
5699
|
kind: Kind.DIRECTIVE,
|
|
5467
5700
|
name: this.parseName(),
|
|
5468
5701
|
arguments: this.parseArguments(isConst),
|
|
5469
|
-
|
|
5470
|
-
};
|
|
5702
|
+
});
|
|
5471
5703
|
} // Implements the parsing rules in the Types section.
|
|
5472
5704
|
|
|
5473
5705
|
/**
|
|
@@ -5476,30 +5708,27 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5476
5708
|
* - ListType
|
|
5477
5709
|
* - NonNullType
|
|
5478
5710
|
*/
|
|
5479
|
-
;
|
|
5480
5711
|
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5712
|
+
parseTypeReference() {
|
|
5713
|
+
const start = this._lexer.token;
|
|
5714
|
+
let type;
|
|
5484
5715
|
|
|
5485
5716
|
if (this.expectOptionalToken(TokenKind.BRACKET_L)) {
|
|
5486
|
-
|
|
5717
|
+
const innerType = this.parseTypeReference();
|
|
5487
5718
|
this.expectToken(TokenKind.BRACKET_R);
|
|
5488
|
-
type = {
|
|
5719
|
+
type = this.node(start, {
|
|
5489
5720
|
kind: Kind.LIST_TYPE,
|
|
5490
|
-
type:
|
|
5491
|
-
|
|
5492
|
-
};
|
|
5721
|
+
type: innerType,
|
|
5722
|
+
});
|
|
5493
5723
|
} else {
|
|
5494
5724
|
type = this.parseNamedType();
|
|
5495
5725
|
}
|
|
5496
5726
|
|
|
5497
5727
|
if (this.expectOptionalToken(TokenKind.BANG)) {
|
|
5498
|
-
return {
|
|
5728
|
+
return this.node(start, {
|
|
5499
5729
|
kind: Kind.NON_NULL_TYPE,
|
|
5500
|
-
type
|
|
5501
|
-
|
|
5502
|
-
};
|
|
5730
|
+
type,
|
|
5731
|
+
});
|
|
5503
5732
|
}
|
|
5504
5733
|
|
|
5505
5734
|
return type;
|
|
@@ -5507,404 +5736,343 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5507
5736
|
/**
|
|
5508
5737
|
* NamedType : Name
|
|
5509
5738
|
*/
|
|
5510
|
-
;
|
|
5511
5739
|
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
return {
|
|
5740
|
+
parseNamedType() {
|
|
5741
|
+
return this.node(this._lexer.token, {
|
|
5515
5742
|
kind: Kind.NAMED_TYPE,
|
|
5516
5743
|
name: this.parseName(),
|
|
5517
|
-
|
|
5518
|
-
};
|
|
5744
|
+
});
|
|
5519
5745
|
} // Implements the parsing rules in the Type Definition section.
|
|
5520
5746
|
|
|
5521
|
-
|
|
5522
|
-
* TypeSystemDefinition :
|
|
5523
|
-
* - SchemaDefinition
|
|
5524
|
-
* - TypeDefinition
|
|
5525
|
-
* - DirectiveDefinition
|
|
5526
|
-
*
|
|
5527
|
-
* TypeDefinition :
|
|
5528
|
-
* - ScalarTypeDefinition
|
|
5529
|
-
* - ObjectTypeDefinition
|
|
5530
|
-
* - InterfaceTypeDefinition
|
|
5531
|
-
* - UnionTypeDefinition
|
|
5532
|
-
* - EnumTypeDefinition
|
|
5533
|
-
* - InputObjectTypeDefinition
|
|
5534
|
-
*/
|
|
5535
|
-
;
|
|
5536
|
-
|
|
5537
|
-
_proto.parseTypeSystemDefinition = function parseTypeSystemDefinition() {
|
|
5538
|
-
// Many definitions begin with a description and require a lookahead.
|
|
5539
|
-
var keywordToken = this.peekDescription() ? this._lexer.lookahead() : this._lexer.token;
|
|
5540
|
-
|
|
5541
|
-
if (keywordToken.kind === TokenKind.NAME) {
|
|
5542
|
-
switch (keywordToken.value) {
|
|
5543
|
-
case 'schema':
|
|
5544
|
-
return this.parseSchemaDefinition();
|
|
5545
|
-
|
|
5546
|
-
case 'scalar':
|
|
5547
|
-
return this.parseScalarTypeDefinition();
|
|
5548
|
-
|
|
5549
|
-
case 'type':
|
|
5550
|
-
return this.parseObjectTypeDefinition();
|
|
5551
|
-
|
|
5552
|
-
case 'interface':
|
|
5553
|
-
return this.parseInterfaceTypeDefinition();
|
|
5554
|
-
|
|
5555
|
-
case 'union':
|
|
5556
|
-
return this.parseUnionTypeDefinition();
|
|
5557
|
-
|
|
5558
|
-
case 'enum':
|
|
5559
|
-
return this.parseEnumTypeDefinition();
|
|
5560
|
-
|
|
5561
|
-
case 'input':
|
|
5562
|
-
return this.parseInputObjectTypeDefinition();
|
|
5563
|
-
|
|
5564
|
-
case 'directive':
|
|
5565
|
-
return this.parseDirectiveDefinition();
|
|
5566
|
-
}
|
|
5567
|
-
}
|
|
5568
|
-
|
|
5569
|
-
throw this.unexpected(keywordToken);
|
|
5570
|
-
};
|
|
5571
|
-
|
|
5572
|
-
_proto.peekDescription = function peekDescription() {
|
|
5747
|
+
peekDescription() {
|
|
5573
5748
|
return this.peek(TokenKind.STRING) || this.peek(TokenKind.BLOCK_STRING);
|
|
5574
5749
|
}
|
|
5575
5750
|
/**
|
|
5576
5751
|
* Description : StringValue
|
|
5577
5752
|
*/
|
|
5578
|
-
;
|
|
5579
5753
|
|
|
5580
|
-
|
|
5754
|
+
parseDescription() {
|
|
5581
5755
|
if (this.peekDescription()) {
|
|
5582
5756
|
return this.parseStringLiteral();
|
|
5583
5757
|
}
|
|
5584
5758
|
}
|
|
5585
5759
|
/**
|
|
5760
|
+
* ```
|
|
5586
5761
|
* SchemaDefinition : Description? schema Directives[Const]? { OperationTypeDefinition+ }
|
|
5762
|
+
* ```
|
|
5587
5763
|
*/
|
|
5588
|
-
;
|
|
5589
5764
|
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5765
|
+
parseSchemaDefinition() {
|
|
5766
|
+
const start = this._lexer.token;
|
|
5767
|
+
const description = this.parseDescription();
|
|
5593
5768
|
this.expectKeyword('schema');
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5769
|
+
const directives = this.parseConstDirectives();
|
|
5770
|
+
const operationTypes = this.many(
|
|
5771
|
+
TokenKind.BRACE_L,
|
|
5772
|
+
this.parseOperationTypeDefinition,
|
|
5773
|
+
TokenKind.BRACE_R,
|
|
5774
|
+
);
|
|
5775
|
+
return this.node(start, {
|
|
5597
5776
|
kind: Kind.SCHEMA_DEFINITION,
|
|
5598
|
-
description
|
|
5599
|
-
directives
|
|
5600
|
-
operationTypes
|
|
5601
|
-
|
|
5602
|
-
};
|
|
5777
|
+
description,
|
|
5778
|
+
directives,
|
|
5779
|
+
operationTypes,
|
|
5780
|
+
});
|
|
5603
5781
|
}
|
|
5604
5782
|
/**
|
|
5605
5783
|
* OperationTypeDefinition : OperationType : NamedType
|
|
5606
5784
|
*/
|
|
5607
|
-
;
|
|
5608
5785
|
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5786
|
+
parseOperationTypeDefinition() {
|
|
5787
|
+
const start = this._lexer.token;
|
|
5788
|
+
const operation = this.parseOperationType();
|
|
5612
5789
|
this.expectToken(TokenKind.COLON);
|
|
5613
|
-
|
|
5614
|
-
return {
|
|
5790
|
+
const type = this.parseNamedType();
|
|
5791
|
+
return this.node(start, {
|
|
5615
5792
|
kind: Kind.OPERATION_TYPE_DEFINITION,
|
|
5616
|
-
operation
|
|
5617
|
-
type
|
|
5618
|
-
|
|
5619
|
-
};
|
|
5793
|
+
operation,
|
|
5794
|
+
type,
|
|
5795
|
+
});
|
|
5620
5796
|
}
|
|
5621
5797
|
/**
|
|
5622
5798
|
* ScalarTypeDefinition : Description? scalar Name Directives[Const]?
|
|
5623
5799
|
*/
|
|
5624
|
-
;
|
|
5625
5800
|
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5801
|
+
parseScalarTypeDefinition() {
|
|
5802
|
+
const start = this._lexer.token;
|
|
5803
|
+
const description = this.parseDescription();
|
|
5629
5804
|
this.expectKeyword('scalar');
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
return {
|
|
5805
|
+
const name = this.parseName();
|
|
5806
|
+
const directives = this.parseConstDirectives();
|
|
5807
|
+
return this.node(start, {
|
|
5633
5808
|
kind: Kind.SCALAR_TYPE_DEFINITION,
|
|
5634
|
-
description
|
|
5635
|
-
name
|
|
5636
|
-
directives
|
|
5637
|
-
|
|
5638
|
-
};
|
|
5809
|
+
description,
|
|
5810
|
+
name,
|
|
5811
|
+
directives,
|
|
5812
|
+
});
|
|
5639
5813
|
}
|
|
5640
5814
|
/**
|
|
5641
5815
|
* ObjectTypeDefinition :
|
|
5642
5816
|
* Description?
|
|
5643
5817
|
* type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition?
|
|
5644
5818
|
*/
|
|
5645
|
-
;
|
|
5646
5819
|
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5820
|
+
parseObjectTypeDefinition() {
|
|
5821
|
+
const start = this._lexer.token;
|
|
5822
|
+
const description = this.parseDescription();
|
|
5650
5823
|
this.expectKeyword('type');
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
return {
|
|
5824
|
+
const name = this.parseName();
|
|
5825
|
+
const interfaces = this.parseImplementsInterfaces();
|
|
5826
|
+
const directives = this.parseConstDirectives();
|
|
5827
|
+
const fields = this.parseFieldsDefinition();
|
|
5828
|
+
return this.node(start, {
|
|
5656
5829
|
kind: Kind.OBJECT_TYPE_DEFINITION,
|
|
5657
|
-
description
|
|
5658
|
-
name
|
|
5659
|
-
interfaces
|
|
5660
|
-
directives
|
|
5661
|
-
fields
|
|
5662
|
-
|
|
5663
|
-
};
|
|
5830
|
+
description,
|
|
5831
|
+
name,
|
|
5832
|
+
interfaces,
|
|
5833
|
+
directives,
|
|
5834
|
+
fields,
|
|
5835
|
+
});
|
|
5664
5836
|
}
|
|
5665
5837
|
/**
|
|
5666
5838
|
* ImplementsInterfaces :
|
|
5667
5839
|
* - implements `&`? NamedType
|
|
5668
5840
|
* - ImplementsInterfaces & NamedType
|
|
5669
5841
|
*/
|
|
5670
|
-
;
|
|
5671
|
-
|
|
5672
|
-
_proto.parseImplementsInterfaces = function parseImplementsInterfaces() {
|
|
5673
|
-
var _this$_options2;
|
|
5674
|
-
|
|
5675
|
-
if (!this.expectOptionalKeyword('implements')) {
|
|
5676
|
-
return [];
|
|
5677
|
-
}
|
|
5678
|
-
|
|
5679
|
-
if (((_this$_options2 = this._options) === null || _this$_options2 === void 0 ? void 0 : _this$_options2.allowLegacySDLImplementsInterfaces) === true) {
|
|
5680
|
-
var types = []; // Optional leading ampersand
|
|
5681
|
-
|
|
5682
|
-
this.expectOptionalToken(TokenKind.AMP);
|
|
5683
|
-
|
|
5684
|
-
do {
|
|
5685
|
-
types.push(this.parseNamedType());
|
|
5686
|
-
} while (this.expectOptionalToken(TokenKind.AMP) || this.peek(TokenKind.NAME));
|
|
5687
5842
|
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5843
|
+
parseImplementsInterfaces() {
|
|
5844
|
+
return this.expectOptionalKeyword('implements')
|
|
5845
|
+
? this.delimitedMany(TokenKind.AMP, this.parseNamedType)
|
|
5846
|
+
: [];
|
|
5692
5847
|
}
|
|
5693
5848
|
/**
|
|
5849
|
+
* ```
|
|
5694
5850
|
* FieldsDefinition : { FieldDefinition+ }
|
|
5851
|
+
* ```
|
|
5695
5852
|
*/
|
|
5696
|
-
;
|
|
5697
|
-
|
|
5698
|
-
_proto.parseFieldsDefinition = function parseFieldsDefinition() {
|
|
5699
|
-
var _this$_options3;
|
|
5700
|
-
|
|
5701
|
-
// Legacy support for the SDL?
|
|
5702
|
-
if (((_this$_options3 = this._options) === null || _this$_options3 === void 0 ? void 0 : _this$_options3.allowLegacySDLEmptyFields) === true && this.peek(TokenKind.BRACE_L) && this._lexer.lookahead().kind === TokenKind.BRACE_R) {
|
|
5703
|
-
this._lexer.advance();
|
|
5704
|
-
|
|
5705
|
-
this._lexer.advance();
|
|
5706
|
-
|
|
5707
|
-
return [];
|
|
5708
|
-
}
|
|
5709
5853
|
|
|
5710
|
-
|
|
5854
|
+
parseFieldsDefinition() {
|
|
5855
|
+
return this.optionalMany(
|
|
5856
|
+
TokenKind.BRACE_L,
|
|
5857
|
+
this.parseFieldDefinition,
|
|
5858
|
+
TokenKind.BRACE_R,
|
|
5859
|
+
);
|
|
5711
5860
|
}
|
|
5712
5861
|
/**
|
|
5713
5862
|
* FieldDefinition :
|
|
5714
5863
|
* - Description? Name ArgumentsDefinition? : Type Directives[Const]?
|
|
5715
5864
|
*/
|
|
5716
|
-
;
|
|
5717
5865
|
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5866
|
+
parseFieldDefinition() {
|
|
5867
|
+
const start = this._lexer.token;
|
|
5868
|
+
const description = this.parseDescription();
|
|
5869
|
+
const name = this.parseName();
|
|
5870
|
+
const args = this.parseArgumentDefs();
|
|
5723
5871
|
this.expectToken(TokenKind.COLON);
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
return {
|
|
5872
|
+
const type = this.parseTypeReference();
|
|
5873
|
+
const directives = this.parseConstDirectives();
|
|
5874
|
+
return this.node(start, {
|
|
5727
5875
|
kind: Kind.FIELD_DEFINITION,
|
|
5728
|
-
description
|
|
5729
|
-
name
|
|
5876
|
+
description,
|
|
5877
|
+
name,
|
|
5730
5878
|
arguments: args,
|
|
5731
|
-
type
|
|
5732
|
-
directives
|
|
5733
|
-
|
|
5734
|
-
};
|
|
5879
|
+
type,
|
|
5880
|
+
directives,
|
|
5881
|
+
});
|
|
5735
5882
|
}
|
|
5736
5883
|
/**
|
|
5737
5884
|
* ArgumentsDefinition : ( InputValueDefinition+ )
|
|
5738
5885
|
*/
|
|
5739
|
-
;
|
|
5740
5886
|
|
|
5741
|
-
|
|
5742
|
-
return this.optionalMany(
|
|
5887
|
+
parseArgumentDefs() {
|
|
5888
|
+
return this.optionalMany(
|
|
5889
|
+
TokenKind.PAREN_L,
|
|
5890
|
+
this.parseInputValueDef,
|
|
5891
|
+
TokenKind.PAREN_R,
|
|
5892
|
+
);
|
|
5743
5893
|
}
|
|
5744
5894
|
/**
|
|
5745
5895
|
* InputValueDefinition :
|
|
5746
5896
|
* - Description? Name : Type DefaultValue? Directives[Const]?
|
|
5747
5897
|
*/
|
|
5748
|
-
;
|
|
5749
5898
|
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5899
|
+
parseInputValueDef() {
|
|
5900
|
+
const start = this._lexer.token;
|
|
5901
|
+
const description = this.parseDescription();
|
|
5902
|
+
const name = this.parseName();
|
|
5754
5903
|
this.expectToken(TokenKind.COLON);
|
|
5755
|
-
|
|
5756
|
-
|
|
5904
|
+
const type = this.parseTypeReference();
|
|
5905
|
+
let defaultValue;
|
|
5757
5906
|
|
|
5758
5907
|
if (this.expectOptionalToken(TokenKind.EQUALS)) {
|
|
5759
|
-
defaultValue = this.
|
|
5908
|
+
defaultValue = this.parseConstValueLiteral();
|
|
5760
5909
|
}
|
|
5761
5910
|
|
|
5762
|
-
|
|
5763
|
-
return {
|
|
5911
|
+
const directives = this.parseConstDirectives();
|
|
5912
|
+
return this.node(start, {
|
|
5764
5913
|
kind: Kind.INPUT_VALUE_DEFINITION,
|
|
5765
|
-
description
|
|
5766
|
-
name
|
|
5767
|
-
type
|
|
5768
|
-
defaultValue
|
|
5769
|
-
directives
|
|
5770
|
-
|
|
5771
|
-
};
|
|
5914
|
+
description,
|
|
5915
|
+
name,
|
|
5916
|
+
type,
|
|
5917
|
+
defaultValue,
|
|
5918
|
+
directives,
|
|
5919
|
+
});
|
|
5772
5920
|
}
|
|
5773
5921
|
/**
|
|
5774
5922
|
* InterfaceTypeDefinition :
|
|
5775
5923
|
* - Description? interface Name Directives[Const]? FieldsDefinition?
|
|
5776
5924
|
*/
|
|
5777
|
-
;
|
|
5778
5925
|
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5926
|
+
parseInterfaceTypeDefinition() {
|
|
5927
|
+
const start = this._lexer.token;
|
|
5928
|
+
const description = this.parseDescription();
|
|
5782
5929
|
this.expectKeyword('interface');
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
return {
|
|
5930
|
+
const name = this.parseName();
|
|
5931
|
+
const interfaces = this.parseImplementsInterfaces();
|
|
5932
|
+
const directives = this.parseConstDirectives();
|
|
5933
|
+
const fields = this.parseFieldsDefinition();
|
|
5934
|
+
return this.node(start, {
|
|
5788
5935
|
kind: Kind.INTERFACE_TYPE_DEFINITION,
|
|
5789
|
-
description
|
|
5790
|
-
name
|
|
5791
|
-
interfaces
|
|
5792
|
-
directives
|
|
5793
|
-
fields
|
|
5794
|
-
|
|
5795
|
-
};
|
|
5936
|
+
description,
|
|
5937
|
+
name,
|
|
5938
|
+
interfaces,
|
|
5939
|
+
directives,
|
|
5940
|
+
fields,
|
|
5941
|
+
});
|
|
5796
5942
|
}
|
|
5797
5943
|
/**
|
|
5798
5944
|
* UnionTypeDefinition :
|
|
5799
5945
|
* - Description? union Name Directives[Const]? UnionMemberTypes?
|
|
5800
5946
|
*/
|
|
5801
|
-
;
|
|
5802
5947
|
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5948
|
+
parseUnionTypeDefinition() {
|
|
5949
|
+
const start = this._lexer.token;
|
|
5950
|
+
const description = this.parseDescription();
|
|
5806
5951
|
this.expectKeyword('union');
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
return {
|
|
5952
|
+
const name = this.parseName();
|
|
5953
|
+
const directives = this.parseConstDirectives();
|
|
5954
|
+
const types = this.parseUnionMemberTypes();
|
|
5955
|
+
return this.node(start, {
|
|
5811
5956
|
kind: Kind.UNION_TYPE_DEFINITION,
|
|
5812
|
-
description
|
|
5813
|
-
name
|
|
5814
|
-
directives
|
|
5815
|
-
types
|
|
5816
|
-
|
|
5817
|
-
};
|
|
5957
|
+
description,
|
|
5958
|
+
name,
|
|
5959
|
+
directives,
|
|
5960
|
+
types,
|
|
5961
|
+
});
|
|
5818
5962
|
}
|
|
5819
5963
|
/**
|
|
5820
5964
|
* UnionMemberTypes :
|
|
5821
5965
|
* - = `|`? NamedType
|
|
5822
5966
|
* - UnionMemberTypes | NamedType
|
|
5823
5967
|
*/
|
|
5824
|
-
;
|
|
5825
5968
|
|
|
5826
|
-
|
|
5827
|
-
return this.expectOptionalToken(TokenKind.EQUALS)
|
|
5969
|
+
parseUnionMemberTypes() {
|
|
5970
|
+
return this.expectOptionalToken(TokenKind.EQUALS)
|
|
5971
|
+
? this.delimitedMany(TokenKind.PIPE, this.parseNamedType)
|
|
5972
|
+
: [];
|
|
5828
5973
|
}
|
|
5829
5974
|
/**
|
|
5830
5975
|
* EnumTypeDefinition :
|
|
5831
5976
|
* - Description? enum Name Directives[Const]? EnumValuesDefinition?
|
|
5832
5977
|
*/
|
|
5833
|
-
;
|
|
5834
5978
|
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5979
|
+
parseEnumTypeDefinition() {
|
|
5980
|
+
const start = this._lexer.token;
|
|
5981
|
+
const description = this.parseDescription();
|
|
5838
5982
|
this.expectKeyword('enum');
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
return {
|
|
5983
|
+
const name = this.parseName();
|
|
5984
|
+
const directives = this.parseConstDirectives();
|
|
5985
|
+
const values = this.parseEnumValuesDefinition();
|
|
5986
|
+
return this.node(start, {
|
|
5843
5987
|
kind: Kind.ENUM_TYPE_DEFINITION,
|
|
5844
|
-
description
|
|
5845
|
-
name
|
|
5846
|
-
directives
|
|
5847
|
-
values
|
|
5848
|
-
|
|
5849
|
-
};
|
|
5988
|
+
description,
|
|
5989
|
+
name,
|
|
5990
|
+
directives,
|
|
5991
|
+
values,
|
|
5992
|
+
});
|
|
5850
5993
|
}
|
|
5851
5994
|
/**
|
|
5995
|
+
* ```
|
|
5852
5996
|
* EnumValuesDefinition : { EnumValueDefinition+ }
|
|
5997
|
+
* ```
|
|
5853
5998
|
*/
|
|
5854
|
-
;
|
|
5855
5999
|
|
|
5856
|
-
|
|
5857
|
-
return this.optionalMany(
|
|
6000
|
+
parseEnumValuesDefinition() {
|
|
6001
|
+
return this.optionalMany(
|
|
6002
|
+
TokenKind.BRACE_L,
|
|
6003
|
+
this.parseEnumValueDefinition,
|
|
6004
|
+
TokenKind.BRACE_R,
|
|
6005
|
+
);
|
|
5858
6006
|
}
|
|
5859
6007
|
/**
|
|
5860
6008
|
* EnumValueDefinition : Description? EnumValue Directives[Const]?
|
|
5861
|
-
*
|
|
5862
|
-
* EnumValue : Name
|
|
5863
6009
|
*/
|
|
5864
|
-
;
|
|
5865
6010
|
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
return {
|
|
6011
|
+
parseEnumValueDefinition() {
|
|
6012
|
+
const start = this._lexer.token;
|
|
6013
|
+
const description = this.parseDescription();
|
|
6014
|
+
const name = this.parseEnumValueName();
|
|
6015
|
+
const directives = this.parseConstDirectives();
|
|
6016
|
+
return this.node(start, {
|
|
5872
6017
|
kind: Kind.ENUM_VALUE_DEFINITION,
|
|
5873
|
-
description
|
|
5874
|
-
name
|
|
5875
|
-
directives
|
|
5876
|
-
|
|
5877
|
-
|
|
6018
|
+
description,
|
|
6019
|
+
name,
|
|
6020
|
+
directives,
|
|
6021
|
+
});
|
|
6022
|
+
}
|
|
6023
|
+
/**
|
|
6024
|
+
* EnumValue : Name but not `true`, `false` or `null`
|
|
6025
|
+
*/
|
|
6026
|
+
|
|
6027
|
+
parseEnumValueName() {
|
|
6028
|
+
if (
|
|
6029
|
+
this._lexer.token.value === 'true' ||
|
|
6030
|
+
this._lexer.token.value === 'false' ||
|
|
6031
|
+
this._lexer.token.value === 'null'
|
|
6032
|
+
) {
|
|
6033
|
+
throw syntaxError(
|
|
6034
|
+
this._lexer.source,
|
|
6035
|
+
this._lexer.token.start,
|
|
6036
|
+
`${getTokenDesc(
|
|
6037
|
+
this._lexer.token,
|
|
6038
|
+
)} is reserved and cannot be used for an enum value.`,
|
|
6039
|
+
);
|
|
6040
|
+
}
|
|
6041
|
+
|
|
6042
|
+
return this.parseName();
|
|
5878
6043
|
}
|
|
5879
6044
|
/**
|
|
5880
6045
|
* InputObjectTypeDefinition :
|
|
5881
6046
|
* - Description? input Name Directives[Const]? InputFieldsDefinition?
|
|
5882
6047
|
*/
|
|
5883
|
-
;
|
|
5884
6048
|
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
6049
|
+
parseInputObjectTypeDefinition() {
|
|
6050
|
+
const start = this._lexer.token;
|
|
6051
|
+
const description = this.parseDescription();
|
|
5888
6052
|
this.expectKeyword('input');
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
return {
|
|
6053
|
+
const name = this.parseName();
|
|
6054
|
+
const directives = this.parseConstDirectives();
|
|
6055
|
+
const fields = this.parseInputFieldsDefinition();
|
|
6056
|
+
return this.node(start, {
|
|
5893
6057
|
kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
5894
|
-
description
|
|
5895
|
-
name
|
|
5896
|
-
directives
|
|
5897
|
-
fields
|
|
5898
|
-
|
|
5899
|
-
};
|
|
6058
|
+
description,
|
|
6059
|
+
name,
|
|
6060
|
+
directives,
|
|
6061
|
+
fields,
|
|
6062
|
+
});
|
|
5900
6063
|
}
|
|
5901
6064
|
/**
|
|
6065
|
+
* ```
|
|
5902
6066
|
* InputFieldsDefinition : { InputValueDefinition+ }
|
|
6067
|
+
* ```
|
|
5903
6068
|
*/
|
|
5904
|
-
;
|
|
5905
6069
|
|
|
5906
|
-
|
|
5907
|
-
return this.optionalMany(
|
|
6070
|
+
parseInputFieldsDefinition() {
|
|
6071
|
+
return this.optionalMany(
|
|
6072
|
+
TokenKind.BRACE_L,
|
|
6073
|
+
this.parseInputValueDef,
|
|
6074
|
+
TokenKind.BRACE_R,
|
|
6075
|
+
);
|
|
5908
6076
|
}
|
|
5909
6077
|
/**
|
|
5910
6078
|
* TypeSystemExtension :
|
|
@@ -5919,10 +6087,9 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5919
6087
|
* - EnumTypeExtension
|
|
5920
6088
|
* - InputObjectTypeDefinition
|
|
5921
6089
|
*/
|
|
5922
|
-
;
|
|
5923
6090
|
|
|
5924
|
-
|
|
5925
|
-
|
|
6091
|
+
parseTypeSystemExtension() {
|
|
6092
|
+
const keywordToken = this._lexer.lookahead();
|
|
5926
6093
|
|
|
5927
6094
|
if (keywordToken.kind === TokenKind.NAME) {
|
|
5928
6095
|
switch (keywordToken.value) {
|
|
@@ -5952,53 +6119,55 @@ var Parser = /*#__PURE__*/function () {
|
|
|
5952
6119
|
throw this.unexpected(keywordToken);
|
|
5953
6120
|
}
|
|
5954
6121
|
/**
|
|
6122
|
+
* ```
|
|
5955
6123
|
* SchemaExtension :
|
|
5956
6124
|
* - extend schema Directives[Const]? { OperationTypeDefinition+ }
|
|
5957
6125
|
* - extend schema Directives[Const]
|
|
6126
|
+
* ```
|
|
5958
6127
|
*/
|
|
5959
|
-
;
|
|
5960
6128
|
|
|
5961
|
-
|
|
5962
|
-
|
|
6129
|
+
parseSchemaExtension() {
|
|
6130
|
+
const start = this._lexer.token;
|
|
5963
6131
|
this.expectKeyword('extend');
|
|
5964
6132
|
this.expectKeyword('schema');
|
|
5965
|
-
|
|
5966
|
-
|
|
6133
|
+
const directives = this.parseConstDirectives();
|
|
6134
|
+
const operationTypes = this.optionalMany(
|
|
6135
|
+
TokenKind.BRACE_L,
|
|
6136
|
+
this.parseOperationTypeDefinition,
|
|
6137
|
+
TokenKind.BRACE_R,
|
|
6138
|
+
);
|
|
5967
6139
|
|
|
5968
6140
|
if (directives.length === 0 && operationTypes.length === 0) {
|
|
5969
6141
|
throw this.unexpected();
|
|
5970
6142
|
}
|
|
5971
6143
|
|
|
5972
|
-
return {
|
|
6144
|
+
return this.node(start, {
|
|
5973
6145
|
kind: Kind.SCHEMA_EXTENSION,
|
|
5974
|
-
directives
|
|
5975
|
-
operationTypes
|
|
5976
|
-
|
|
5977
|
-
};
|
|
6146
|
+
directives,
|
|
6147
|
+
operationTypes,
|
|
6148
|
+
});
|
|
5978
6149
|
}
|
|
5979
6150
|
/**
|
|
5980
6151
|
* ScalarTypeExtension :
|
|
5981
6152
|
* - extend scalar Name Directives[Const]
|
|
5982
6153
|
*/
|
|
5983
|
-
;
|
|
5984
6154
|
|
|
5985
|
-
|
|
5986
|
-
|
|
6155
|
+
parseScalarTypeExtension() {
|
|
6156
|
+
const start = this._lexer.token;
|
|
5987
6157
|
this.expectKeyword('extend');
|
|
5988
6158
|
this.expectKeyword('scalar');
|
|
5989
|
-
|
|
5990
|
-
|
|
6159
|
+
const name = this.parseName();
|
|
6160
|
+
const directives = this.parseConstDirectives();
|
|
5991
6161
|
|
|
5992
6162
|
if (directives.length === 0) {
|
|
5993
6163
|
throw this.unexpected();
|
|
5994
6164
|
}
|
|
5995
6165
|
|
|
5996
|
-
return {
|
|
6166
|
+
return this.node(start, {
|
|
5997
6167
|
kind: Kind.SCALAR_TYPE_EXTENSION,
|
|
5998
|
-
name
|
|
5999
|
-
directives
|
|
6000
|
-
|
|
6001
|
-
};
|
|
6168
|
+
name,
|
|
6169
|
+
directives,
|
|
6170
|
+
});
|
|
6002
6171
|
}
|
|
6003
6172
|
/**
|
|
6004
6173
|
* ObjectTypeExtension :
|
|
@@ -6006,29 +6175,31 @@ var Parser = /*#__PURE__*/function () {
|
|
|
6006
6175
|
* - extend type Name ImplementsInterfaces? Directives[Const]
|
|
6007
6176
|
* - extend type Name ImplementsInterfaces
|
|
6008
6177
|
*/
|
|
6009
|
-
;
|
|
6010
6178
|
|
|
6011
|
-
|
|
6012
|
-
|
|
6179
|
+
parseObjectTypeExtension() {
|
|
6180
|
+
const start = this._lexer.token;
|
|
6013
6181
|
this.expectKeyword('extend');
|
|
6014
6182
|
this.expectKeyword('type');
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
if (
|
|
6183
|
+
const name = this.parseName();
|
|
6184
|
+
const interfaces = this.parseImplementsInterfaces();
|
|
6185
|
+
const directives = this.parseConstDirectives();
|
|
6186
|
+
const fields = this.parseFieldsDefinition();
|
|
6187
|
+
|
|
6188
|
+
if (
|
|
6189
|
+
interfaces.length === 0 &&
|
|
6190
|
+
directives.length === 0 &&
|
|
6191
|
+
fields.length === 0
|
|
6192
|
+
) {
|
|
6021
6193
|
throw this.unexpected();
|
|
6022
6194
|
}
|
|
6023
6195
|
|
|
6024
|
-
return {
|
|
6196
|
+
return this.node(start, {
|
|
6025
6197
|
kind: Kind.OBJECT_TYPE_EXTENSION,
|
|
6026
|
-
name
|
|
6027
|
-
interfaces
|
|
6028
|
-
directives
|
|
6029
|
-
fields
|
|
6030
|
-
|
|
6031
|
-
};
|
|
6198
|
+
name,
|
|
6199
|
+
interfaces,
|
|
6200
|
+
directives,
|
|
6201
|
+
fields,
|
|
6202
|
+
});
|
|
6032
6203
|
}
|
|
6033
6204
|
/**
|
|
6034
6205
|
* InterfaceTypeExtension :
|
|
@@ -6036,145 +6207,140 @@ var Parser = /*#__PURE__*/function () {
|
|
|
6036
6207
|
* - extend interface Name ImplementsInterfaces? Directives[Const]
|
|
6037
6208
|
* - extend interface Name ImplementsInterfaces
|
|
6038
6209
|
*/
|
|
6039
|
-
;
|
|
6040
6210
|
|
|
6041
|
-
|
|
6042
|
-
|
|
6211
|
+
parseInterfaceTypeExtension() {
|
|
6212
|
+
const start = this._lexer.token;
|
|
6043
6213
|
this.expectKeyword('extend');
|
|
6044
6214
|
this.expectKeyword('interface');
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
if (
|
|
6215
|
+
const name = this.parseName();
|
|
6216
|
+
const interfaces = this.parseImplementsInterfaces();
|
|
6217
|
+
const directives = this.parseConstDirectives();
|
|
6218
|
+
const fields = this.parseFieldsDefinition();
|
|
6219
|
+
|
|
6220
|
+
if (
|
|
6221
|
+
interfaces.length === 0 &&
|
|
6222
|
+
directives.length === 0 &&
|
|
6223
|
+
fields.length === 0
|
|
6224
|
+
) {
|
|
6051
6225
|
throw this.unexpected();
|
|
6052
6226
|
}
|
|
6053
6227
|
|
|
6054
|
-
return {
|
|
6228
|
+
return this.node(start, {
|
|
6055
6229
|
kind: Kind.INTERFACE_TYPE_EXTENSION,
|
|
6056
|
-
name
|
|
6057
|
-
interfaces
|
|
6058
|
-
directives
|
|
6059
|
-
fields
|
|
6060
|
-
|
|
6061
|
-
};
|
|
6230
|
+
name,
|
|
6231
|
+
interfaces,
|
|
6232
|
+
directives,
|
|
6233
|
+
fields,
|
|
6234
|
+
});
|
|
6062
6235
|
}
|
|
6063
6236
|
/**
|
|
6064
6237
|
* UnionTypeExtension :
|
|
6065
6238
|
* - extend union Name Directives[Const]? UnionMemberTypes
|
|
6066
6239
|
* - extend union Name Directives[Const]
|
|
6067
6240
|
*/
|
|
6068
|
-
;
|
|
6069
6241
|
|
|
6070
|
-
|
|
6071
|
-
|
|
6242
|
+
parseUnionTypeExtension() {
|
|
6243
|
+
const start = this._lexer.token;
|
|
6072
6244
|
this.expectKeyword('extend');
|
|
6073
6245
|
this.expectKeyword('union');
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6246
|
+
const name = this.parseName();
|
|
6247
|
+
const directives = this.parseConstDirectives();
|
|
6248
|
+
const types = this.parseUnionMemberTypes();
|
|
6077
6249
|
|
|
6078
6250
|
if (directives.length === 0 && types.length === 0) {
|
|
6079
6251
|
throw this.unexpected();
|
|
6080
6252
|
}
|
|
6081
6253
|
|
|
6082
|
-
return {
|
|
6254
|
+
return this.node(start, {
|
|
6083
6255
|
kind: Kind.UNION_TYPE_EXTENSION,
|
|
6084
|
-
name
|
|
6085
|
-
directives
|
|
6086
|
-
types
|
|
6087
|
-
|
|
6088
|
-
};
|
|
6256
|
+
name,
|
|
6257
|
+
directives,
|
|
6258
|
+
types,
|
|
6259
|
+
});
|
|
6089
6260
|
}
|
|
6090
6261
|
/**
|
|
6091
6262
|
* EnumTypeExtension :
|
|
6092
6263
|
* - extend enum Name Directives[Const]? EnumValuesDefinition
|
|
6093
6264
|
* - extend enum Name Directives[Const]
|
|
6094
6265
|
*/
|
|
6095
|
-
;
|
|
6096
6266
|
|
|
6097
|
-
|
|
6098
|
-
|
|
6267
|
+
parseEnumTypeExtension() {
|
|
6268
|
+
const start = this._lexer.token;
|
|
6099
6269
|
this.expectKeyword('extend');
|
|
6100
6270
|
this.expectKeyword('enum');
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6271
|
+
const name = this.parseName();
|
|
6272
|
+
const directives = this.parseConstDirectives();
|
|
6273
|
+
const values = this.parseEnumValuesDefinition();
|
|
6104
6274
|
|
|
6105
6275
|
if (directives.length === 0 && values.length === 0) {
|
|
6106
6276
|
throw this.unexpected();
|
|
6107
6277
|
}
|
|
6108
6278
|
|
|
6109
|
-
return {
|
|
6279
|
+
return this.node(start, {
|
|
6110
6280
|
kind: Kind.ENUM_TYPE_EXTENSION,
|
|
6111
|
-
name
|
|
6112
|
-
directives
|
|
6113
|
-
values
|
|
6114
|
-
|
|
6115
|
-
};
|
|
6281
|
+
name,
|
|
6282
|
+
directives,
|
|
6283
|
+
values,
|
|
6284
|
+
});
|
|
6116
6285
|
}
|
|
6117
6286
|
/**
|
|
6118
6287
|
* InputObjectTypeExtension :
|
|
6119
6288
|
* - extend input Name Directives[Const]? InputFieldsDefinition
|
|
6120
6289
|
* - extend input Name Directives[Const]
|
|
6121
6290
|
*/
|
|
6122
|
-
;
|
|
6123
6291
|
|
|
6124
|
-
|
|
6125
|
-
|
|
6292
|
+
parseInputObjectTypeExtension() {
|
|
6293
|
+
const start = this._lexer.token;
|
|
6126
6294
|
this.expectKeyword('extend');
|
|
6127
6295
|
this.expectKeyword('input');
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
|
|
6296
|
+
const name = this.parseName();
|
|
6297
|
+
const directives = this.parseConstDirectives();
|
|
6298
|
+
const fields = this.parseInputFieldsDefinition();
|
|
6131
6299
|
|
|
6132
6300
|
if (directives.length === 0 && fields.length === 0) {
|
|
6133
6301
|
throw this.unexpected();
|
|
6134
6302
|
}
|
|
6135
6303
|
|
|
6136
|
-
return {
|
|
6304
|
+
return this.node(start, {
|
|
6137
6305
|
kind: Kind.INPUT_OBJECT_TYPE_EXTENSION,
|
|
6138
|
-
name
|
|
6139
|
-
directives
|
|
6140
|
-
fields
|
|
6141
|
-
|
|
6142
|
-
};
|
|
6306
|
+
name,
|
|
6307
|
+
directives,
|
|
6308
|
+
fields,
|
|
6309
|
+
});
|
|
6143
6310
|
}
|
|
6144
6311
|
/**
|
|
6312
|
+
* ```
|
|
6145
6313
|
* DirectiveDefinition :
|
|
6146
6314
|
* - Description? directive @ Name ArgumentsDefinition? `repeatable`? on DirectiveLocations
|
|
6315
|
+
* ```
|
|
6147
6316
|
*/
|
|
6148
|
-
;
|
|
6149
6317
|
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6318
|
+
parseDirectiveDefinition() {
|
|
6319
|
+
const start = this._lexer.token;
|
|
6320
|
+
const description = this.parseDescription();
|
|
6153
6321
|
this.expectKeyword('directive');
|
|
6154
6322
|
this.expectToken(TokenKind.AT);
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6323
|
+
const name = this.parseName();
|
|
6324
|
+
const args = this.parseArgumentDefs();
|
|
6325
|
+
const repeatable = this.expectOptionalKeyword('repeatable');
|
|
6158
6326
|
this.expectKeyword('on');
|
|
6159
|
-
|
|
6160
|
-
return {
|
|
6327
|
+
const locations = this.parseDirectiveLocations();
|
|
6328
|
+
return this.node(start, {
|
|
6161
6329
|
kind: Kind.DIRECTIVE_DEFINITION,
|
|
6162
|
-
description
|
|
6163
|
-
name
|
|
6330
|
+
description,
|
|
6331
|
+
name,
|
|
6164
6332
|
arguments: args,
|
|
6165
|
-
repeatable
|
|
6166
|
-
locations
|
|
6167
|
-
|
|
6168
|
-
};
|
|
6333
|
+
repeatable,
|
|
6334
|
+
locations,
|
|
6335
|
+
});
|
|
6169
6336
|
}
|
|
6170
6337
|
/**
|
|
6171
6338
|
* DirectiveLocations :
|
|
6172
6339
|
* - `|`? DirectiveLocation
|
|
6173
6340
|
* - DirectiveLocations | DirectiveLocation
|
|
6174
6341
|
*/
|
|
6175
|
-
;
|
|
6176
6342
|
|
|
6177
|
-
|
|
6343
|
+
parseDirectiveLocations() {
|
|
6178
6344
|
return this.delimitedMany(TokenKind.PIPE, this.parseDirectiveLocation);
|
|
6179
6345
|
}
|
|
6180
6346
|
/*
|
|
@@ -6204,13 +6370,12 @@ var Parser = /*#__PURE__*/function () {
|
|
|
6204
6370
|
* `INPUT_OBJECT`
|
|
6205
6371
|
* `INPUT_FIELD_DEFINITION`
|
|
6206
6372
|
*/
|
|
6207
|
-
;
|
|
6208
6373
|
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6374
|
+
parseDirectiveLocation() {
|
|
6375
|
+
const start = this._lexer.token;
|
|
6376
|
+
const name = this.parseName();
|
|
6212
6377
|
|
|
6213
|
-
if (DirectiveLocation
|
|
6378
|
+
if (Object.prototype.hasOwnProperty.call(DirectiveLocation, name.value)) {
|
|
6214
6379
|
return name;
|
|
6215
6380
|
}
|
|
6216
6381
|
|
|
@@ -6218,33 +6383,42 @@ var Parser = /*#__PURE__*/function () {
|
|
|
6218
6383
|
} // Core parsing utility functions
|
|
6219
6384
|
|
|
6220
6385
|
/**
|
|
6221
|
-
* Returns a
|
|
6386
|
+
* Returns a node that, if configured to do so, sets a "loc" field as a
|
|
6387
|
+
* location object, used to identify the place in the source that created a
|
|
6388
|
+
* given parsed object.
|
|
6222
6389
|
*/
|
|
6223
|
-
;
|
|
6224
6390
|
|
|
6225
|
-
|
|
6226
|
-
var _this$
|
|
6391
|
+
node(startToken, node) {
|
|
6392
|
+
var _this$_options2;
|
|
6227
6393
|
|
|
6228
|
-
if (
|
|
6229
|
-
|
|
6394
|
+
if (
|
|
6395
|
+
((_this$_options2 = this._options) === null || _this$_options2 === void 0
|
|
6396
|
+
? void 0
|
|
6397
|
+
: _this$_options2.noLocation) !== true
|
|
6398
|
+
) {
|
|
6399
|
+
node.loc = new Location(
|
|
6400
|
+
startToken,
|
|
6401
|
+
this._lexer.lastToken,
|
|
6402
|
+
this._lexer.source,
|
|
6403
|
+
);
|
|
6230
6404
|
}
|
|
6405
|
+
|
|
6406
|
+
return node;
|
|
6231
6407
|
}
|
|
6232
6408
|
/**
|
|
6233
6409
|
* Determines if the next token is of a given kind
|
|
6234
6410
|
*/
|
|
6235
|
-
;
|
|
6236
6411
|
|
|
6237
|
-
|
|
6412
|
+
peek(kind) {
|
|
6238
6413
|
return this._lexer.token.kind === kind;
|
|
6239
6414
|
}
|
|
6240
6415
|
/**
|
|
6241
6416
|
* If the next token is of the given kind, return that token after advancing the lexer.
|
|
6242
6417
|
* Otherwise, do not change the parser state and throw an error.
|
|
6243
6418
|
*/
|
|
6244
|
-
;
|
|
6245
6419
|
|
|
6246
|
-
|
|
6247
|
-
|
|
6420
|
+
expectToken(kind) {
|
|
6421
|
+
const token = this._lexer.token;
|
|
6248
6422
|
|
|
6249
6423
|
if (token.kind === kind) {
|
|
6250
6424
|
this._lexer.advance();
|
|
@@ -6252,48 +6426,53 @@ var Parser = /*#__PURE__*/function () {
|
|
|
6252
6426
|
return token;
|
|
6253
6427
|
}
|
|
6254
6428
|
|
|
6255
|
-
throw syntaxError(
|
|
6429
|
+
throw syntaxError(
|
|
6430
|
+
this._lexer.source,
|
|
6431
|
+
token.start,
|
|
6432
|
+
`Expected ${getTokenKindDesc(kind)}, found ${getTokenDesc(token)}.`,
|
|
6433
|
+
);
|
|
6256
6434
|
}
|
|
6257
6435
|
/**
|
|
6258
|
-
* If the next token is of the given kind, return
|
|
6259
|
-
* Otherwise, do not change the parser state and return
|
|
6436
|
+
* If the next token is of the given kind, return "true" after advancing the lexer.
|
|
6437
|
+
* Otherwise, do not change the parser state and return "false".
|
|
6260
6438
|
*/
|
|
6261
|
-
;
|
|
6262
6439
|
|
|
6263
|
-
|
|
6264
|
-
|
|
6440
|
+
expectOptionalToken(kind) {
|
|
6441
|
+
const token = this._lexer.token;
|
|
6265
6442
|
|
|
6266
6443
|
if (token.kind === kind) {
|
|
6267
6444
|
this._lexer.advance();
|
|
6268
6445
|
|
|
6269
|
-
return
|
|
6446
|
+
return true;
|
|
6270
6447
|
}
|
|
6271
6448
|
|
|
6272
|
-
return
|
|
6449
|
+
return false;
|
|
6273
6450
|
}
|
|
6274
6451
|
/**
|
|
6275
6452
|
* If the next token is a given keyword, advance the lexer.
|
|
6276
6453
|
* Otherwise, do not change the parser state and throw an error.
|
|
6277
6454
|
*/
|
|
6278
|
-
;
|
|
6279
6455
|
|
|
6280
|
-
|
|
6281
|
-
|
|
6456
|
+
expectKeyword(value) {
|
|
6457
|
+
const token = this._lexer.token;
|
|
6282
6458
|
|
|
6283
6459
|
if (token.kind === TokenKind.NAME && token.value === value) {
|
|
6284
6460
|
this._lexer.advance();
|
|
6285
6461
|
} else {
|
|
6286
|
-
throw syntaxError(
|
|
6462
|
+
throw syntaxError(
|
|
6463
|
+
this._lexer.source,
|
|
6464
|
+
token.start,
|
|
6465
|
+
`Expected "${value}", found ${getTokenDesc(token)}.`,
|
|
6466
|
+
);
|
|
6287
6467
|
}
|
|
6288
6468
|
}
|
|
6289
6469
|
/**
|
|
6290
6470
|
* If the next token is a given keyword, return "true" after advancing the lexer.
|
|
6291
6471
|
* Otherwise, do not change the parser state and return "false".
|
|
6292
6472
|
*/
|
|
6293
|
-
;
|
|
6294
6473
|
|
|
6295
|
-
|
|
6296
|
-
|
|
6474
|
+
expectOptionalKeyword(value) {
|
|
6475
|
+
const token = this._lexer.token;
|
|
6297
6476
|
|
|
6298
6477
|
if (token.kind === TokenKind.NAME && token.value === value) {
|
|
6299
6478
|
this._lexer.advance();
|
|
@@ -6306,22 +6485,25 @@ var Parser = /*#__PURE__*/function () {
|
|
|
6306
6485
|
/**
|
|
6307
6486
|
* Helper function for creating an error when an unexpected lexed token is encountered.
|
|
6308
6487
|
*/
|
|
6309
|
-
;
|
|
6310
6488
|
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6489
|
+
unexpected(atToken) {
|
|
6490
|
+
const token =
|
|
6491
|
+
atToken !== null && atToken !== void 0 ? atToken : this._lexer.token;
|
|
6492
|
+
return syntaxError(
|
|
6493
|
+
this._lexer.source,
|
|
6494
|
+
token.start,
|
|
6495
|
+
`Unexpected ${getTokenDesc(token)}.`,
|
|
6496
|
+
);
|
|
6314
6497
|
}
|
|
6315
6498
|
/**
|
|
6316
6499
|
* Returns a possibly empty list of parse nodes, determined by the parseFn.
|
|
6317
6500
|
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
6318
6501
|
* Advances the parser to the next lex token after the closing token.
|
|
6319
6502
|
*/
|
|
6320
|
-
;
|
|
6321
6503
|
|
|
6322
|
-
|
|
6504
|
+
any(openKind, parseFn, closeKind) {
|
|
6323
6505
|
this.expectToken(openKind);
|
|
6324
|
-
|
|
6506
|
+
const nodes = [];
|
|
6325
6507
|
|
|
6326
6508
|
while (!this.expectOptionalToken(closeKind)) {
|
|
6327
6509
|
nodes.push(parseFn.call(this));
|
|
@@ -6335,11 +6517,10 @@ var Parser = /*#__PURE__*/function () {
|
|
|
6335
6517
|
* that begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
6336
6518
|
* Advances the parser to the next lex token after the closing token.
|
|
6337
6519
|
*/
|
|
6338
|
-
;
|
|
6339
6520
|
|
|
6340
|
-
|
|
6521
|
+
optionalMany(openKind, parseFn, closeKind) {
|
|
6341
6522
|
if (this.expectOptionalToken(openKind)) {
|
|
6342
|
-
|
|
6523
|
+
const nodes = [];
|
|
6343
6524
|
|
|
6344
6525
|
do {
|
|
6345
6526
|
nodes.push(parseFn.call(this));
|
|
@@ -6355,11 +6536,10 @@ var Parser = /*#__PURE__*/function () {
|
|
|
6355
6536
|
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
6356
6537
|
* Advances the parser to the next lex token after the closing token.
|
|
6357
6538
|
*/
|
|
6358
|
-
;
|
|
6359
6539
|
|
|
6360
|
-
|
|
6540
|
+
many(openKind, parseFn, closeKind) {
|
|
6361
6541
|
this.expectToken(openKind);
|
|
6362
|
-
|
|
6542
|
+
const nodes = [];
|
|
6363
6543
|
|
|
6364
6544
|
do {
|
|
6365
6545
|
nodes.push(parseFn.call(this));
|
|
@@ -6372,36 +6552,32 @@ var Parser = /*#__PURE__*/function () {
|
|
|
6372
6552
|
* This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
|
|
6373
6553
|
* Advances the parser to the next lex token after last item in the list.
|
|
6374
6554
|
*/
|
|
6375
|
-
;
|
|
6376
6555
|
|
|
6377
|
-
|
|
6556
|
+
delimitedMany(delimiterKind, parseFn) {
|
|
6378
6557
|
this.expectOptionalToken(delimiterKind);
|
|
6379
|
-
|
|
6558
|
+
const nodes = [];
|
|
6380
6559
|
|
|
6381
6560
|
do {
|
|
6382
6561
|
nodes.push(parseFn.call(this));
|
|
6383
6562
|
} while (this.expectOptionalToken(delimiterKind));
|
|
6384
6563
|
|
|
6385
6564
|
return nodes;
|
|
6386
|
-
}
|
|
6387
|
-
|
|
6388
|
-
return Parser;
|
|
6389
|
-
}();
|
|
6565
|
+
}
|
|
6566
|
+
}
|
|
6390
6567
|
/**
|
|
6391
6568
|
* A helper function to describe a token as a string for debugging.
|
|
6392
6569
|
*/
|
|
6393
6570
|
|
|
6394
6571
|
function getTokenDesc(token) {
|
|
6395
|
-
|
|
6396
|
-
return getTokenKindDesc(token.kind) + (value != null ?
|
|
6572
|
+
const value = token.value;
|
|
6573
|
+
return getTokenKindDesc(token.kind) + (value != null ? ` "${value}"` : '');
|
|
6397
6574
|
}
|
|
6398
6575
|
/**
|
|
6399
6576
|
* A helper function to describe a token kind as a string for debugging.
|
|
6400
6577
|
*/
|
|
6401
6578
|
|
|
6402
|
-
|
|
6403
6579
|
function getTokenKindDesc(kind) {
|
|
6404
|
-
return isPunctuatorTokenKind(kind) ? "
|
|
6580
|
+
return isPunctuatorTokenKind(kind) ? `"${kind}"` : kind;
|
|
6405
6581
|
}
|
|
6406
6582
|
|
|
6407
6583
|
/**
|
|
@@ -6817,7 +6993,9 @@ const createFetchRequestParameters = (input) => {
|
|
|
6817
6993
|
if (['GET', 'HEAD'].includes(method)) {
|
|
6818
6994
|
return requestParameters;
|
|
6819
6995
|
}
|
|
6820
|
-
if (typeof body === 'object' ||
|
|
6996
|
+
if (typeof body === 'object' ||
|
|
6997
|
+
typeof body === 'number' ||
|
|
6998
|
+
typeof body === 'boolean') {
|
|
6821
6999
|
requestParameters.body = JSON.stringify(body);
|
|
6822
7000
|
}
|
|
6823
7001
|
else {
|
|
@@ -7780,56 +7958,71 @@ ${handlers.map((handler) => ` • ${handler.info.header}`).join('\n')}`;
|
|
|
7780
7958
|
return `Did you mean to request "${handlers[0].info.header}" instead?`;
|
|
7781
7959
|
}
|
|
7782
7960
|
function onUnhandledRequest(request, handlers, strategy = 'warn') {
|
|
7783
|
-
if (typeof strategy === 'function') {
|
|
7784
|
-
strategy(request);
|
|
7785
|
-
return;
|
|
7786
|
-
}
|
|
7787
|
-
/**
|
|
7788
|
-
* @note Ignore exceptions during GraphQL request parsing because at this point
|
|
7789
|
-
* we cannot assume the unhandled request is a valid GraphQL request.
|
|
7790
|
-
* If the GraphQL parsing fails, just don't treat it as a GraphQL request.
|
|
7791
|
-
*/
|
|
7792
7961
|
const parsedGraphQLQuery = tryCatch(() => parseGraphQLRequest(request));
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7962
|
+
function generateHandlerSuggestion() {
|
|
7963
|
+
/**
|
|
7964
|
+
* @note Ignore exceptions during GraphQL request parsing because at this point
|
|
7965
|
+
* we cannot assume the unhandled request is a valid GraphQL request.
|
|
7966
|
+
* If the GraphQL parsing fails, just don't treat it as a GraphQL request.
|
|
7967
|
+
*/
|
|
7968
|
+
const handlerGroups = groupHandlersByType(handlers);
|
|
7969
|
+
const relevantHandlers = parsedGraphQLQuery
|
|
7970
|
+
? handlerGroups.graphql
|
|
7971
|
+
: handlerGroups.rest;
|
|
7972
|
+
const suggestedHandlers = getSuggestedHandler(request, relevantHandlers, parsedGraphQLQuery
|
|
7973
|
+
? getGraphQLHandlerScore(parsedGraphQLQuery)
|
|
7974
|
+
: getRestHandlerScore());
|
|
7975
|
+
return suggestedHandlers.length > 0
|
|
7976
|
+
? getSuggestedHandlersMessage(suggestedHandlers)
|
|
7977
|
+
: '';
|
|
7978
|
+
}
|
|
7979
|
+
function generateUnhandledRequestMessage() {
|
|
7980
|
+
const publicUrl = getPublicUrlFromRequest(request);
|
|
7981
|
+
const requestHeader = parsedGraphQLQuery
|
|
7982
|
+
? `${parsedGraphQLQuery.operationType} ${parsedGraphQLQuery.operationName} (${request.method} ${publicUrl})`
|
|
7983
|
+
: `${request.method} ${publicUrl}`;
|
|
7984
|
+
const handlerSuggestion = generateHandlerSuggestion();
|
|
7985
|
+
const messageTemplate = [
|
|
7986
|
+
`captured a request without a matching request handler:`,
|
|
7987
|
+
` \u2022 ${requestHeader}`,
|
|
7988
|
+
handlerSuggestion,
|
|
7989
|
+
`\
|
|
7812
7990
|
If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
7813
7991
|
Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
7814
7992
|
`,
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
7993
|
+
].filter(Boolean);
|
|
7994
|
+
return messageTemplate.join('\n\n');
|
|
7995
|
+
}
|
|
7996
|
+
function applyStrategy(strategy) {
|
|
7997
|
+
// Generate handler suggestions only when applying the strategy.
|
|
7998
|
+
// This saves bandwidth for scenarios when developers opt-out
|
|
7999
|
+
// from the default unhandled request handling strategy.
|
|
8000
|
+
const message = generateUnhandledRequestMessage();
|
|
8001
|
+
switch (strategy) {
|
|
8002
|
+
case 'error': {
|
|
8003
|
+
// Print a developer-friendly error.
|
|
8004
|
+
devUtils.error('Error: %s', message);
|
|
8005
|
+
// Throw an exception to halt request processing and not perform the original request.
|
|
8006
|
+
throw new Error(devUtils.formatMessage('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'));
|
|
8007
|
+
}
|
|
8008
|
+
case 'warn': {
|
|
8009
|
+
devUtils.warn('Warning: %s', message);
|
|
8010
|
+
break;
|
|
8011
|
+
}
|
|
8012
|
+
case 'bypass':
|
|
8013
|
+
break;
|
|
8014
|
+
default:
|
|
8015
|
+
throw new Error(devUtils.formatMessage('Failed to react to an unhandled request: unknown strategy "%s". Please provide one of the supported strategies ("bypass", "warn", "error") or a custom callback function as the value of the "onUnhandledRequest" option.', strategy));
|
|
7827
8016
|
}
|
|
7828
|
-
case 'bypass':
|
|
7829
|
-
break;
|
|
7830
|
-
default:
|
|
7831
|
-
throw new Error(devUtils.formatMessage('Failed to react to an unhandled request: unknown strategy "%s". Please provide one of the supported strategies ("bypass", "warn", "error") or a custom callback function as the value of the "onUnhandledRequest" option.', strategy));
|
|
7832
8017
|
}
|
|
8018
|
+
if (typeof strategy === 'function') {
|
|
8019
|
+
strategy(request, {
|
|
8020
|
+
warning: applyStrategy.bind(null, 'warn'),
|
|
8021
|
+
error: applyStrategy.bind(null, 'error'),
|
|
8022
|
+
});
|
|
8023
|
+
return;
|
|
8024
|
+
}
|
|
8025
|
+
applyStrategy(strategy);
|
|
7833
8026
|
}
|
|
7834
8027
|
|
|
7835
8028
|
function readResponseCookies(request, response) {
|
|
@@ -7842,7 +8035,7 @@ function handleRequest(request, handlers, options, emitter, handleRequestOptions
|
|
|
7842
8035
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7843
8036
|
emitter.emit('request:start', request);
|
|
7844
8037
|
// Perform bypassed requests (i.e. issued via "ctx.fetch") as-is.
|
|
7845
|
-
if (request.headers.get('x-msw-bypass')) {
|
|
8038
|
+
if (request.headers.get('x-msw-bypass') === 'true') {
|
|
7846
8039
|
emitter.emit('request:end', request);
|
|
7847
8040
|
(_a = handleRequestOptions === null || handleRequestOptions === void 0 ? void 0 : handleRequestOptions.onBypassResponse) === null || _a === void 0 ? void 0 : _a.call(handleRequestOptions, request);
|
|
7848
8041
|
return;
|