msw 0.36.8 → 0.38.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/fetch-deps.js +14 -11
- 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/handlers/RequestHandler.d.ts +1 -1
- 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 +1 -1
- package/lib/types/utils/request/onUnhandledRequest.d.ts +5 -1
- package/lib/umd/index.js +18038 -15294
- package/lib/umd/mockServiceWorker.js +1 -1
- package/native/lib/index.js +2028 -1834
- package/node/lib/index.js +2028 -1834
- package/package.json +23 -22
- package/CHANGELOG.md +0 -4
package/native/lib/index.js
CHANGED
|
@@ -183,7 +183,6 @@ var serialize_1 = serialize;
|
|
|
183
183
|
|
|
184
184
|
var decode = decodeURIComponent;
|
|
185
185
|
var encode = encodeURIComponent;
|
|
186
|
-
var pairSplitRegExp = /; */;
|
|
187
186
|
|
|
188
187
|
/**
|
|
189
188
|
* RegExp to match field-content in RFC 7230 sec 3.2
|
|
@@ -214,28 +213,29 @@ function parse$2(str, options) {
|
|
|
214
213
|
|
|
215
214
|
var obj = {};
|
|
216
215
|
var opt = options || {};
|
|
217
|
-
var pairs = str.split(
|
|
216
|
+
var pairs = str.split(';');
|
|
218
217
|
var dec = opt.decode || decode;
|
|
219
218
|
|
|
220
219
|
for (var i = 0; i < pairs.length; i++) {
|
|
221
220
|
var pair = pairs[i];
|
|
222
|
-
var
|
|
221
|
+
var index = pair.indexOf('=');
|
|
223
222
|
|
|
224
223
|
// skip things that don't look like key=value
|
|
225
|
-
if (
|
|
224
|
+
if (index < 0) {
|
|
226
225
|
continue;
|
|
227
226
|
}
|
|
228
227
|
|
|
229
|
-
var key = pair.
|
|
230
|
-
var val = pair.substr(++eq_idx, pair.length).trim();
|
|
231
|
-
|
|
232
|
-
// quoted values
|
|
233
|
-
if ('"' == val[0]) {
|
|
234
|
-
val = val.slice(1, -1);
|
|
235
|
-
}
|
|
228
|
+
var key = pair.substring(0, index).trim();
|
|
236
229
|
|
|
237
230
|
// only assign once
|
|
238
231
|
if (undefined == obj[key]) {
|
|
232
|
+
var val = pair.substring(index + 1, pair.length).trim();
|
|
233
|
+
|
|
234
|
+
// quoted values
|
|
235
|
+
if (val[0] === '"') {
|
|
236
|
+
val = val.slice(1, -1);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
239
|
obj[key] = tryDecode(val, dec);
|
|
240
240
|
}
|
|
241
241
|
}
|
|
@@ -758,6 +758,9 @@ var Headers_1$2 = Headers;
|
|
|
758
758
|
function stringToHeaders(str) {
|
|
759
759
|
var lines = str.trim().split(/[\r\n]+/);
|
|
760
760
|
return lines.reduce(function (headers, line) {
|
|
761
|
+
if (line.trim() === '') {
|
|
762
|
+
return headers;
|
|
763
|
+
}
|
|
761
764
|
var parts = line.split(': ');
|
|
762
765
|
var name = parts.shift();
|
|
763
766
|
var value = parts.join(': ');
|
|
@@ -1391,20 +1394,33 @@ var jsLevenshtein = (function()
|
|
|
1391
1394
|
};
|
|
1392
1395
|
})();
|
|
1393
1396
|
|
|
1394
|
-
function
|
|
1397
|
+
function devAssert(condition, message) {
|
|
1398
|
+
const booleanCondition = Boolean(condition);
|
|
1399
|
+
|
|
1400
|
+
if (!booleanCondition) {
|
|
1401
|
+
throw new Error(message);
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1395
1404
|
|
|
1396
1405
|
/**
|
|
1397
1406
|
* Return true if `value` is object-like. A value is object-like if it's not
|
|
1398
1407
|
* `null` and has a `typeof` result of "object".
|
|
1399
1408
|
*/
|
|
1400
1409
|
function isObjectLike(value) {
|
|
1401
|
-
return
|
|
1410
|
+
return typeof value == 'object' && value !== null;
|
|
1402
1411
|
}
|
|
1403
1412
|
|
|
1404
|
-
|
|
1413
|
+
function invariant(condition, message) {
|
|
1414
|
+
const booleanCondition = Boolean(condition);
|
|
1405
1415
|
|
|
1406
|
-
|
|
1416
|
+
if (!booleanCondition) {
|
|
1417
|
+
throw new Error(
|
|
1418
|
+
message != null ? message : 'Unexpected invariant triggered.',
|
|
1419
|
+
);
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1407
1422
|
|
|
1423
|
+
const LineRegExp = /\r\n|[\n\r]/g;
|
|
1408
1424
|
/**
|
|
1409
1425
|
* Represents a location in a Source.
|
|
1410
1426
|
*/
|
|
@@ -1414,115 +1430,107 @@ var SYMBOL_TO_STRING_TAG = typeof Symbol === 'function' && Symbol.toStringTag !=
|
|
|
1414
1430
|
* line and column as a SourceLocation.
|
|
1415
1431
|
*/
|
|
1416
1432
|
function getLocation(source, position) {
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1433
|
+
let lastLineStart = 0;
|
|
1434
|
+
let line = 1;
|
|
1435
|
+
|
|
1436
|
+
for (const match of source.body.matchAll(LineRegExp)) {
|
|
1437
|
+
typeof match.index === 'number' || invariant(false);
|
|
1438
|
+
|
|
1439
|
+
if (match.index >= position) {
|
|
1440
|
+
break;
|
|
1441
|
+
}
|
|
1421
1442
|
|
|
1422
|
-
|
|
1443
|
+
lastLineStart = match.index + match[0].length;
|
|
1423
1444
|
line += 1;
|
|
1424
|
-
column = position + 1 - (match.index + match[0].length);
|
|
1425
1445
|
}
|
|
1426
1446
|
|
|
1427
1447
|
return {
|
|
1428
|
-
line
|
|
1429
|
-
column:
|
|
1448
|
+
line,
|
|
1449
|
+
column: position + 1 - lastLineStart,
|
|
1430
1450
|
};
|
|
1431
1451
|
}
|
|
1432
1452
|
|
|
1433
1453
|
/**
|
|
1434
1454
|
* Render a helpful description of the location in the GraphQL Source document.
|
|
1435
1455
|
*/
|
|
1436
|
-
|
|
1437
1456
|
function printLocation(location) {
|
|
1438
|
-
return printSourceLocation(
|
|
1457
|
+
return printSourceLocation(
|
|
1458
|
+
location.source,
|
|
1459
|
+
getLocation(location.source, location.start),
|
|
1460
|
+
);
|
|
1439
1461
|
}
|
|
1440
1462
|
/**
|
|
1441
1463
|
* Render a helpful description of the location in the GraphQL Source document.
|
|
1442
1464
|
*/
|
|
1443
1465
|
|
|
1444
1466
|
function printSourceLocation(source, sourceLocation) {
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1467
|
+
const firstLineColumnOffset = source.locationOffset.column - 1;
|
|
1468
|
+
const body = ''.padStart(firstLineColumnOffset) + source.body;
|
|
1469
|
+
const lineIndex = sourceLocation.line - 1;
|
|
1470
|
+
const lineOffset = source.locationOffset.line - 1;
|
|
1471
|
+
const lineNum = sourceLocation.line + lineOffset;
|
|
1472
|
+
const columnOffset = sourceLocation.line === 1 ? firstLineColumnOffset : 0;
|
|
1473
|
+
const columnNum = sourceLocation.column + columnOffset;
|
|
1474
|
+
const locationStr = `${source.name}:${lineNum}:${columnNum}\n`;
|
|
1475
|
+
const lines = body.split(/\r\n|[\n\r]/g);
|
|
1476
|
+
const locationLine = lines[lineIndex]; // Special case for minified documents
|
|
1455
1477
|
|
|
1456
1478
|
if (locationLine.length > 120) {
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1479
|
+
const subLineIndex = Math.floor(columnNum / 80);
|
|
1480
|
+
const subLineColumnNum = columnNum % 80;
|
|
1481
|
+
const subLines = [];
|
|
1460
1482
|
|
|
1461
|
-
for (
|
|
1483
|
+
for (let i = 0; i < locationLine.length; i += 80) {
|
|
1462
1484
|
subLines.push(locationLine.slice(i, i + 80));
|
|
1463
1485
|
}
|
|
1464
1486
|
|
|
1465
|
-
return
|
|
1466
|
-
|
|
1467
|
-
|
|
1487
|
+
return (
|
|
1488
|
+
locationStr +
|
|
1489
|
+
printPrefixedLines([
|
|
1490
|
+
[`${lineNum} |`, subLines[0]],
|
|
1491
|
+
...subLines.slice(1, subLineIndex + 1).map((subLine) => ['|', subLine]),
|
|
1492
|
+
['|', '^'.padStart(subLineColumnNum)],
|
|
1493
|
+
['|', subLines[subLineIndex + 1]],
|
|
1494
|
+
])
|
|
1495
|
+
);
|
|
1468
1496
|
}
|
|
1469
1497
|
|
|
1470
|
-
return
|
|
1471
|
-
|
|
1498
|
+
return (
|
|
1499
|
+
locationStr +
|
|
1500
|
+
printPrefixedLines([
|
|
1501
|
+
// Lines specified like this: ["prefix", "string"],
|
|
1502
|
+
[`${lineNum - 1} |`, lines[lineIndex - 1]],
|
|
1503
|
+
[`${lineNum} |`, locationLine],
|
|
1504
|
+
['|', '^'.padStart(columnNum)],
|
|
1505
|
+
[`${lineNum + 1} |`, lines[lineIndex + 1]],
|
|
1506
|
+
])
|
|
1507
|
+
);
|
|
1472
1508
|
}
|
|
1473
1509
|
|
|
1474
1510
|
function printPrefixedLines(lines) {
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
var padLen = Math.max.apply(Math, existingLines.map(function (_ref2) {
|
|
1481
|
-
var prefix = _ref2[0];
|
|
1482
|
-
return prefix.length;
|
|
1483
|
-
}));
|
|
1484
|
-
return existingLines.map(function (_ref3) {
|
|
1485
|
-
var prefix = _ref3[0],
|
|
1486
|
-
line = _ref3[1];
|
|
1487
|
-
return leftPad(padLen, prefix) + (line ? ' | ' + line : ' |');
|
|
1488
|
-
}).join('\n');
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
function whitespace(len) {
|
|
1492
|
-
return Array(len + 1).join(' ');
|
|
1493
|
-
}
|
|
1494
|
-
|
|
1495
|
-
function leftPad(len, str) {
|
|
1496
|
-
return whitespace(len - str.length) + str;
|
|
1511
|
+
const existingLines = lines.filter(([_, line]) => line !== undefined);
|
|
1512
|
+
const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
|
|
1513
|
+
return existingLines
|
|
1514
|
+
.map(([prefix, line]) => prefix.padStart(padLen) + (line ? ' ' + line : ''))
|
|
1515
|
+
.join('\n');
|
|
1497
1516
|
}
|
|
1498
1517
|
|
|
1499
|
-
function
|
|
1500
|
-
|
|
1501
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1502
|
-
|
|
1503
|
-
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); } }
|
|
1504
|
-
|
|
1505
|
-
function _createClass$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1(Constructor, staticProps); return Constructor; }
|
|
1506
|
-
|
|
1507
|
-
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); }
|
|
1508
|
-
|
|
1509
|
-
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); }; }
|
|
1518
|
+
function toNormalizedArgs(args) {
|
|
1519
|
+
const firstArg = args[0];
|
|
1510
1520
|
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
1522
|
-
|
|
1523
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
1521
|
+
if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
|
|
1522
|
+
return {
|
|
1523
|
+
nodes: firstArg,
|
|
1524
|
+
source: args[1],
|
|
1525
|
+
positions: args[2],
|
|
1526
|
+
path: args[3],
|
|
1527
|
+
originalError: args[4],
|
|
1528
|
+
extensions: args[5],
|
|
1529
|
+
};
|
|
1530
|
+
}
|
|
1524
1531
|
|
|
1525
|
-
|
|
1532
|
+
return firstArg;
|
|
1533
|
+
}
|
|
1526
1534
|
/**
|
|
1527
1535
|
* A GraphQLError describes an Error found during the parse, validate, or
|
|
1528
1536
|
* execute phases of performing a GraphQL operation. In addition to a message
|
|
@@ -1530,21 +1538,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
1530
1538
|
* GraphQL document and/or execution result that correspond to the Error.
|
|
1531
1539
|
*/
|
|
1532
1540
|
|
|
1533
|
-
|
|
1534
|
-
_inherits(GraphQLError, _Error);
|
|
1535
|
-
|
|
1536
|
-
var _super = _createSuper(GraphQLError);
|
|
1537
|
-
|
|
1538
|
-
/**
|
|
1539
|
-
* A message describing the Error for debugging purposes.
|
|
1540
|
-
*
|
|
1541
|
-
* Enumerable, and appears in the result of JSON.stringify().
|
|
1542
|
-
*
|
|
1543
|
-
* Note: should be treated as readonly, despite invariant usage.
|
|
1544
|
-
*/
|
|
1545
|
-
|
|
1541
|
+
class GraphQLError extends Error {
|
|
1546
1542
|
/**
|
|
1547
|
-
* An array of { line, column } locations within the source GraphQL document
|
|
1543
|
+
* An array of `{ line, column }` locations within the source GraphQL document
|
|
1548
1544
|
* which correspond to this error.
|
|
1549
1545
|
*
|
|
1550
1546
|
* Errors during validation often contain multiple locations, for example to
|
|
@@ -1584,184 +1580,163 @@ var GraphQLError = /*#__PURE__*/function (_Error) {
|
|
|
1584
1580
|
/**
|
|
1585
1581
|
* Extension fields to add to the formatted error.
|
|
1586
1582
|
*/
|
|
1587
|
-
function GraphQLError(message, nodes, source, positions, path, originalError, extensions) {
|
|
1588
|
-
var _locations2, _source2, _positions2, _extensions2;
|
|
1589
|
-
|
|
1590
|
-
var _this;
|
|
1591
|
-
|
|
1592
|
-
_classCallCheck(this, GraphQLError);
|
|
1593
|
-
|
|
1594
|
-
_this = _super.call(this, message); // Compute list of blame nodes.
|
|
1595
|
-
|
|
1596
|
-
var _nodes = Array.isArray(nodes) ? nodes.length !== 0 ? nodes : undefined : nodes ? [nodes] : undefined; // Compute locations in the source for the given nodes/positions.
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
var _source = source;
|
|
1600
|
-
|
|
1601
|
-
if (!_source && _nodes) {
|
|
1602
|
-
var _nodes$0$loc;
|
|
1603
|
-
|
|
1604
|
-
_source = (_nodes$0$loc = _nodes[0].loc) === null || _nodes$0$loc === void 0 ? void 0 : _nodes$0$loc.source;
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
var _positions = positions;
|
|
1608
|
-
|
|
1609
|
-
if (!_positions && _nodes) {
|
|
1610
|
-
_positions = _nodes.reduce(function (list, node) {
|
|
1611
|
-
if (node.loc) {
|
|
1612
|
-
list.push(node.loc.start);
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
return list;
|
|
1616
|
-
}, []);
|
|
1617
|
-
}
|
|
1618
|
-
|
|
1619
|
-
if (_positions && _positions.length === 0) {
|
|
1620
|
-
_positions = undefined;
|
|
1621
|
-
}
|
|
1622
|
-
|
|
1623
|
-
var _locations;
|
|
1624
|
-
|
|
1625
|
-
if (positions && source) {
|
|
1626
|
-
_locations = positions.map(function (pos) {
|
|
1627
|
-
return getLocation(source, pos);
|
|
1628
|
-
});
|
|
1629
|
-
} else if (_nodes) {
|
|
1630
|
-
_locations = _nodes.reduce(function (list, node) {
|
|
1631
|
-
if (node.loc) {
|
|
1632
|
-
list.push(getLocation(node.loc.source, node.loc.start));
|
|
1633
|
-
}
|
|
1634
1583
|
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
var
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1584
|
+
/**
|
|
1585
|
+
* @deprecated Please use the `GraphQLErrorArgs` constructor overload instead.
|
|
1586
|
+
*/
|
|
1587
|
+
constructor(message, ...rawArgs) {
|
|
1588
|
+
var _this$nodes, _nodeLocations$, _ref;
|
|
1589
|
+
|
|
1590
|
+
const { nodes, source, positions, path, originalError, extensions } =
|
|
1591
|
+
toNormalizedArgs(rawArgs);
|
|
1592
|
+
super(message);
|
|
1593
|
+
this.name = 'GraphQLError';
|
|
1594
|
+
this.path = path !== null && path !== void 0 ? path : undefined;
|
|
1595
|
+
this.originalError =
|
|
1596
|
+
originalError !== null && originalError !== void 0
|
|
1597
|
+
? originalError
|
|
1598
|
+
: undefined; // Compute list of blame nodes.
|
|
1599
|
+
|
|
1600
|
+
this.nodes = undefinedIfEmpty(
|
|
1601
|
+
Array.isArray(nodes) ? nodes : nodes ? [nodes] : undefined,
|
|
1602
|
+
);
|
|
1603
|
+
const nodeLocations = undefinedIfEmpty(
|
|
1604
|
+
(_this$nodes = this.nodes) === null || _this$nodes === void 0
|
|
1605
|
+
? void 0
|
|
1606
|
+
: _this$nodes.map((node) => node.loc).filter((loc) => loc != null),
|
|
1607
|
+
); // Compute locations in the source for the given nodes/positions.
|
|
1608
|
+
|
|
1609
|
+
this.source =
|
|
1610
|
+
source !== null && source !== void 0
|
|
1611
|
+
? source
|
|
1612
|
+
: nodeLocations === null || nodeLocations === void 0
|
|
1613
|
+
? void 0
|
|
1614
|
+
: (_nodeLocations$ = nodeLocations[0]) === null ||
|
|
1615
|
+
_nodeLocations$ === void 0
|
|
1616
|
+
? void 0
|
|
1617
|
+
: _nodeLocations$.source;
|
|
1618
|
+
this.positions =
|
|
1619
|
+
positions !== null && positions !== void 0
|
|
1620
|
+
? positions
|
|
1621
|
+
: nodeLocations === null || nodeLocations === void 0
|
|
1622
|
+
? void 0
|
|
1623
|
+
: nodeLocations.map((loc) => loc.start);
|
|
1624
|
+
this.locations =
|
|
1625
|
+
positions && source
|
|
1626
|
+
? positions.map((pos) => getLocation(source, pos))
|
|
1627
|
+
: nodeLocations === null || nodeLocations === void 0
|
|
1628
|
+
? void 0
|
|
1629
|
+
: nodeLocations.map((loc) => getLocation(loc.source, loc.start));
|
|
1630
|
+
const originalExtensions = isObjectLike(
|
|
1631
|
+
originalError === null || originalError === void 0
|
|
1632
|
+
? void 0
|
|
1633
|
+
: originalError.extensions,
|
|
1634
|
+
)
|
|
1635
|
+
? originalError === null || originalError === void 0
|
|
1636
|
+
? void 0
|
|
1637
|
+
: originalError.extensions
|
|
1638
|
+
: undefined;
|
|
1639
|
+
this.extensions =
|
|
1640
|
+
(_ref =
|
|
1641
|
+
extensions !== null && extensions !== void 0
|
|
1642
|
+
? extensions
|
|
1643
|
+
: originalExtensions) !== null && _ref !== void 0
|
|
1644
|
+
? _ref
|
|
1645
|
+
: Object.create(null); // Only properties prescribed by the spec should be enumerable.
|
|
1646
|
+
// Keep the rest as non-enumerable.
|
|
1647
|
+
|
|
1648
|
+
Object.defineProperties(this, {
|
|
1653
1649
|
message: {
|
|
1654
|
-
|
|
1655
|
-
// By being enumerable, JSON.stringify will include `message` in the
|
|
1656
|
-
// resulting output. This ensures that the simplest possible GraphQL
|
|
1657
|
-
// service adheres to the spec.
|
|
1650
|
+
writable: true,
|
|
1658
1651
|
enumerable: true,
|
|
1659
|
-
writable: true
|
|
1660
1652
|
},
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
// in JSON.stringify() when not provided.
|
|
1664
|
-
value: (_locations2 = _locations) !== null && _locations2 !== void 0 ? _locations2 : undefined,
|
|
1665
|
-
// By being enumerable, JSON.stringify will include `locations` in the
|
|
1666
|
-
// resulting output. This ensures that the simplest possible GraphQL
|
|
1667
|
-
// service adheres to the spec.
|
|
1668
|
-
enumerable: _locations != null
|
|
1669
|
-
},
|
|
1670
|
-
path: {
|
|
1671
|
-
// Coercing falsy values to undefined ensures they will not be included
|
|
1672
|
-
// in JSON.stringify() when not provided.
|
|
1673
|
-
value: path !== null && path !== void 0 ? path : undefined,
|
|
1674
|
-
// By being enumerable, JSON.stringify will include `path` in the
|
|
1675
|
-
// resulting output. This ensures that the simplest possible GraphQL
|
|
1676
|
-
// service adheres to the spec.
|
|
1677
|
-
enumerable: path != null
|
|
1653
|
+
name: {
|
|
1654
|
+
enumerable: false,
|
|
1678
1655
|
},
|
|
1679
1656
|
nodes: {
|
|
1680
|
-
|
|
1657
|
+
enumerable: false,
|
|
1681
1658
|
},
|
|
1682
1659
|
source: {
|
|
1683
|
-
|
|
1660
|
+
enumerable: false,
|
|
1684
1661
|
},
|
|
1685
1662
|
positions: {
|
|
1686
|
-
|
|
1663
|
+
enumerable: false,
|
|
1687
1664
|
},
|
|
1688
1665
|
originalError: {
|
|
1689
|
-
|
|
1666
|
+
enumerable: false,
|
|
1690
1667
|
},
|
|
1691
|
-
extensions: {
|
|
1692
|
-
// Coercing falsy values to undefined ensures they will not be included
|
|
1693
|
-
// in JSON.stringify() when not provided.
|
|
1694
|
-
value: (_extensions2 = _extensions) !== null && _extensions2 !== void 0 ? _extensions2 : undefined,
|
|
1695
|
-
// By being enumerable, JSON.stringify will include `path` in the
|
|
1696
|
-
// resulting output. This ensures that the simplest possible GraphQL
|
|
1697
|
-
// service adheres to the spec.
|
|
1698
|
-
enumerable: _extensions != null
|
|
1699
|
-
}
|
|
1700
1668
|
}); // Include (non-enumerable) stack trace.
|
|
1701
1669
|
|
|
1702
|
-
|
|
1703
|
-
|
|
1670
|
+
/* c8 ignore start */
|
|
1671
|
+
// FIXME: https://github.com/graphql/graphql-js/issues/2317
|
|
1672
|
+
|
|
1673
|
+
if (
|
|
1674
|
+
originalError !== null &&
|
|
1675
|
+
originalError !== void 0 &&
|
|
1676
|
+
originalError.stack
|
|
1677
|
+
) {
|
|
1678
|
+
Object.defineProperty(this, 'stack', {
|
|
1704
1679
|
value: originalError.stack,
|
|
1705
1680
|
writable: true,
|
|
1706
|
-
configurable: true
|
|
1681
|
+
configurable: true,
|
|
1707
1682
|
});
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
if (Error.captureStackTrace) {
|
|
1713
|
-
Error.captureStackTrace(_assertThisInitialized(_this), GraphQLError);
|
|
1683
|
+
} else if (Error.captureStackTrace) {
|
|
1684
|
+
Error.captureStackTrace(this, GraphQLError);
|
|
1714
1685
|
} else {
|
|
1715
|
-
Object.defineProperty(
|
|
1686
|
+
Object.defineProperty(this, 'stack', {
|
|
1716
1687
|
value: Error().stack,
|
|
1717
1688
|
writable: true,
|
|
1718
|
-
configurable: true
|
|
1689
|
+
configurable: true,
|
|
1719
1690
|
});
|
|
1720
1691
|
}
|
|
1692
|
+
/* c8 ignore stop */
|
|
1693
|
+
}
|
|
1721
1694
|
|
|
1722
|
-
|
|
1695
|
+
get [Symbol.toStringTag]() {
|
|
1696
|
+
return 'GraphQLError';
|
|
1723
1697
|
}
|
|
1724
1698
|
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1699
|
+
toString() {
|
|
1700
|
+
let output = this.message;
|
|
1701
|
+
|
|
1702
|
+
if (this.nodes) {
|
|
1703
|
+
for (const node of this.nodes) {
|
|
1704
|
+
if (node.loc) {
|
|
1705
|
+
output += '\n\n' + printLocation(node.loc);
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
} else if (this.source && this.locations) {
|
|
1709
|
+
for (const location of this.locations) {
|
|
1710
|
+
output += '\n\n' + printSourceLocation(this.source, location);
|
|
1711
|
+
}
|
|
1736
1712
|
}
|
|
1737
|
-
}]);
|
|
1738
1713
|
|
|
1739
|
-
|
|
1740
|
-
}
|
|
1741
|
-
/**
|
|
1742
|
-
* Prints a GraphQLError to a string, representing useful location information
|
|
1743
|
-
* about the error's position in the source.
|
|
1744
|
-
*/
|
|
1714
|
+
return output;
|
|
1715
|
+
}
|
|
1745
1716
|
|
|
1746
|
-
|
|
1747
|
-
|
|
1717
|
+
toJSON() {
|
|
1718
|
+
const formattedError = {
|
|
1719
|
+
message: this.message,
|
|
1720
|
+
};
|
|
1748
1721
|
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1722
|
+
if (this.locations != null) {
|
|
1723
|
+
formattedError.locations = this.locations;
|
|
1724
|
+
}
|
|
1752
1725
|
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
}
|
|
1726
|
+
if (this.path != null) {
|
|
1727
|
+
formattedError.path = this.path;
|
|
1756
1728
|
}
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
output += '\n\n' + printSourceLocation(error.source, location);
|
|
1729
|
+
|
|
1730
|
+
if (this.extensions != null && Object.keys(this.extensions).length > 0) {
|
|
1731
|
+
formattedError.extensions = this.extensions;
|
|
1761
1732
|
}
|
|
1733
|
+
|
|
1734
|
+
return formattedError;
|
|
1762
1735
|
}
|
|
1736
|
+
}
|
|
1763
1737
|
|
|
1764
|
-
|
|
1738
|
+
function undefinedIfEmpty(array) {
|
|
1739
|
+
return array === undefined || array.length === 0 ? undefined : array;
|
|
1765
1740
|
}
|
|
1766
1741
|
|
|
1767
1742
|
/**
|
|
@@ -1770,103 +1745,16 @@ function printError(error) {
|
|
|
1770
1745
|
*/
|
|
1771
1746
|
|
|
1772
1747
|
function syntaxError(source, position, description) {
|
|
1773
|
-
return new GraphQLError(
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
/**
|
|
1777
|
-
* The set of allowed kind values for AST nodes.
|
|
1778
|
-
*/
|
|
1779
|
-
var Kind = Object.freeze({
|
|
1780
|
-
// Name
|
|
1781
|
-
NAME: 'Name',
|
|
1782
|
-
// Document
|
|
1783
|
-
DOCUMENT: 'Document',
|
|
1784
|
-
OPERATION_DEFINITION: 'OperationDefinition',
|
|
1785
|
-
VARIABLE_DEFINITION: 'VariableDefinition',
|
|
1786
|
-
SELECTION_SET: 'SelectionSet',
|
|
1787
|
-
FIELD: 'Field',
|
|
1788
|
-
ARGUMENT: 'Argument',
|
|
1789
|
-
// Fragments
|
|
1790
|
-
FRAGMENT_SPREAD: 'FragmentSpread',
|
|
1791
|
-
INLINE_FRAGMENT: 'InlineFragment',
|
|
1792
|
-
FRAGMENT_DEFINITION: 'FragmentDefinition',
|
|
1793
|
-
// Values
|
|
1794
|
-
VARIABLE: 'Variable',
|
|
1795
|
-
INT: 'IntValue',
|
|
1796
|
-
FLOAT: 'FloatValue',
|
|
1797
|
-
STRING: 'StringValue',
|
|
1798
|
-
BOOLEAN: 'BooleanValue',
|
|
1799
|
-
NULL: 'NullValue',
|
|
1800
|
-
ENUM: 'EnumValue',
|
|
1801
|
-
LIST: 'ListValue',
|
|
1802
|
-
OBJECT: 'ObjectValue',
|
|
1803
|
-
OBJECT_FIELD: 'ObjectField',
|
|
1804
|
-
// Directives
|
|
1805
|
-
DIRECTIVE: 'Directive',
|
|
1806
|
-
// Types
|
|
1807
|
-
NAMED_TYPE: 'NamedType',
|
|
1808
|
-
LIST_TYPE: 'ListType',
|
|
1809
|
-
NON_NULL_TYPE: 'NonNullType',
|
|
1810
|
-
// Type System Definitions
|
|
1811
|
-
SCHEMA_DEFINITION: 'SchemaDefinition',
|
|
1812
|
-
OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition',
|
|
1813
|
-
// Type Definitions
|
|
1814
|
-
SCALAR_TYPE_DEFINITION: 'ScalarTypeDefinition',
|
|
1815
|
-
OBJECT_TYPE_DEFINITION: 'ObjectTypeDefinition',
|
|
1816
|
-
FIELD_DEFINITION: 'FieldDefinition',
|
|
1817
|
-
INPUT_VALUE_DEFINITION: 'InputValueDefinition',
|
|
1818
|
-
INTERFACE_TYPE_DEFINITION: 'InterfaceTypeDefinition',
|
|
1819
|
-
UNION_TYPE_DEFINITION: 'UnionTypeDefinition',
|
|
1820
|
-
ENUM_TYPE_DEFINITION: 'EnumTypeDefinition',
|
|
1821
|
-
ENUM_VALUE_DEFINITION: 'EnumValueDefinition',
|
|
1822
|
-
INPUT_OBJECT_TYPE_DEFINITION: 'InputObjectTypeDefinition',
|
|
1823
|
-
// Directive Definitions
|
|
1824
|
-
DIRECTIVE_DEFINITION: 'DirectiveDefinition',
|
|
1825
|
-
// Type System Extensions
|
|
1826
|
-
SCHEMA_EXTENSION: 'SchemaExtension',
|
|
1827
|
-
// Type Extensions
|
|
1828
|
-
SCALAR_TYPE_EXTENSION: 'ScalarTypeExtension',
|
|
1829
|
-
OBJECT_TYPE_EXTENSION: 'ObjectTypeExtension',
|
|
1830
|
-
INTERFACE_TYPE_EXTENSION: 'InterfaceTypeExtension',
|
|
1831
|
-
UNION_TYPE_EXTENSION: 'UnionTypeExtension',
|
|
1832
|
-
ENUM_TYPE_EXTENSION: 'EnumTypeExtension',
|
|
1833
|
-
INPUT_OBJECT_TYPE_EXTENSION: 'InputObjectTypeExtension'
|
|
1834
|
-
});
|
|
1835
|
-
/**
|
|
1836
|
-
* The enum type representing the possible kind values of AST nodes.
|
|
1837
|
-
*/
|
|
1838
|
-
|
|
1839
|
-
function invariant(condition, message) {
|
|
1840
|
-
var booleanCondition = Boolean(condition); // istanbul ignore else (See transformation done in './resources/inlineInvariant.js')
|
|
1841
|
-
|
|
1842
|
-
if (!booleanCondition) {
|
|
1843
|
-
throw new Error(message != null ? message : 'Unexpected invariant triggered.');
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
|
|
1847
|
-
// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
1848
|
-
var nodejsCustomInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined;
|
|
1849
|
-
var nodejsCustomInspectSymbol$1 = nodejsCustomInspectSymbol;
|
|
1850
|
-
|
|
1851
|
-
/**
|
|
1852
|
-
* The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`
|
|
1853
|
-
*/
|
|
1854
|
-
|
|
1855
|
-
function defineInspect(classObject) {
|
|
1856
|
-
var fn = classObject.prototype.toJSON;
|
|
1857
|
-
typeof fn === 'function' || invariant(0);
|
|
1858
|
-
classObject.prototype.inspect = fn; // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
1859
|
-
|
|
1860
|
-
if (nodejsCustomInspectSymbol$1) {
|
|
1861
|
-
classObject.prototype[nodejsCustomInspectSymbol$1] = fn;
|
|
1862
|
-
}
|
|
1748
|
+
return new GraphQLError(`Syntax Error: ${description}`, undefined, source, [
|
|
1749
|
+
position,
|
|
1750
|
+
]);
|
|
1863
1751
|
}
|
|
1864
1752
|
|
|
1865
1753
|
/**
|
|
1866
1754
|
* Contains a range of UTF-8 character offsets and token references that
|
|
1867
1755
|
* identify the region of the source from which the AST derived.
|
|
1868
1756
|
*/
|
|
1869
|
-
|
|
1757
|
+
class Location {
|
|
1870
1758
|
/**
|
|
1871
1759
|
* The character offset at which this Node begins.
|
|
1872
1760
|
*/
|
|
@@ -1886,7 +1774,7 @@ var Location = /*#__PURE__*/function () {
|
|
|
1886
1774
|
/**
|
|
1887
1775
|
* The Source document the AST represents.
|
|
1888
1776
|
*/
|
|
1889
|
-
|
|
1777
|
+
constructor(startToken, endToken, source) {
|
|
1890
1778
|
this.start = startToken.start;
|
|
1891
1779
|
this.end = endToken.end;
|
|
1892
1780
|
this.startToken = startToken;
|
|
@@ -1894,25 +1782,23 @@ var Location = /*#__PURE__*/function () {
|
|
|
1894
1782
|
this.source = source;
|
|
1895
1783
|
}
|
|
1896
1784
|
|
|
1897
|
-
|
|
1785
|
+
get [Symbol.toStringTag]() {
|
|
1786
|
+
return 'Location';
|
|
1787
|
+
}
|
|
1898
1788
|
|
|
1899
|
-
|
|
1789
|
+
toJSON() {
|
|
1900
1790
|
return {
|
|
1901
1791
|
start: this.start,
|
|
1902
|
-
end: this.end
|
|
1792
|
+
end: this.end,
|
|
1903
1793
|
};
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
return Location;
|
|
1907
|
-
}(); // Print a simplified form when appearing in `inspect` and `util.inspect`.
|
|
1908
|
-
|
|
1909
|
-
defineInspect(Location);
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1910
1796
|
/**
|
|
1911
1797
|
* Represents a range of characters represented by a lexical token
|
|
1912
1798
|
* within a Source.
|
|
1913
1799
|
*/
|
|
1914
1800
|
|
|
1915
|
-
|
|
1801
|
+
class Token {
|
|
1916
1802
|
/**
|
|
1917
1803
|
* The kind of Token.
|
|
1918
1804
|
*/
|
|
@@ -1935,6 +1821,9 @@ var Token = /*#__PURE__*/function () {
|
|
|
1935
1821
|
|
|
1936
1822
|
/**
|
|
1937
1823
|
* For non-punctuation tokens, represents the interpreted value of the token.
|
|
1824
|
+
*
|
|
1825
|
+
* Note: is undefined for punctuation tokens, but typed as string for
|
|
1826
|
+
* convenience in the parser.
|
|
1938
1827
|
*/
|
|
1939
1828
|
|
|
1940
1829
|
/**
|
|
@@ -1942,403 +1831,288 @@ var Token = /*#__PURE__*/function () {
|
|
|
1942
1831
|
* including ignored tokens. <SOF> is always the first node and <EOF>
|
|
1943
1832
|
* the last.
|
|
1944
1833
|
*/
|
|
1945
|
-
|
|
1834
|
+
constructor(kind, start, end, line, column, value) {
|
|
1946
1835
|
this.kind = kind;
|
|
1947
1836
|
this.start = start;
|
|
1948
1837
|
this.end = end;
|
|
1949
1838
|
this.line = line;
|
|
1950
|
-
this.column = column;
|
|
1839
|
+
this.column = column; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1840
|
+
|
|
1951
1841
|
this.value = value;
|
|
1952
|
-
this.prev =
|
|
1842
|
+
this.prev = null;
|
|
1953
1843
|
this.next = null;
|
|
1954
1844
|
}
|
|
1955
1845
|
|
|
1956
|
-
|
|
1846
|
+
get [Symbol.toStringTag]() {
|
|
1847
|
+
return 'Token';
|
|
1848
|
+
}
|
|
1957
1849
|
|
|
1958
|
-
|
|
1850
|
+
toJSON() {
|
|
1959
1851
|
return {
|
|
1960
1852
|
kind: this.kind,
|
|
1961
1853
|
value: this.value,
|
|
1962
1854
|
line: this.line,
|
|
1963
|
-
column: this.column
|
|
1855
|
+
column: this.column,
|
|
1964
1856
|
};
|
|
1965
|
-
}
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
/** Name */
|
|
1860
|
+
|
|
1861
|
+
let OperationTypeNode;
|
|
1966
1862
|
|
|
1967
|
-
|
|
1968
|
-
|
|
1863
|
+
(function (OperationTypeNode) {
|
|
1864
|
+
OperationTypeNode['QUERY'] = 'query';
|
|
1865
|
+
OperationTypeNode['MUTATION'] = 'mutation';
|
|
1866
|
+
OperationTypeNode['SUBSCRIPTION'] = 'subscription';
|
|
1867
|
+
})(OperationTypeNode || (OperationTypeNode = {}));
|
|
1969
1868
|
|
|
1970
|
-
defineInspect(Token);
|
|
1971
1869
|
/**
|
|
1972
|
-
* The
|
|
1870
|
+
* The set of allowed directive location values.
|
|
1871
|
+
*/
|
|
1872
|
+
let DirectiveLocation;
|
|
1873
|
+
/**
|
|
1874
|
+
* The enum type representing the directive location values.
|
|
1875
|
+
*
|
|
1876
|
+
* @deprecated Please use `DirectiveLocation`. Will be remove in v17.
|
|
1973
1877
|
*/
|
|
1974
1878
|
|
|
1879
|
+
(function (DirectiveLocation) {
|
|
1880
|
+
DirectiveLocation['QUERY'] = 'QUERY';
|
|
1881
|
+
DirectiveLocation['MUTATION'] = 'MUTATION';
|
|
1882
|
+
DirectiveLocation['SUBSCRIPTION'] = 'SUBSCRIPTION';
|
|
1883
|
+
DirectiveLocation['FIELD'] = 'FIELD';
|
|
1884
|
+
DirectiveLocation['FRAGMENT_DEFINITION'] = 'FRAGMENT_DEFINITION';
|
|
1885
|
+
DirectiveLocation['FRAGMENT_SPREAD'] = 'FRAGMENT_SPREAD';
|
|
1886
|
+
DirectiveLocation['INLINE_FRAGMENT'] = 'INLINE_FRAGMENT';
|
|
1887
|
+
DirectiveLocation['VARIABLE_DEFINITION'] = 'VARIABLE_DEFINITION';
|
|
1888
|
+
DirectiveLocation['SCHEMA'] = 'SCHEMA';
|
|
1889
|
+
DirectiveLocation['SCALAR'] = 'SCALAR';
|
|
1890
|
+
DirectiveLocation['OBJECT'] = 'OBJECT';
|
|
1891
|
+
DirectiveLocation['FIELD_DEFINITION'] = 'FIELD_DEFINITION';
|
|
1892
|
+
DirectiveLocation['ARGUMENT_DEFINITION'] = 'ARGUMENT_DEFINITION';
|
|
1893
|
+
DirectiveLocation['INTERFACE'] = 'INTERFACE';
|
|
1894
|
+
DirectiveLocation['UNION'] = 'UNION';
|
|
1895
|
+
DirectiveLocation['ENUM'] = 'ENUM';
|
|
1896
|
+
DirectiveLocation['ENUM_VALUE'] = 'ENUM_VALUE';
|
|
1897
|
+
DirectiveLocation['INPUT_OBJECT'] = 'INPUT_OBJECT';
|
|
1898
|
+
DirectiveLocation['INPUT_FIELD_DEFINITION'] = 'INPUT_FIELD_DEFINITION';
|
|
1899
|
+
})(DirectiveLocation || (DirectiveLocation = {}));
|
|
1900
|
+
|
|
1975
1901
|
/**
|
|
1976
|
-
*
|
|
1977
|
-
* lexer emits.
|
|
1902
|
+
* The set of allowed kind values for AST nodes.
|
|
1978
1903
|
*/
|
|
1979
|
-
|
|
1980
|
-
SOF: '<SOF>',
|
|
1981
|
-
EOF: '<EOF>',
|
|
1982
|
-
BANG: '!',
|
|
1983
|
-
DOLLAR: '$',
|
|
1984
|
-
AMP: '&',
|
|
1985
|
-
PAREN_L: '(',
|
|
1986
|
-
PAREN_R: ')',
|
|
1987
|
-
SPREAD: '...',
|
|
1988
|
-
COLON: ':',
|
|
1989
|
-
EQUALS: '=',
|
|
1990
|
-
AT: '@',
|
|
1991
|
-
BRACKET_L: '[',
|
|
1992
|
-
BRACKET_R: ']',
|
|
1993
|
-
BRACE_L: '{',
|
|
1994
|
-
PIPE: '|',
|
|
1995
|
-
BRACE_R: '}',
|
|
1996
|
-
NAME: 'Name',
|
|
1997
|
-
INT: 'Int',
|
|
1998
|
-
FLOAT: 'Float',
|
|
1999
|
-
STRING: 'String',
|
|
2000
|
-
BLOCK_STRING: 'BlockString',
|
|
2001
|
-
COMMENT: 'Comment'
|
|
2002
|
-
});
|
|
1904
|
+
let Kind;
|
|
2003
1905
|
/**
|
|
2004
|
-
* The enum type representing the
|
|
1906
|
+
* The enum type representing the possible kind values of AST nodes.
|
|
1907
|
+
*
|
|
1908
|
+
* @deprecated Please use `Kind`. Will be remove in v17.
|
|
2005
1909
|
*/
|
|
2006
1910
|
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
1911
|
+
(function (Kind) {
|
|
1912
|
+
Kind['NAME'] = 'Name';
|
|
1913
|
+
Kind['DOCUMENT'] = 'Document';
|
|
1914
|
+
Kind['OPERATION_DEFINITION'] = 'OperationDefinition';
|
|
1915
|
+
Kind['VARIABLE_DEFINITION'] = 'VariableDefinition';
|
|
1916
|
+
Kind['SELECTION_SET'] = 'SelectionSet';
|
|
1917
|
+
Kind['FIELD'] = 'Field';
|
|
1918
|
+
Kind['ARGUMENT'] = 'Argument';
|
|
1919
|
+
Kind['FRAGMENT_SPREAD'] = 'FragmentSpread';
|
|
1920
|
+
Kind['INLINE_FRAGMENT'] = 'InlineFragment';
|
|
1921
|
+
Kind['FRAGMENT_DEFINITION'] = 'FragmentDefinition';
|
|
1922
|
+
Kind['VARIABLE'] = 'Variable';
|
|
1923
|
+
Kind['INT'] = 'IntValue';
|
|
1924
|
+
Kind['FLOAT'] = 'FloatValue';
|
|
1925
|
+
Kind['STRING'] = 'StringValue';
|
|
1926
|
+
Kind['BOOLEAN'] = 'BooleanValue';
|
|
1927
|
+
Kind['NULL'] = 'NullValue';
|
|
1928
|
+
Kind['ENUM'] = 'EnumValue';
|
|
1929
|
+
Kind['LIST'] = 'ListValue';
|
|
1930
|
+
Kind['OBJECT'] = 'ObjectValue';
|
|
1931
|
+
Kind['OBJECT_FIELD'] = 'ObjectField';
|
|
1932
|
+
Kind['DIRECTIVE'] = 'Directive';
|
|
1933
|
+
Kind['NAMED_TYPE'] = 'NamedType';
|
|
1934
|
+
Kind['LIST_TYPE'] = 'ListType';
|
|
1935
|
+
Kind['NON_NULL_TYPE'] = 'NonNullType';
|
|
1936
|
+
Kind['SCHEMA_DEFINITION'] = 'SchemaDefinition';
|
|
1937
|
+
Kind['OPERATION_TYPE_DEFINITION'] = 'OperationTypeDefinition';
|
|
1938
|
+
Kind['SCALAR_TYPE_DEFINITION'] = 'ScalarTypeDefinition';
|
|
1939
|
+
Kind['OBJECT_TYPE_DEFINITION'] = 'ObjectTypeDefinition';
|
|
1940
|
+
Kind['FIELD_DEFINITION'] = 'FieldDefinition';
|
|
1941
|
+
Kind['INPUT_VALUE_DEFINITION'] = 'InputValueDefinition';
|
|
1942
|
+
Kind['INTERFACE_TYPE_DEFINITION'] = 'InterfaceTypeDefinition';
|
|
1943
|
+
Kind['UNION_TYPE_DEFINITION'] = 'UnionTypeDefinition';
|
|
1944
|
+
Kind['ENUM_TYPE_DEFINITION'] = 'EnumTypeDefinition';
|
|
1945
|
+
Kind['ENUM_VALUE_DEFINITION'] = 'EnumValueDefinition';
|
|
1946
|
+
Kind['INPUT_OBJECT_TYPE_DEFINITION'] = 'InputObjectTypeDefinition';
|
|
1947
|
+
Kind['DIRECTIVE_DEFINITION'] = 'DirectiveDefinition';
|
|
1948
|
+
Kind['SCHEMA_EXTENSION'] = 'SchemaExtension';
|
|
1949
|
+
Kind['SCALAR_TYPE_EXTENSION'] = 'ScalarTypeExtension';
|
|
1950
|
+
Kind['OBJECT_TYPE_EXTENSION'] = 'ObjectTypeExtension';
|
|
1951
|
+
Kind['INTERFACE_TYPE_EXTENSION'] = 'InterfaceTypeExtension';
|
|
1952
|
+
Kind['UNION_TYPE_EXTENSION'] = 'UnionTypeExtension';
|
|
1953
|
+
Kind['ENUM_TYPE_EXTENSION'] = 'EnumTypeExtension';
|
|
1954
|
+
Kind['INPUT_OBJECT_TYPE_EXTENSION'] = 'InputObjectTypeExtension';
|
|
1955
|
+
})(Kind || (Kind = {}));
|
|
1956
|
+
|
|
2010
1957
|
/**
|
|
2011
|
-
*
|
|
1958
|
+
* ```
|
|
1959
|
+
* WhiteSpace ::
|
|
1960
|
+
* - "Horizontal Tab (U+0009)"
|
|
1961
|
+
* - "Space (U+0020)"
|
|
1962
|
+
* ```
|
|
1963
|
+
* @internal
|
|
2012
1964
|
*/
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
return formatValue(value, []);
|
|
1965
|
+
function isWhiteSpace(code) {
|
|
1966
|
+
return code === 0x0009 || code === 0x0020;
|
|
2016
1967
|
}
|
|
1968
|
+
/**
|
|
1969
|
+
* ```
|
|
1970
|
+
* Digit :: one of
|
|
1971
|
+
* - `0` `1` `2` `3` `4` `5` `6` `7` `8` `9`
|
|
1972
|
+
* ```
|
|
1973
|
+
* @internal
|
|
1974
|
+
*/
|
|
2017
1975
|
|
|
2018
|
-
function
|
|
2019
|
-
|
|
2020
|
-
case 'string':
|
|
2021
|
-
return JSON.stringify(value);
|
|
2022
|
-
|
|
2023
|
-
case 'function':
|
|
2024
|
-
return value.name ? "[function ".concat(value.name, "]") : '[function]';
|
|
2025
|
-
|
|
2026
|
-
case 'object':
|
|
2027
|
-
if (value === null) {
|
|
2028
|
-
return 'null';
|
|
2029
|
-
}
|
|
2030
|
-
|
|
2031
|
-
return formatObjectValue(value, seenValues);
|
|
2032
|
-
|
|
2033
|
-
default:
|
|
2034
|
-
return String(value);
|
|
2035
|
-
}
|
|
1976
|
+
function isDigit(code) {
|
|
1977
|
+
return code >= 0x0030 && code <= 0x0039;
|
|
2036
1978
|
}
|
|
1979
|
+
/**
|
|
1980
|
+
* ```
|
|
1981
|
+
* Letter :: one of
|
|
1982
|
+
* - `A` `B` `C` `D` `E` `F` `G` `H` `I` `J` `K` `L` `M`
|
|
1983
|
+
* - `N` `O` `P` `Q` `R` `S` `T` `U` `V` `W` `X` `Y` `Z`
|
|
1984
|
+
* - `a` `b` `c` `d` `e` `f` `g` `h` `i` `j` `k` `l` `m`
|
|
1985
|
+
* - `n` `o` `p` `q` `r` `s` `t` `u` `v` `w` `x` `y` `z`
|
|
1986
|
+
* ```
|
|
1987
|
+
* @internal
|
|
1988
|
+
*/
|
|
2037
1989
|
|
|
2038
|
-
function
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
var seenValues = [].concat(previouslySeenValues, [value]);
|
|
2044
|
-
var customInspectFn = getCustomFn(value);
|
|
2045
|
-
|
|
2046
|
-
if (customInspectFn !== undefined) {
|
|
2047
|
-
var customValue = customInspectFn.call(value); // check for infinite recursion
|
|
2048
|
-
|
|
2049
|
-
if (customValue !== value) {
|
|
2050
|
-
return typeof customValue === 'string' ? customValue : formatValue(customValue, seenValues);
|
|
2051
|
-
}
|
|
2052
|
-
} else if (Array.isArray(value)) {
|
|
2053
|
-
return formatArray(value, seenValues);
|
|
2054
|
-
}
|
|
2055
|
-
|
|
2056
|
-
return formatObject(value, seenValues);
|
|
1990
|
+
function isLetter(code) {
|
|
1991
|
+
return (
|
|
1992
|
+
(code >= 0x0061 && code <= 0x007a) || // A-Z
|
|
1993
|
+
(code >= 0x0041 && code <= 0x005a) // a-z
|
|
1994
|
+
);
|
|
2057
1995
|
}
|
|
1996
|
+
/**
|
|
1997
|
+
* ```
|
|
1998
|
+
* NameStart ::
|
|
1999
|
+
* - Letter
|
|
2000
|
+
* - `_`
|
|
2001
|
+
* ```
|
|
2002
|
+
* @internal
|
|
2003
|
+
*/
|
|
2058
2004
|
|
|
2059
|
-
function
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2005
|
+
function isNameStart(code) {
|
|
2006
|
+
return isLetter(code) || code === 0x005f;
|
|
2007
|
+
}
|
|
2008
|
+
/**
|
|
2009
|
+
* ```
|
|
2010
|
+
* NameContinue ::
|
|
2011
|
+
* - Letter
|
|
2012
|
+
* - Digit
|
|
2013
|
+
* - `_`
|
|
2014
|
+
* ```
|
|
2015
|
+
* @internal
|
|
2016
|
+
*/
|
|
2069
2017
|
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
return key + ': ' + value;
|
|
2073
|
-
});
|
|
2074
|
-
return '{ ' + properties.join(', ') + ' }';
|
|
2018
|
+
function isNameContinue(code) {
|
|
2019
|
+
return isLetter(code) || isDigit(code) || code === 0x005f;
|
|
2075
2020
|
}
|
|
2076
2021
|
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2022
|
+
/**
|
|
2023
|
+
* Produces the value of a block string from its parsed raw value, similar to
|
|
2024
|
+
* CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc.
|
|
2025
|
+
*
|
|
2026
|
+
* This implements the GraphQL spec's BlockStringValue() static algorithm.
|
|
2027
|
+
*
|
|
2028
|
+
* @internal
|
|
2029
|
+
*/
|
|
2081
2030
|
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
}
|
|
2031
|
+
function dedentBlockStringLines(lines) {
|
|
2032
|
+
var _firstNonEmptyLine2;
|
|
2085
2033
|
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2034
|
+
let commonIndent = Number.MAX_SAFE_INTEGER;
|
|
2035
|
+
let firstNonEmptyLine = null;
|
|
2036
|
+
let lastNonEmptyLine = -1;
|
|
2089
2037
|
|
|
2090
|
-
for (
|
|
2091
|
-
|
|
2092
|
-
}
|
|
2038
|
+
for (let i = 0; i < lines.length; ++i) {
|
|
2039
|
+
var _firstNonEmptyLine;
|
|
2093
2040
|
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
} else if (remaining > 1) {
|
|
2097
|
-
items.push("... ".concat(remaining, " more items"));
|
|
2098
|
-
}
|
|
2041
|
+
const line = lines[i];
|
|
2042
|
+
const indent = leadingWhitespace(line);
|
|
2099
2043
|
|
|
2100
|
-
|
|
2101
|
-
|
|
2044
|
+
if (indent === line.length) {
|
|
2045
|
+
continue; // skip empty lines
|
|
2046
|
+
}
|
|
2102
2047
|
|
|
2103
|
-
|
|
2104
|
-
|
|
2048
|
+
firstNonEmptyLine =
|
|
2049
|
+
(_firstNonEmptyLine = firstNonEmptyLine) !== null &&
|
|
2050
|
+
_firstNonEmptyLine !== void 0
|
|
2051
|
+
? _firstNonEmptyLine
|
|
2052
|
+
: i;
|
|
2053
|
+
lastNonEmptyLine = i;
|
|
2105
2054
|
|
|
2106
|
-
|
|
2107
|
-
|
|
2055
|
+
if (i !== 0 && indent < commonIndent) {
|
|
2056
|
+
commonIndent = indent;
|
|
2057
|
+
}
|
|
2108
2058
|
}
|
|
2109
2059
|
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2060
|
+
return lines // Remove common indentation from all lines but first.
|
|
2061
|
+
.map((line, i) => (i === 0 ? line : line.slice(commonIndent))) // Remove leading and trailing blank lines.
|
|
2062
|
+
.slice(
|
|
2063
|
+
(_firstNonEmptyLine2 = firstNonEmptyLine) !== null &&
|
|
2064
|
+
_firstNonEmptyLine2 !== void 0
|
|
2065
|
+
? _firstNonEmptyLine2
|
|
2066
|
+
: 0,
|
|
2067
|
+
lastNonEmptyLine + 1,
|
|
2068
|
+
);
|
|
2113
2069
|
}
|
|
2114
2070
|
|
|
2115
|
-
function
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
if (tag === 'Object' && typeof object.constructor === 'function') {
|
|
2119
|
-
var name = object.constructor.name;
|
|
2071
|
+
function leadingWhitespace(str) {
|
|
2072
|
+
let i = 0;
|
|
2120
2073
|
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
}
|
|
2074
|
+
while (i < str.length && isWhiteSpace(str.charCodeAt(i))) {
|
|
2075
|
+
++i;
|
|
2124
2076
|
}
|
|
2125
2077
|
|
|
2126
|
-
return
|
|
2078
|
+
return i;
|
|
2127
2079
|
}
|
|
2128
2080
|
|
|
2129
|
-
|
|
2130
|
-
|
|
2081
|
+
/**
|
|
2082
|
+
* An exported enum describing the different kinds of tokens that the
|
|
2083
|
+
* lexer emits.
|
|
2084
|
+
*/
|
|
2085
|
+
let TokenKind;
|
|
2086
|
+
/**
|
|
2087
|
+
* The enum type representing the token kinds values.
|
|
2088
|
+
*
|
|
2089
|
+
* @deprecated Please use `TokenKind`. Will be remove in v17.
|
|
2090
|
+
*/
|
|
2131
2091
|
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
var _value$constructor;
|
|
2157
|
-
|
|
2158
|
-
var className = constructor.prototype[Symbol.toStringTag];
|
|
2159
|
-
var valueClassName = // We still need to support constructor's name to detect conflicts with older versions of this library.
|
|
2160
|
-
Symbol.toStringTag in value ? value[Symbol.toStringTag] : (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name;
|
|
2161
|
-
|
|
2162
|
-
if (className === valueClassName) {
|
|
2163
|
-
var stringifiedValue = inspect(value);
|
|
2164
|
-
throw new Error("Cannot use ".concat(className, " \"").concat(stringifiedValue, "\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results."));
|
|
2165
|
-
}
|
|
2166
|
-
}
|
|
2167
|
-
|
|
2168
|
-
return false;
|
|
2169
|
-
};
|
|
2170
|
-
|
|
2171
|
-
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); } }
|
|
2172
|
-
|
|
2173
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
2174
|
-
|
|
2175
|
-
/**
|
|
2176
|
-
* A representation of source input to GraphQL. The `name` and `locationOffset` parameters are
|
|
2177
|
-
* optional, but they are useful for clients who store GraphQL documents in source files.
|
|
2178
|
-
* For example, if the GraphQL input starts at line 40 in a file named `Foo.graphql`, it might
|
|
2179
|
-
* be useful for `name` to be `"Foo.graphql"` and location to be `{ line: 40, column: 1 }`.
|
|
2180
|
-
* The `line` and `column` properties in `locationOffset` are 1-indexed.
|
|
2181
|
-
*/
|
|
2182
|
-
var Source = /*#__PURE__*/function () {
|
|
2183
|
-
function Source(body) {
|
|
2184
|
-
var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GraphQL request';
|
|
2185
|
-
var locationOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
2186
|
-
line: 1,
|
|
2187
|
-
column: 1
|
|
2188
|
-
};
|
|
2189
|
-
typeof body === 'string' || devAssert(0, "Body must be a string. Received: ".concat(inspect(body), "."));
|
|
2190
|
-
this.body = body;
|
|
2191
|
-
this.name = name;
|
|
2192
|
-
this.locationOffset = locationOffset;
|
|
2193
|
-
this.locationOffset.line > 0 || devAssert(0, 'line in locationOffset is 1-indexed and must be positive.');
|
|
2194
|
-
this.locationOffset.column > 0 || devAssert(0, 'column in locationOffset is 1-indexed and must be positive.');
|
|
2195
|
-
} // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
_createClass(Source, [{
|
|
2199
|
-
key: SYMBOL_TO_STRING_TAG,
|
|
2200
|
-
get: function get() {
|
|
2201
|
-
return 'Source';
|
|
2202
|
-
}
|
|
2203
|
-
}]);
|
|
2204
|
-
|
|
2205
|
-
return Source;
|
|
2206
|
-
}();
|
|
2207
|
-
/**
|
|
2208
|
-
* Test if the given value is a Source object.
|
|
2209
|
-
*
|
|
2210
|
-
* @internal
|
|
2211
|
-
*/
|
|
2212
|
-
|
|
2213
|
-
// eslint-disable-next-line no-redeclare
|
|
2214
|
-
function isSource(source) {
|
|
2215
|
-
return instanceOf(source, Source);
|
|
2216
|
-
}
|
|
2217
|
-
|
|
2218
|
-
/**
|
|
2219
|
-
* The set of allowed directive location values.
|
|
2220
|
-
*/
|
|
2221
|
-
var DirectiveLocation = Object.freeze({
|
|
2222
|
-
// Request Definitions
|
|
2223
|
-
QUERY: 'QUERY',
|
|
2224
|
-
MUTATION: 'MUTATION',
|
|
2225
|
-
SUBSCRIPTION: 'SUBSCRIPTION',
|
|
2226
|
-
FIELD: 'FIELD',
|
|
2227
|
-
FRAGMENT_DEFINITION: 'FRAGMENT_DEFINITION',
|
|
2228
|
-
FRAGMENT_SPREAD: 'FRAGMENT_SPREAD',
|
|
2229
|
-
INLINE_FRAGMENT: 'INLINE_FRAGMENT',
|
|
2230
|
-
VARIABLE_DEFINITION: 'VARIABLE_DEFINITION',
|
|
2231
|
-
// Type System Definitions
|
|
2232
|
-
SCHEMA: 'SCHEMA',
|
|
2233
|
-
SCALAR: 'SCALAR',
|
|
2234
|
-
OBJECT: 'OBJECT',
|
|
2235
|
-
FIELD_DEFINITION: 'FIELD_DEFINITION',
|
|
2236
|
-
ARGUMENT_DEFINITION: 'ARGUMENT_DEFINITION',
|
|
2237
|
-
INTERFACE: 'INTERFACE',
|
|
2238
|
-
UNION: 'UNION',
|
|
2239
|
-
ENUM: 'ENUM',
|
|
2240
|
-
ENUM_VALUE: 'ENUM_VALUE',
|
|
2241
|
-
INPUT_OBJECT: 'INPUT_OBJECT',
|
|
2242
|
-
INPUT_FIELD_DEFINITION: 'INPUT_FIELD_DEFINITION'
|
|
2243
|
-
});
|
|
2244
|
-
/**
|
|
2245
|
-
* The enum type representing the directive location values.
|
|
2246
|
-
*/
|
|
2247
|
-
|
|
2248
|
-
/**
|
|
2249
|
-
* Produces the value of a block string from its parsed raw value, similar to
|
|
2250
|
-
* CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc.
|
|
2251
|
-
*
|
|
2252
|
-
* This implements the GraphQL spec's BlockStringValue() static algorithm.
|
|
2253
|
-
*
|
|
2254
|
-
* @internal
|
|
2255
|
-
*/
|
|
2256
|
-
function dedentBlockStringValue(rawString) {
|
|
2257
|
-
// Expand a block string's raw value into independent lines.
|
|
2258
|
-
var lines = rawString.split(/\r\n|[\n\r]/g); // Remove common indentation from all lines but first.
|
|
2259
|
-
|
|
2260
|
-
var commonIndent = getBlockStringIndentation(rawString);
|
|
2261
|
-
|
|
2262
|
-
if (commonIndent !== 0) {
|
|
2263
|
-
for (var i = 1; i < lines.length; i++) {
|
|
2264
|
-
lines[i] = lines[i].slice(commonIndent);
|
|
2265
|
-
}
|
|
2266
|
-
} // Remove leading and trailing blank lines.
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
var startLine = 0;
|
|
2270
|
-
|
|
2271
|
-
while (startLine < lines.length && isBlank(lines[startLine])) {
|
|
2272
|
-
++startLine;
|
|
2273
|
-
}
|
|
2274
|
-
|
|
2275
|
-
var endLine = lines.length;
|
|
2276
|
-
|
|
2277
|
-
while (endLine > startLine && isBlank(lines[endLine - 1])) {
|
|
2278
|
-
--endLine;
|
|
2279
|
-
} // Return a string of the lines joined with U+000A.
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
return lines.slice(startLine, endLine).join('\n');
|
|
2283
|
-
}
|
|
2284
|
-
|
|
2285
|
-
function isBlank(str) {
|
|
2286
|
-
for (var i = 0; i < str.length; ++i) {
|
|
2287
|
-
if (str[i] !== ' ' && str[i] !== '\t') {
|
|
2288
|
-
return false;
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
|
|
2292
|
-
return true;
|
|
2293
|
-
}
|
|
2294
|
-
/**
|
|
2295
|
-
* @internal
|
|
2296
|
-
*/
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
function getBlockStringIndentation(value) {
|
|
2300
|
-
var _commonIndent;
|
|
2301
|
-
|
|
2302
|
-
var isFirstLine = true;
|
|
2303
|
-
var isEmptyLine = true;
|
|
2304
|
-
var indent = 0;
|
|
2305
|
-
var commonIndent = null;
|
|
2306
|
-
|
|
2307
|
-
for (var i = 0; i < value.length; ++i) {
|
|
2308
|
-
switch (value.charCodeAt(i)) {
|
|
2309
|
-
case 13:
|
|
2310
|
-
// \r
|
|
2311
|
-
if (value.charCodeAt(i + 1) === 10) {
|
|
2312
|
-
++i; // skip \r\n as one symbol
|
|
2313
|
-
}
|
|
2314
|
-
|
|
2315
|
-
// falls through
|
|
2316
|
-
|
|
2317
|
-
case 10:
|
|
2318
|
-
// \n
|
|
2319
|
-
isFirstLine = false;
|
|
2320
|
-
isEmptyLine = true;
|
|
2321
|
-
indent = 0;
|
|
2322
|
-
break;
|
|
2323
|
-
|
|
2324
|
-
case 9: // \t
|
|
2325
|
-
|
|
2326
|
-
case 32:
|
|
2327
|
-
// <space>
|
|
2328
|
-
++indent;
|
|
2329
|
-
break;
|
|
2330
|
-
|
|
2331
|
-
default:
|
|
2332
|
-
if (isEmptyLine && !isFirstLine && (commonIndent === null || indent < commonIndent)) {
|
|
2333
|
-
commonIndent = indent;
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
isEmptyLine = false;
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
|
|
2340
|
-
return (_commonIndent = commonIndent) !== null && _commonIndent !== void 0 ? _commonIndent : 0;
|
|
2341
|
-
}
|
|
2092
|
+
(function (TokenKind) {
|
|
2093
|
+
TokenKind['SOF'] = '<SOF>';
|
|
2094
|
+
TokenKind['EOF'] = '<EOF>';
|
|
2095
|
+
TokenKind['BANG'] = '!';
|
|
2096
|
+
TokenKind['DOLLAR'] = '$';
|
|
2097
|
+
TokenKind['AMP'] = '&';
|
|
2098
|
+
TokenKind['PAREN_L'] = '(';
|
|
2099
|
+
TokenKind['PAREN_R'] = ')';
|
|
2100
|
+
TokenKind['SPREAD'] = '...';
|
|
2101
|
+
TokenKind['COLON'] = ':';
|
|
2102
|
+
TokenKind['EQUALS'] = '=';
|
|
2103
|
+
TokenKind['AT'] = '@';
|
|
2104
|
+
TokenKind['BRACKET_L'] = '[';
|
|
2105
|
+
TokenKind['BRACKET_R'] = ']';
|
|
2106
|
+
TokenKind['BRACE_L'] = '{';
|
|
2107
|
+
TokenKind['PIPE'] = '|';
|
|
2108
|
+
TokenKind['BRACE_R'] = '}';
|
|
2109
|
+
TokenKind['NAME'] = 'Name';
|
|
2110
|
+
TokenKind['INT'] = 'Int';
|
|
2111
|
+
TokenKind['FLOAT'] = 'Float';
|
|
2112
|
+
TokenKind['STRING'] = 'String';
|
|
2113
|
+
TokenKind['BLOCK_STRING'] = 'BlockString';
|
|
2114
|
+
TokenKind['COMMENT'] = 'Comment';
|
|
2115
|
+
})(TokenKind || (TokenKind = {}));
|
|
2342
2116
|
|
|
2343
2117
|
/**
|
|
2344
2118
|
* Given a Source object, creates a Lexer for that source.
|
|
@@ -2349,7 +2123,7 @@ function getBlockStringIndentation(value) {
|
|
|
2349
2123
|
* whenever called.
|
|
2350
2124
|
*/
|
|
2351
2125
|
|
|
2352
|
-
|
|
2126
|
+
class Lexer {
|
|
2353
2127
|
/**
|
|
2354
2128
|
* The previously focused non-ignored token.
|
|
2355
2129
|
*/
|
|
@@ -2365,64 +2139,143 @@ var Lexer = /*#__PURE__*/function () {
|
|
|
2365
2139
|
/**
|
|
2366
2140
|
* The character offset at which the current line begins.
|
|
2367
2141
|
*/
|
|
2368
|
-
|
|
2369
|
-
|
|
2142
|
+
constructor(source) {
|
|
2143
|
+
const startOfFileToken = new Token(TokenKind.SOF, 0, 0, 0, 0);
|
|
2370
2144
|
this.source = source;
|
|
2371
2145
|
this.lastToken = startOfFileToken;
|
|
2372
2146
|
this.token = startOfFileToken;
|
|
2373
2147
|
this.line = 1;
|
|
2374
2148
|
this.lineStart = 0;
|
|
2375
2149
|
}
|
|
2150
|
+
|
|
2151
|
+
get [Symbol.toStringTag]() {
|
|
2152
|
+
return 'Lexer';
|
|
2153
|
+
}
|
|
2376
2154
|
/**
|
|
2377
2155
|
* Advances the token stream to the next non-ignored token.
|
|
2378
2156
|
*/
|
|
2379
2157
|
|
|
2380
|
-
|
|
2381
|
-
var _proto = Lexer.prototype;
|
|
2382
|
-
|
|
2383
|
-
_proto.advance = function advance() {
|
|
2158
|
+
advance() {
|
|
2384
2159
|
this.lastToken = this.token;
|
|
2385
|
-
|
|
2160
|
+
const token = (this.token = this.lookahead());
|
|
2386
2161
|
return token;
|
|
2387
2162
|
}
|
|
2388
2163
|
/**
|
|
2389
2164
|
* Looks ahead and returns the next non-ignored token, but does not change
|
|
2390
2165
|
* the state of Lexer.
|
|
2391
2166
|
*/
|
|
2392
|
-
;
|
|
2393
2167
|
|
|
2394
|
-
|
|
2395
|
-
|
|
2168
|
+
lookahead() {
|
|
2169
|
+
let token = this.token;
|
|
2396
2170
|
|
|
2397
2171
|
if (token.kind !== TokenKind.EOF) {
|
|
2398
2172
|
do {
|
|
2399
|
-
|
|
2173
|
+
if (token.next) {
|
|
2174
|
+
token = token.next;
|
|
2175
|
+
} else {
|
|
2176
|
+
// Read the next token and form a link in the token linked-list.
|
|
2177
|
+
const nextToken = readNextToken(this, token.end); // @ts-expect-error next is only mutable during parsing.
|
|
2178
|
+
|
|
2179
|
+
token.next = nextToken; // @ts-expect-error prev is only mutable during parsing.
|
|
2400
2180
|
|
|
2401
|
-
|
|
2402
|
-
|
|
2181
|
+
nextToken.prev = token;
|
|
2182
|
+
token = nextToken;
|
|
2183
|
+
}
|
|
2403
2184
|
} while (token.kind === TokenKind.COMMENT);
|
|
2404
2185
|
}
|
|
2405
2186
|
|
|
2406
2187
|
return token;
|
|
2407
|
-
}
|
|
2408
|
-
|
|
2409
|
-
return Lexer;
|
|
2410
|
-
}();
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2411
2190
|
/**
|
|
2412
2191
|
* @internal
|
|
2413
2192
|
*/
|
|
2414
2193
|
|
|
2415
2194
|
function isPunctuatorTokenKind(kind) {
|
|
2416
|
-
return
|
|
2195
|
+
return (
|
|
2196
|
+
kind === TokenKind.BANG ||
|
|
2197
|
+
kind === TokenKind.DOLLAR ||
|
|
2198
|
+
kind === TokenKind.AMP ||
|
|
2199
|
+
kind === TokenKind.PAREN_L ||
|
|
2200
|
+
kind === TokenKind.PAREN_R ||
|
|
2201
|
+
kind === TokenKind.SPREAD ||
|
|
2202
|
+
kind === TokenKind.COLON ||
|
|
2203
|
+
kind === TokenKind.EQUALS ||
|
|
2204
|
+
kind === TokenKind.AT ||
|
|
2205
|
+
kind === TokenKind.BRACKET_L ||
|
|
2206
|
+
kind === TokenKind.BRACKET_R ||
|
|
2207
|
+
kind === TokenKind.BRACE_L ||
|
|
2208
|
+
kind === TokenKind.PIPE ||
|
|
2209
|
+
kind === TokenKind.BRACE_R
|
|
2210
|
+
);
|
|
2417
2211
|
}
|
|
2212
|
+
/**
|
|
2213
|
+
* A Unicode scalar value is any Unicode code point except surrogate code
|
|
2214
|
+
* points. In other words, the inclusive ranges of values 0x0000 to 0xD7FF and
|
|
2215
|
+
* 0xE000 to 0x10FFFF.
|
|
2216
|
+
*
|
|
2217
|
+
* SourceCharacter ::
|
|
2218
|
+
* - "Any Unicode scalar value"
|
|
2219
|
+
*/
|
|
2220
|
+
|
|
2221
|
+
function isUnicodeScalarValue(code) {
|
|
2222
|
+
return (
|
|
2223
|
+
(code >= 0x0000 && code <= 0xd7ff) || (code >= 0xe000 && code <= 0x10ffff)
|
|
2224
|
+
);
|
|
2225
|
+
}
|
|
2226
|
+
/**
|
|
2227
|
+
* The GraphQL specification defines source text as a sequence of unicode scalar
|
|
2228
|
+
* values (which Unicode defines to exclude surrogate code points). However
|
|
2229
|
+
* JavaScript defines strings as a sequence of UTF-16 code units which may
|
|
2230
|
+
* include surrogates. A surrogate pair is a valid source character as it
|
|
2231
|
+
* encodes a supplementary code point (above U+FFFF), but unpaired surrogate
|
|
2232
|
+
* code points are not valid source characters.
|
|
2233
|
+
*/
|
|
2418
2234
|
|
|
2419
|
-
function
|
|
2420
|
-
return (
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
"\"\\u".concat(('00' + code.toString(16).toUpperCase()).slice(-4), "\"")
|
|
2235
|
+
function isSupplementaryCodePoint(body, location) {
|
|
2236
|
+
return (
|
|
2237
|
+
isLeadingSurrogate(body.charCodeAt(location)) &&
|
|
2238
|
+
isTrailingSurrogate(body.charCodeAt(location + 1))
|
|
2424
2239
|
);
|
|
2425
2240
|
}
|
|
2241
|
+
|
|
2242
|
+
function isLeadingSurrogate(code) {
|
|
2243
|
+
return code >= 0xd800 && code <= 0xdbff;
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
function isTrailingSurrogate(code) {
|
|
2247
|
+
return code >= 0xdc00 && code <= 0xdfff;
|
|
2248
|
+
}
|
|
2249
|
+
/**
|
|
2250
|
+
* Prints the code point (or end of file reference) at a given location in a
|
|
2251
|
+
* source for use in error messages.
|
|
2252
|
+
*
|
|
2253
|
+
* Printable ASCII is printed quoted, while other points are printed in Unicode
|
|
2254
|
+
* code point form (ie. U+1234).
|
|
2255
|
+
*/
|
|
2256
|
+
|
|
2257
|
+
function printCodePointAt(lexer, location) {
|
|
2258
|
+
const code = lexer.source.body.codePointAt(location);
|
|
2259
|
+
|
|
2260
|
+
if (code === undefined) {
|
|
2261
|
+
return TokenKind.EOF;
|
|
2262
|
+
} else if (code >= 0x0020 && code <= 0x007e) {
|
|
2263
|
+
// Printable ASCII
|
|
2264
|
+
const char = String.fromCodePoint(code);
|
|
2265
|
+
return char === '"' ? "'\"'" : `"${char}"`;
|
|
2266
|
+
} // Unicode code point
|
|
2267
|
+
|
|
2268
|
+
return 'U+' + code.toString(16).toUpperCase().padStart(4, '0');
|
|
2269
|
+
}
|
|
2270
|
+
/**
|
|
2271
|
+
* Create a token with line and column location information.
|
|
2272
|
+
*/
|
|
2273
|
+
|
|
2274
|
+
function createToken(lexer, kind, start, end, value) {
|
|
2275
|
+
const line = lexer.line;
|
|
2276
|
+
const col = 1 + start - lexer.lineStart;
|
|
2277
|
+
return new Token(kind, start, end, line, col, value);
|
|
2278
|
+
}
|
|
2426
2279
|
/**
|
|
2427
2280
|
* Gets the next token from the source starting at the given position.
|
|
2428
2281
|
*
|
|
@@ -2431,586 +2284,947 @@ function printCharCode(code) {
|
|
|
2431
2284
|
* complicated tokens.
|
|
2432
2285
|
*/
|
|
2433
2286
|
|
|
2287
|
+
function readNextToken(lexer, start) {
|
|
2288
|
+
const body = lexer.source.body;
|
|
2289
|
+
const bodyLength = body.length;
|
|
2290
|
+
let position = start;
|
|
2434
2291
|
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
var body = source.body;
|
|
2438
|
-
var bodyLength = body.length;
|
|
2439
|
-
var pos = prev.end;
|
|
2440
|
-
|
|
2441
|
-
while (pos < bodyLength) {
|
|
2442
|
-
var code = body.charCodeAt(pos);
|
|
2443
|
-
var _line = lexer.line;
|
|
2444
|
-
|
|
2445
|
-
var _col = 1 + pos - lexer.lineStart; // SourceCharacter
|
|
2446
|
-
|
|
2292
|
+
while (position < bodyLength) {
|
|
2293
|
+
const code = body.charCodeAt(position); // SourceCharacter
|
|
2447
2294
|
|
|
2448
2295
|
switch (code) {
|
|
2296
|
+
// Ignored ::
|
|
2297
|
+
// - UnicodeBOM
|
|
2298
|
+
// - WhiteSpace
|
|
2299
|
+
// - LineTerminator
|
|
2300
|
+
// - Comment
|
|
2301
|
+
// - Comma
|
|
2302
|
+
//
|
|
2303
|
+
// UnicodeBOM :: "Byte Order Mark (U+FEFF)"
|
|
2304
|
+
//
|
|
2305
|
+
// WhiteSpace ::
|
|
2306
|
+
// - "Horizontal Tab (U+0009)"
|
|
2307
|
+
// - "Space (U+0020)"
|
|
2308
|
+
//
|
|
2309
|
+
// Comma :: ,
|
|
2449
2310
|
case 0xfeff: // <BOM>
|
|
2450
2311
|
|
|
2451
|
-
case
|
|
2312
|
+
case 0x0009: // \t
|
|
2452
2313
|
|
|
2453
|
-
case
|
|
2314
|
+
case 0x0020: // <space>
|
|
2454
2315
|
|
|
2455
|
-
case
|
|
2456
|
-
//
|
|
2457
|
-
++
|
|
2316
|
+
case 0x002c:
|
|
2317
|
+
// ,
|
|
2318
|
+
++position;
|
|
2458
2319
|
continue;
|
|
2320
|
+
// LineTerminator ::
|
|
2321
|
+
// - "New Line (U+000A)"
|
|
2322
|
+
// - "Carriage Return (U+000D)" [lookahead != "New Line (U+000A)"]
|
|
2323
|
+
// - "Carriage Return (U+000D)" "New Line (U+000A)"
|
|
2459
2324
|
|
|
2460
|
-
case
|
|
2461
|
-
//
|
|
2462
|
-
++
|
|
2325
|
+
case 0x000a:
|
|
2326
|
+
// \n
|
|
2327
|
+
++position;
|
|
2463
2328
|
++lexer.line;
|
|
2464
|
-
lexer.lineStart =
|
|
2329
|
+
lexer.lineStart = position;
|
|
2465
2330
|
continue;
|
|
2466
2331
|
|
|
2467
|
-
case
|
|
2468
|
-
//
|
|
2469
|
-
if (body.charCodeAt(
|
|
2470
|
-
|
|
2332
|
+
case 0x000d:
|
|
2333
|
+
// \r
|
|
2334
|
+
if (body.charCodeAt(position + 1) === 0x000a) {
|
|
2335
|
+
position += 2;
|
|
2471
2336
|
} else {
|
|
2472
|
-
++
|
|
2337
|
+
++position;
|
|
2473
2338
|
}
|
|
2474
2339
|
|
|
2475
2340
|
++lexer.line;
|
|
2476
|
-
lexer.lineStart =
|
|
2341
|
+
lexer.lineStart = position;
|
|
2477
2342
|
continue;
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2343
|
+
// Comment
|
|
2344
|
+
|
|
2345
|
+
case 0x0023:
|
|
2346
|
+
// #
|
|
2347
|
+
return readComment(lexer, position);
|
|
2348
|
+
// Token ::
|
|
2349
|
+
// - Punctuator
|
|
2350
|
+
// - Name
|
|
2351
|
+
// - IntValue
|
|
2352
|
+
// - FloatValue
|
|
2353
|
+
// - StringValue
|
|
2354
|
+
//
|
|
2355
|
+
// Punctuator :: one of ! $ & ( ) ... : = @ [ ] { | }
|
|
2356
|
+
|
|
2357
|
+
case 0x0021:
|
|
2358
|
+
// !
|
|
2359
|
+
return createToken(lexer, TokenKind.BANG, position, position + 1);
|
|
2360
|
+
|
|
2361
|
+
case 0x0024:
|
|
2362
|
+
// $
|
|
2363
|
+
return createToken(lexer, TokenKind.DOLLAR, position, position + 1);
|
|
2364
|
+
|
|
2365
|
+
case 0x0026:
|
|
2366
|
+
// &
|
|
2367
|
+
return createToken(lexer, TokenKind.AMP, position, position + 1);
|
|
2368
|
+
|
|
2369
|
+
case 0x0028:
|
|
2370
|
+
// (
|
|
2371
|
+
return createToken(lexer, TokenKind.PAREN_L, position, position + 1);
|
|
2372
|
+
|
|
2373
|
+
case 0x0029:
|
|
2374
|
+
// )
|
|
2375
|
+
return createToken(lexer, TokenKind.PAREN_R, position, position + 1);
|
|
2376
|
+
|
|
2377
|
+
case 0x002e:
|
|
2378
|
+
// .
|
|
2379
|
+
if (
|
|
2380
|
+
body.charCodeAt(position + 1) === 0x002e &&
|
|
2381
|
+
body.charCodeAt(position + 2) === 0x002e
|
|
2382
|
+
) {
|
|
2383
|
+
return createToken(lexer, TokenKind.SPREAD, position, position + 3);
|
|
2507
2384
|
}
|
|
2508
2385
|
|
|
2509
2386
|
break;
|
|
2510
2387
|
|
|
2511
|
-
case
|
|
2512
|
-
//
|
|
2513
|
-
return
|
|
2388
|
+
case 0x003a:
|
|
2389
|
+
// :
|
|
2390
|
+
return createToken(lexer, TokenKind.COLON, position, position + 1);
|
|
2514
2391
|
|
|
2515
|
-
case
|
|
2516
|
-
//
|
|
2517
|
-
return
|
|
2392
|
+
case 0x003d:
|
|
2393
|
+
// =
|
|
2394
|
+
return createToken(lexer, TokenKind.EQUALS, position, position + 1);
|
|
2518
2395
|
|
|
2519
|
-
case
|
|
2520
|
-
//
|
|
2521
|
-
return
|
|
2396
|
+
case 0x0040:
|
|
2397
|
+
// @
|
|
2398
|
+
return createToken(lexer, TokenKind.AT, position, position + 1);
|
|
2522
2399
|
|
|
2523
|
-
case
|
|
2524
|
-
//
|
|
2525
|
-
return
|
|
2400
|
+
case 0x005b:
|
|
2401
|
+
// [
|
|
2402
|
+
return createToken(lexer, TokenKind.BRACKET_L, position, position + 1);
|
|
2526
2403
|
|
|
2527
|
-
case
|
|
2528
|
-
//
|
|
2529
|
-
return
|
|
2404
|
+
case 0x005d:
|
|
2405
|
+
// ]
|
|
2406
|
+
return createToken(lexer, TokenKind.BRACKET_R, position, position + 1);
|
|
2530
2407
|
|
|
2531
|
-
case
|
|
2408
|
+
case 0x007b:
|
|
2532
2409
|
// {
|
|
2533
|
-
return
|
|
2410
|
+
return createToken(lexer, TokenKind.BRACE_L, position, position + 1);
|
|
2534
2411
|
|
|
2535
|
-
case
|
|
2412
|
+
case 0x007c:
|
|
2536
2413
|
// |
|
|
2537
|
-
return
|
|
2414
|
+
return createToken(lexer, TokenKind.PIPE, position, position + 1);
|
|
2538
2415
|
|
|
2539
|
-
case
|
|
2416
|
+
case 0x007d:
|
|
2540
2417
|
// }
|
|
2541
|
-
return
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2418
|
+
return createToken(lexer, TokenKind.BRACE_R, position, position + 1);
|
|
2419
|
+
// StringValue
|
|
2420
|
+
|
|
2421
|
+
case 0x0022:
|
|
2422
|
+
// "
|
|
2423
|
+
if (
|
|
2424
|
+
body.charCodeAt(position + 1) === 0x0022 &&
|
|
2425
|
+
body.charCodeAt(position + 2) === 0x0022
|
|
2426
|
+
) {
|
|
2427
|
+
return readBlockString(lexer, position);
|
|
2547
2428
|
}
|
|
2548
2429
|
|
|
2549
|
-
return readString(
|
|
2550
|
-
|
|
2551
|
-
case 45: // -
|
|
2552
|
-
|
|
2553
|
-
case 48: // 0
|
|
2554
|
-
|
|
2555
|
-
case 49: // 1
|
|
2556
|
-
|
|
2557
|
-
case 50: // 2
|
|
2558
|
-
|
|
2559
|
-
case 51: // 3
|
|
2430
|
+
return readString(lexer, position);
|
|
2431
|
+
} // IntValue | FloatValue (Digit | -)
|
|
2560
2432
|
|
|
2561
|
-
|
|
2433
|
+
if (isDigit(code) || code === 0x002d) {
|
|
2434
|
+
return readNumber(lexer, position, code);
|
|
2435
|
+
} // Name
|
|
2562
2436
|
|
|
2563
|
-
|
|
2437
|
+
if (isNameStart(code)) {
|
|
2438
|
+
return readName(lexer, position);
|
|
2439
|
+
}
|
|
2564
2440
|
|
|
2565
|
-
|
|
2441
|
+
throw syntaxError(
|
|
2442
|
+
lexer.source,
|
|
2443
|
+
position,
|
|
2444
|
+
code === 0x0027
|
|
2445
|
+
? 'Unexpected single quote character (\'), did you mean to use a double quote (")?'
|
|
2446
|
+
: isUnicodeScalarValue(code) || isSupplementaryCodePoint(body, position)
|
|
2447
|
+
? `Unexpected character: ${printCodePointAt(lexer, position)}.`
|
|
2448
|
+
: `Invalid character: ${printCodePointAt(lexer, position)}.`,
|
|
2449
|
+
);
|
|
2450
|
+
}
|
|
2566
2451
|
|
|
2567
|
-
|
|
2452
|
+
return createToken(lexer, TokenKind.EOF, bodyLength, bodyLength);
|
|
2453
|
+
}
|
|
2454
|
+
/**
|
|
2455
|
+
* Reads a comment token from the source file.
|
|
2456
|
+
*
|
|
2457
|
+
* ```
|
|
2458
|
+
* Comment :: # CommentChar* [lookahead != CommentChar]
|
|
2459
|
+
*
|
|
2460
|
+
* CommentChar :: SourceCharacter but not LineTerminator
|
|
2461
|
+
* ```
|
|
2462
|
+
*/
|
|
2568
2463
|
|
|
2569
|
-
|
|
2464
|
+
function readComment(lexer, start) {
|
|
2465
|
+
const body = lexer.source.body;
|
|
2466
|
+
const bodyLength = body.length;
|
|
2467
|
+
let position = start + 1;
|
|
2570
2468
|
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
return readNumber(source, pos, code, _line, _col, prev);
|
|
2469
|
+
while (position < bodyLength) {
|
|
2470
|
+
const code = body.charCodeAt(position); // LineTerminator (\n | \r)
|
|
2574
2471
|
|
|
2575
|
-
|
|
2472
|
+
if (code === 0x000a || code === 0x000d) {
|
|
2473
|
+
break;
|
|
2474
|
+
} // SourceCharacter
|
|
2576
2475
|
|
|
2577
|
-
|
|
2476
|
+
if (isUnicodeScalarValue(code)) {
|
|
2477
|
+
++position;
|
|
2478
|
+
} else if (isSupplementaryCodePoint(body, position)) {
|
|
2479
|
+
position += 2;
|
|
2480
|
+
} else {
|
|
2481
|
+
break;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2578
2484
|
|
|
2579
|
-
|
|
2485
|
+
return createToken(
|
|
2486
|
+
lexer,
|
|
2487
|
+
TokenKind.COMMENT,
|
|
2488
|
+
start,
|
|
2489
|
+
position,
|
|
2490
|
+
body.slice(start + 1, position),
|
|
2491
|
+
);
|
|
2492
|
+
}
|
|
2493
|
+
/**
|
|
2494
|
+
* Reads a number token from the source file, either a FloatValue or an IntValue
|
|
2495
|
+
* depending on whether a FractionalPart or ExponentPart is encountered.
|
|
2496
|
+
*
|
|
2497
|
+
* ```
|
|
2498
|
+
* IntValue :: IntegerPart [lookahead != {Digit, `.`, NameStart}]
|
|
2499
|
+
*
|
|
2500
|
+
* IntegerPart ::
|
|
2501
|
+
* - NegativeSign? 0
|
|
2502
|
+
* - NegativeSign? NonZeroDigit Digit*
|
|
2503
|
+
*
|
|
2504
|
+
* NegativeSign :: -
|
|
2505
|
+
*
|
|
2506
|
+
* NonZeroDigit :: Digit but not `0`
|
|
2507
|
+
*
|
|
2508
|
+
* FloatValue ::
|
|
2509
|
+
* - IntegerPart FractionalPart ExponentPart [lookahead != {Digit, `.`, NameStart}]
|
|
2510
|
+
* - IntegerPart FractionalPart [lookahead != {Digit, `.`, NameStart}]
|
|
2511
|
+
* - IntegerPart ExponentPart [lookahead != {Digit, `.`, NameStart}]
|
|
2512
|
+
*
|
|
2513
|
+
* FractionalPart :: . Digit+
|
|
2514
|
+
*
|
|
2515
|
+
* ExponentPart :: ExponentIndicator Sign? Digit+
|
|
2516
|
+
*
|
|
2517
|
+
* ExponentIndicator :: one of `e` `E`
|
|
2518
|
+
*
|
|
2519
|
+
* Sign :: one of + -
|
|
2520
|
+
* ```
|
|
2521
|
+
*/
|
|
2580
2522
|
|
|
2581
|
-
|
|
2523
|
+
function readNumber(lexer, start, firstCode) {
|
|
2524
|
+
const body = lexer.source.body;
|
|
2525
|
+
let position = start;
|
|
2526
|
+
let code = firstCode;
|
|
2527
|
+
let isFloat = false; // NegativeSign (-)
|
|
2582
2528
|
|
|
2583
|
-
|
|
2529
|
+
if (code === 0x002d) {
|
|
2530
|
+
code = body.charCodeAt(++position);
|
|
2531
|
+
} // Zero (0)
|
|
2584
2532
|
|
|
2585
|
-
|
|
2533
|
+
if (code === 0x0030) {
|
|
2534
|
+
code = body.charCodeAt(++position);
|
|
2586
2535
|
|
|
2587
|
-
|
|
2536
|
+
if (isDigit(code)) {
|
|
2537
|
+
throw syntaxError(
|
|
2538
|
+
lexer.source,
|
|
2539
|
+
position,
|
|
2540
|
+
`Invalid number, unexpected digit after 0: ${printCodePointAt(
|
|
2541
|
+
lexer,
|
|
2542
|
+
position,
|
|
2543
|
+
)}.`,
|
|
2544
|
+
);
|
|
2545
|
+
}
|
|
2546
|
+
} else {
|
|
2547
|
+
position = readDigits(lexer, position, code);
|
|
2548
|
+
code = body.charCodeAt(position);
|
|
2549
|
+
} // Full stop (.)
|
|
2588
2550
|
|
|
2589
|
-
|
|
2551
|
+
if (code === 0x002e) {
|
|
2552
|
+
isFloat = true;
|
|
2553
|
+
code = body.charCodeAt(++position);
|
|
2554
|
+
position = readDigits(lexer, position, code);
|
|
2555
|
+
code = body.charCodeAt(position);
|
|
2556
|
+
} // E e
|
|
2590
2557
|
|
|
2591
|
-
|
|
2558
|
+
if (code === 0x0045 || code === 0x0065) {
|
|
2559
|
+
isFloat = true;
|
|
2560
|
+
code = body.charCodeAt(++position); // + -
|
|
2592
2561
|
|
|
2593
|
-
|
|
2562
|
+
if (code === 0x002b || code === 0x002d) {
|
|
2563
|
+
code = body.charCodeAt(++position);
|
|
2564
|
+
}
|
|
2594
2565
|
|
|
2595
|
-
|
|
2566
|
+
position = readDigits(lexer, position, code);
|
|
2567
|
+
code = body.charCodeAt(position);
|
|
2568
|
+
} // Numbers cannot be followed by . or NameStart
|
|
2596
2569
|
|
|
2597
|
-
|
|
2570
|
+
if (code === 0x002e || isNameStart(code)) {
|
|
2571
|
+
throw syntaxError(
|
|
2572
|
+
lexer.source,
|
|
2573
|
+
position,
|
|
2574
|
+
`Invalid number, expected digit but got: ${printCodePointAt(
|
|
2575
|
+
lexer,
|
|
2576
|
+
position,
|
|
2577
|
+
)}.`,
|
|
2578
|
+
);
|
|
2579
|
+
}
|
|
2598
2580
|
|
|
2599
|
-
|
|
2581
|
+
return createToken(
|
|
2582
|
+
lexer,
|
|
2583
|
+
isFloat ? TokenKind.FLOAT : TokenKind.INT,
|
|
2584
|
+
start,
|
|
2585
|
+
position,
|
|
2586
|
+
body.slice(start, position),
|
|
2587
|
+
);
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2590
|
+
* Returns the new position in the source after reading one or more digits.
|
|
2591
|
+
*/
|
|
2600
2592
|
|
|
2601
|
-
|
|
2593
|
+
function readDigits(lexer, start, firstCode) {
|
|
2594
|
+
if (!isDigit(firstCode)) {
|
|
2595
|
+
throw syntaxError(
|
|
2596
|
+
lexer.source,
|
|
2597
|
+
start,
|
|
2598
|
+
`Invalid number, expected digit but got: ${printCodePointAt(
|
|
2599
|
+
lexer,
|
|
2600
|
+
start,
|
|
2601
|
+
)}.`,
|
|
2602
|
+
);
|
|
2603
|
+
}
|
|
2602
2604
|
|
|
2603
|
-
|
|
2605
|
+
const body = lexer.source.body;
|
|
2606
|
+
let position = start + 1; // +1 to skip first firstCode
|
|
2604
2607
|
|
|
2605
|
-
|
|
2608
|
+
while (isDigit(body.charCodeAt(position))) {
|
|
2609
|
+
++position;
|
|
2610
|
+
}
|
|
2606
2611
|
|
|
2607
|
-
|
|
2612
|
+
return position;
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* Reads a single-quote string token from the source file.
|
|
2616
|
+
*
|
|
2617
|
+
* ```
|
|
2618
|
+
* StringValue ::
|
|
2619
|
+
* - `""` [lookahead != `"`]
|
|
2620
|
+
* - `"` StringCharacter+ `"`
|
|
2621
|
+
*
|
|
2622
|
+
* StringCharacter ::
|
|
2623
|
+
* - SourceCharacter but not `"` or `\` or LineTerminator
|
|
2624
|
+
* - `\u` EscapedUnicode
|
|
2625
|
+
* - `\` EscapedCharacter
|
|
2626
|
+
*
|
|
2627
|
+
* EscapedUnicode ::
|
|
2628
|
+
* - `{` HexDigit+ `}`
|
|
2629
|
+
* - HexDigit HexDigit HexDigit HexDigit
|
|
2630
|
+
*
|
|
2631
|
+
* EscapedCharacter :: one of `"` `\` `/` `b` `f` `n` `r` `t`
|
|
2632
|
+
* ```
|
|
2633
|
+
*/
|
|
2608
2634
|
|
|
2609
|
-
|
|
2635
|
+
function readString(lexer, start) {
|
|
2636
|
+
const body = lexer.source.body;
|
|
2637
|
+
const bodyLength = body.length;
|
|
2638
|
+
let position = start + 1;
|
|
2639
|
+
let chunkStart = position;
|
|
2640
|
+
let value = '';
|
|
2610
2641
|
|
|
2611
|
-
|
|
2642
|
+
while (position < bodyLength) {
|
|
2643
|
+
const code = body.charCodeAt(position); // Closing Quote (")
|
|
2612
2644
|
|
|
2613
|
-
|
|
2645
|
+
if (code === 0x0022) {
|
|
2646
|
+
value += body.slice(chunkStart, position);
|
|
2647
|
+
return createToken(lexer, TokenKind.STRING, start, position + 1, value);
|
|
2648
|
+
} // Escape Sequence (\)
|
|
2614
2649
|
|
|
2615
|
-
|
|
2650
|
+
if (code === 0x005c) {
|
|
2651
|
+
value += body.slice(chunkStart, position);
|
|
2652
|
+
const escape =
|
|
2653
|
+
body.charCodeAt(position + 1) === 0x0075 // u
|
|
2654
|
+
? body.charCodeAt(position + 2) === 0x007b // {
|
|
2655
|
+
? readEscapedUnicodeVariableWidth(lexer, position)
|
|
2656
|
+
: readEscapedUnicodeFixedWidth(lexer, position)
|
|
2657
|
+
: readEscapedCharacter(lexer, position);
|
|
2658
|
+
value += escape.value;
|
|
2659
|
+
position += escape.size;
|
|
2660
|
+
chunkStart = position;
|
|
2661
|
+
continue;
|
|
2662
|
+
} // LineTerminator (\n | \r)
|
|
2616
2663
|
|
|
2617
|
-
|
|
2664
|
+
if (code === 0x000a || code === 0x000d) {
|
|
2665
|
+
break;
|
|
2666
|
+
} // SourceCharacter
|
|
2618
2667
|
|
|
2619
|
-
|
|
2668
|
+
if (isUnicodeScalarValue(code)) {
|
|
2669
|
+
++position;
|
|
2670
|
+
} else if (isSupplementaryCodePoint(body, position)) {
|
|
2671
|
+
position += 2;
|
|
2672
|
+
} else {
|
|
2673
|
+
throw syntaxError(
|
|
2674
|
+
lexer.source,
|
|
2675
|
+
position,
|
|
2676
|
+
`Invalid character within String: ${printCodePointAt(
|
|
2677
|
+
lexer,
|
|
2678
|
+
position,
|
|
2679
|
+
)}.`,
|
|
2680
|
+
);
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2620
2683
|
|
|
2621
|
-
|
|
2684
|
+
throw syntaxError(lexer.source, position, 'Unterminated string.');
|
|
2685
|
+
} // The string value and lexed size of an escape sequence.
|
|
2622
2686
|
|
|
2623
|
-
|
|
2687
|
+
function readEscapedUnicodeVariableWidth(lexer, position) {
|
|
2688
|
+
const body = lexer.source.body;
|
|
2689
|
+
let point = 0;
|
|
2690
|
+
let size = 3; // Cannot be larger than 12 chars (\u{00000000}).
|
|
2624
2691
|
|
|
2625
|
-
|
|
2692
|
+
while (size < 12) {
|
|
2693
|
+
const code = body.charCodeAt(position + size++); // Closing Brace (})
|
|
2626
2694
|
|
|
2627
|
-
|
|
2695
|
+
if (code === 0x007d) {
|
|
2696
|
+
// Must be at least 5 chars (\u{0}) and encode a Unicode scalar value.
|
|
2697
|
+
if (size < 5 || !isUnicodeScalarValue(point)) {
|
|
2698
|
+
break;
|
|
2699
|
+
}
|
|
2628
2700
|
|
|
2629
|
-
|
|
2701
|
+
return {
|
|
2702
|
+
value: String.fromCodePoint(point),
|
|
2703
|
+
size,
|
|
2704
|
+
};
|
|
2705
|
+
} // Append this hex digit to the code point.
|
|
2630
2706
|
|
|
2631
|
-
|
|
2707
|
+
point = (point << 4) | readHexDigit(code);
|
|
2632
2708
|
|
|
2633
|
-
|
|
2709
|
+
if (point < 0) {
|
|
2710
|
+
break;
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2634
2713
|
|
|
2635
|
-
|
|
2714
|
+
throw syntaxError(
|
|
2715
|
+
lexer.source,
|
|
2716
|
+
position,
|
|
2717
|
+
`Invalid Unicode escape sequence: "${body.slice(
|
|
2718
|
+
position,
|
|
2719
|
+
position + size,
|
|
2720
|
+
)}".`,
|
|
2721
|
+
);
|
|
2722
|
+
}
|
|
2636
2723
|
|
|
2637
|
-
|
|
2724
|
+
function readEscapedUnicodeFixedWidth(lexer, position) {
|
|
2725
|
+
const body = lexer.source.body;
|
|
2726
|
+
const code = read16BitHexCode(body, position + 2);
|
|
2638
2727
|
|
|
2639
|
-
|
|
2728
|
+
if (isUnicodeScalarValue(code)) {
|
|
2729
|
+
return {
|
|
2730
|
+
value: String.fromCodePoint(code),
|
|
2731
|
+
size: 6,
|
|
2732
|
+
};
|
|
2733
|
+
} // GraphQL allows JSON-style surrogate pair escape sequences, but only when
|
|
2734
|
+
// a valid pair is formed.
|
|
2735
|
+
|
|
2736
|
+
if (isLeadingSurrogate(code)) {
|
|
2737
|
+
// \u
|
|
2738
|
+
if (
|
|
2739
|
+
body.charCodeAt(position + 6) === 0x005c &&
|
|
2740
|
+
body.charCodeAt(position + 7) === 0x0075
|
|
2741
|
+
) {
|
|
2742
|
+
const trailingCode = read16BitHexCode(body, position + 8);
|
|
2743
|
+
|
|
2744
|
+
if (isTrailingSurrogate(trailingCode)) {
|
|
2745
|
+
// JavaScript defines strings as a sequence of UTF-16 code units and
|
|
2746
|
+
// encodes Unicode code points above U+FFFF using a surrogate pair of
|
|
2747
|
+
// code units. Since this is a surrogate pair escape sequence, just
|
|
2748
|
+
// include both codes into the JavaScript string value. Had JavaScript
|
|
2749
|
+
// not been internally based on UTF-16, then this surrogate pair would
|
|
2750
|
+
// be decoded to retrieve the supplementary code point.
|
|
2751
|
+
return {
|
|
2752
|
+
value: String.fromCodePoint(code, trailingCode),
|
|
2753
|
+
size: 12,
|
|
2754
|
+
};
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2640
2758
|
|
|
2641
|
-
|
|
2759
|
+
throw syntaxError(
|
|
2760
|
+
lexer.source,
|
|
2761
|
+
position,
|
|
2762
|
+
`Invalid Unicode escape sequence: "${body.slice(position, position + 6)}".`,
|
|
2763
|
+
);
|
|
2764
|
+
}
|
|
2765
|
+
/**
|
|
2766
|
+
* Reads four hexadecimal characters and returns the positive integer that 16bit
|
|
2767
|
+
* hexadecimal string represents. For example, "000f" will return 15, and "dead"
|
|
2768
|
+
* will return 57005.
|
|
2769
|
+
*
|
|
2770
|
+
* Returns a negative number if any char was not a valid hexadecimal digit.
|
|
2771
|
+
*/
|
|
2642
2772
|
|
|
2643
|
-
|
|
2773
|
+
function read16BitHexCode(body, position) {
|
|
2774
|
+
// readHexDigit() returns -1 on error. ORing a negative value with any other
|
|
2775
|
+
// value always produces a negative value.
|
|
2776
|
+
return (
|
|
2777
|
+
(readHexDigit(body.charCodeAt(position)) << 12) |
|
|
2778
|
+
(readHexDigit(body.charCodeAt(position + 1)) << 8) |
|
|
2779
|
+
(readHexDigit(body.charCodeAt(position + 2)) << 4) |
|
|
2780
|
+
readHexDigit(body.charCodeAt(position + 3))
|
|
2781
|
+
);
|
|
2782
|
+
}
|
|
2783
|
+
/**
|
|
2784
|
+
* Reads a hexadecimal character and returns its positive integer value (0-15).
|
|
2785
|
+
*
|
|
2786
|
+
* '0' becomes 0, '9' becomes 9
|
|
2787
|
+
* 'A' becomes 10, 'F' becomes 15
|
|
2788
|
+
* 'a' becomes 10, 'f' becomes 15
|
|
2789
|
+
*
|
|
2790
|
+
* Returns -1 if the provided character code was not a valid hexadecimal digit.
|
|
2791
|
+
*
|
|
2792
|
+
* HexDigit :: one of
|
|
2793
|
+
* - `0` `1` `2` `3` `4` `5` `6` `7` `8` `9`
|
|
2794
|
+
* - `A` `B` `C` `D` `E` `F`
|
|
2795
|
+
* - `a` `b` `c` `d` `e` `f`
|
|
2796
|
+
*/
|
|
2644
2797
|
|
|
2645
|
-
|
|
2798
|
+
function readHexDigit(code) {
|
|
2799
|
+
return code >= 0x0030 && code <= 0x0039 // 0-9
|
|
2800
|
+
? code - 0x0030
|
|
2801
|
+
: code >= 0x0041 && code <= 0x0046 // A-F
|
|
2802
|
+
? code - 0x0037
|
|
2803
|
+
: code >= 0x0061 && code <= 0x0066 // a-f
|
|
2804
|
+
? code - 0x0057
|
|
2805
|
+
: -1;
|
|
2806
|
+
}
|
|
2807
|
+
/**
|
|
2808
|
+
* | Escaped Character | Code Point | Character Name |
|
|
2809
|
+
* | ----------------- | ---------- | ---------------------------- |
|
|
2810
|
+
* | `"` | U+0022 | double quote |
|
|
2811
|
+
* | `\` | U+005C | reverse solidus (back slash) |
|
|
2812
|
+
* | `/` | U+002F | solidus (forward slash) |
|
|
2813
|
+
* | `b` | U+0008 | backspace |
|
|
2814
|
+
* | `f` | U+000C | form feed |
|
|
2815
|
+
* | `n` | U+000A | line feed (new line) |
|
|
2816
|
+
* | `r` | U+000D | carriage return |
|
|
2817
|
+
* | `t` | U+0009 | horizontal tab |
|
|
2818
|
+
*/
|
|
2646
2819
|
|
|
2647
|
-
|
|
2820
|
+
function readEscapedCharacter(lexer, position) {
|
|
2821
|
+
const body = lexer.source.body;
|
|
2822
|
+
const code = body.charCodeAt(position + 1);
|
|
2648
2823
|
|
|
2649
|
-
|
|
2824
|
+
switch (code) {
|
|
2825
|
+
case 0x0022:
|
|
2826
|
+
// "
|
|
2827
|
+
return {
|
|
2828
|
+
value: '\u0022',
|
|
2829
|
+
size: 2,
|
|
2830
|
+
};
|
|
2650
2831
|
|
|
2651
|
-
|
|
2832
|
+
case 0x005c:
|
|
2833
|
+
// \
|
|
2834
|
+
return {
|
|
2835
|
+
value: '\u005c',
|
|
2836
|
+
size: 2,
|
|
2837
|
+
};
|
|
2652
2838
|
|
|
2653
|
-
|
|
2839
|
+
case 0x002f:
|
|
2840
|
+
// /
|
|
2841
|
+
return {
|
|
2842
|
+
value: '\u002f',
|
|
2843
|
+
size: 2,
|
|
2844
|
+
};
|
|
2654
2845
|
|
|
2655
|
-
|
|
2846
|
+
case 0x0062:
|
|
2847
|
+
// b
|
|
2848
|
+
return {
|
|
2849
|
+
value: '\u0008',
|
|
2850
|
+
size: 2,
|
|
2851
|
+
};
|
|
2656
2852
|
|
|
2657
|
-
|
|
2853
|
+
case 0x0066:
|
|
2854
|
+
// f
|
|
2855
|
+
return {
|
|
2856
|
+
value: '\u000c',
|
|
2857
|
+
size: 2,
|
|
2858
|
+
};
|
|
2658
2859
|
|
|
2659
|
-
|
|
2860
|
+
case 0x006e:
|
|
2861
|
+
// n
|
|
2862
|
+
return {
|
|
2863
|
+
value: '\u000a',
|
|
2864
|
+
size: 2,
|
|
2865
|
+
};
|
|
2660
2866
|
|
|
2661
|
-
|
|
2867
|
+
case 0x0072:
|
|
2868
|
+
// r
|
|
2869
|
+
return {
|
|
2870
|
+
value: '\u000d',
|
|
2871
|
+
size: 2,
|
|
2872
|
+
};
|
|
2662
2873
|
|
|
2663
|
-
|
|
2874
|
+
case 0x0074:
|
|
2875
|
+
// t
|
|
2876
|
+
return {
|
|
2877
|
+
value: '\u0009',
|
|
2878
|
+
size: 2,
|
|
2879
|
+
};
|
|
2880
|
+
}
|
|
2664
2881
|
|
|
2665
|
-
|
|
2882
|
+
throw syntaxError(
|
|
2883
|
+
lexer.source,
|
|
2884
|
+
position,
|
|
2885
|
+
`Invalid character escape sequence: "${body.slice(
|
|
2886
|
+
position,
|
|
2887
|
+
position + 2,
|
|
2888
|
+
)}".`,
|
|
2889
|
+
);
|
|
2890
|
+
}
|
|
2891
|
+
/**
|
|
2892
|
+
* Reads a block string token from the source file.
|
|
2893
|
+
*
|
|
2894
|
+
* ```
|
|
2895
|
+
* StringValue ::
|
|
2896
|
+
* - `"""` BlockStringCharacter* `"""`
|
|
2897
|
+
*
|
|
2898
|
+
* BlockStringCharacter ::
|
|
2899
|
+
* - SourceCharacter but not `"""` or `\"""`
|
|
2900
|
+
* - `\"""`
|
|
2901
|
+
* ```
|
|
2902
|
+
*/
|
|
2666
2903
|
|
|
2667
|
-
|
|
2904
|
+
function readBlockString(lexer, start) {
|
|
2905
|
+
const body = lexer.source.body;
|
|
2906
|
+
const bodyLength = body.length;
|
|
2907
|
+
let lineStart = lexer.lineStart;
|
|
2908
|
+
let position = start + 3;
|
|
2909
|
+
let chunkStart = position;
|
|
2910
|
+
let currentLine = '';
|
|
2911
|
+
const blockLines = [];
|
|
2912
|
+
|
|
2913
|
+
while (position < bodyLength) {
|
|
2914
|
+
const code = body.charCodeAt(position); // Closing Triple-Quote (""")
|
|
2915
|
+
|
|
2916
|
+
if (
|
|
2917
|
+
code === 0x0022 &&
|
|
2918
|
+
body.charCodeAt(position + 1) === 0x0022 &&
|
|
2919
|
+
body.charCodeAt(position + 2) === 0x0022
|
|
2920
|
+
) {
|
|
2921
|
+
currentLine += body.slice(chunkStart, position);
|
|
2922
|
+
blockLines.push(currentLine);
|
|
2923
|
+
const token = createToken(
|
|
2924
|
+
lexer,
|
|
2925
|
+
TokenKind.BLOCK_STRING,
|
|
2926
|
+
start,
|
|
2927
|
+
position + 3, // Return a string of the lines joined with U+000A.
|
|
2928
|
+
dedentBlockStringLines(blockLines).join('\n'),
|
|
2929
|
+
);
|
|
2930
|
+
lexer.line += blockLines.length - 1;
|
|
2931
|
+
lexer.lineStart = lineStart;
|
|
2932
|
+
return token;
|
|
2933
|
+
} // Escaped Triple-Quote (\""")
|
|
2668
2934
|
|
|
2669
|
-
|
|
2935
|
+
if (
|
|
2936
|
+
code === 0x005c &&
|
|
2937
|
+
body.charCodeAt(position + 1) === 0x0022 &&
|
|
2938
|
+
body.charCodeAt(position + 2) === 0x0022 &&
|
|
2939
|
+
body.charCodeAt(position + 3) === 0x0022
|
|
2940
|
+
) {
|
|
2941
|
+
currentLine += body.slice(chunkStart, position);
|
|
2942
|
+
chunkStart = position + 1; // skip only slash
|
|
2670
2943
|
|
|
2671
|
-
|
|
2944
|
+
position += 4;
|
|
2945
|
+
continue;
|
|
2946
|
+
} // LineTerminator
|
|
2672
2947
|
|
|
2673
|
-
|
|
2948
|
+
if (code === 0x000a || code === 0x000d) {
|
|
2949
|
+
currentLine += body.slice(chunkStart, position);
|
|
2950
|
+
blockLines.push(currentLine);
|
|
2674
2951
|
|
|
2675
|
-
|
|
2952
|
+
if (code === 0x000d && body.charCodeAt(position + 1) === 0x000a) {
|
|
2953
|
+
position += 2;
|
|
2954
|
+
} else {
|
|
2955
|
+
++position;
|
|
2956
|
+
}
|
|
2676
2957
|
|
|
2677
|
-
|
|
2958
|
+
currentLine = '';
|
|
2959
|
+
chunkStart = position;
|
|
2960
|
+
lineStart = position;
|
|
2961
|
+
continue;
|
|
2962
|
+
} // SourceCharacter
|
|
2678
2963
|
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2964
|
+
if (isUnicodeScalarValue(code)) {
|
|
2965
|
+
++position;
|
|
2966
|
+
} else if (isSupplementaryCodePoint(body, position)) {
|
|
2967
|
+
position += 2;
|
|
2968
|
+
} else {
|
|
2969
|
+
throw syntaxError(
|
|
2970
|
+
lexer.source,
|
|
2971
|
+
position,
|
|
2972
|
+
`Invalid character within String: ${printCodePointAt(
|
|
2973
|
+
lexer,
|
|
2974
|
+
position,
|
|
2975
|
+
)}.`,
|
|
2976
|
+
);
|
|
2682
2977
|
}
|
|
2683
|
-
|
|
2684
|
-
throw syntaxError(source, pos, unexpectedCharacterMessage(code));
|
|
2685
2978
|
}
|
|
2686
2979
|
|
|
2687
|
-
|
|
2688
|
-
var col = 1 + pos - lexer.lineStart;
|
|
2689
|
-
return new Token(TokenKind.EOF, bodyLength, bodyLength, line, col, prev);
|
|
2980
|
+
throw syntaxError(lexer.source, position, 'Unterminated string.');
|
|
2690
2981
|
}
|
|
2691
2982
|
/**
|
|
2692
|
-
*
|
|
2983
|
+
* Reads an alphanumeric + underscore name from the source.
|
|
2984
|
+
*
|
|
2985
|
+
* ```
|
|
2986
|
+
* Name ::
|
|
2987
|
+
* - NameStart NameContinue* [lookahead != NameContinue]
|
|
2988
|
+
* ```
|
|
2693
2989
|
*/
|
|
2694
2990
|
|
|
2991
|
+
function readName(lexer, start) {
|
|
2992
|
+
const body = lexer.source.body;
|
|
2993
|
+
const bodyLength = body.length;
|
|
2994
|
+
let position = start + 1;
|
|
2695
2995
|
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
return "Cannot contain the invalid character ".concat(printCharCode(code), ".");
|
|
2699
|
-
}
|
|
2996
|
+
while (position < bodyLength) {
|
|
2997
|
+
const code = body.charCodeAt(position);
|
|
2700
2998
|
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2999
|
+
if (isNameContinue(code)) {
|
|
3000
|
+
++position;
|
|
3001
|
+
} else {
|
|
3002
|
+
break;
|
|
3003
|
+
}
|
|
2704
3004
|
}
|
|
2705
3005
|
|
|
2706
|
-
return
|
|
3006
|
+
return createToken(
|
|
3007
|
+
lexer,
|
|
3008
|
+
TokenKind.NAME,
|
|
3009
|
+
start,
|
|
3010
|
+
position,
|
|
3011
|
+
body.slice(start, position),
|
|
3012
|
+
);
|
|
2707
3013
|
}
|
|
2708
|
-
/**
|
|
2709
|
-
* Reads a comment token from the source file.
|
|
2710
|
-
*
|
|
2711
|
-
* #[\u0009\u0020-\uFFFF]*
|
|
2712
|
-
*/
|
|
2713
|
-
|
|
2714
3014
|
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
var code;
|
|
2718
|
-
var position = start;
|
|
2719
|
-
|
|
2720
|
-
do {
|
|
2721
|
-
code = body.charCodeAt(++position);
|
|
2722
|
-
} while (!isNaN(code) && ( // SourceCharacter but not LineTerminator
|
|
2723
|
-
code > 0x001f || code === 0x0009));
|
|
2724
|
-
|
|
2725
|
-
return new Token(TokenKind.COMMENT, start, position, line, col, prev, body.slice(start + 1, position));
|
|
2726
|
-
}
|
|
3015
|
+
const MAX_ARRAY_LENGTH = 10;
|
|
3016
|
+
const MAX_RECURSIVE_DEPTH = 2;
|
|
2727
3017
|
/**
|
|
2728
|
-
*
|
|
2729
|
-
* or an int depending on whether a decimal point appears.
|
|
2730
|
-
*
|
|
2731
|
-
* Int: -?(0|[1-9][0-9]*)
|
|
2732
|
-
* Float: -?(0|[1-9][0-9]*)(\.[0-9]+)?((E|e)(+|-)?[0-9]+)?
|
|
3018
|
+
* Used to print values in error messages.
|
|
2733
3019
|
*/
|
|
2734
3020
|
|
|
3021
|
+
function inspect(value) {
|
|
3022
|
+
return formatValue(value, []);
|
|
3023
|
+
}
|
|
2735
3024
|
|
|
2736
|
-
function
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
var isFloat = false;
|
|
3025
|
+
function formatValue(value, seenValues) {
|
|
3026
|
+
switch (typeof value) {
|
|
3027
|
+
case 'string':
|
|
3028
|
+
return JSON.stringify(value);
|
|
2741
3029
|
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
code = body.charCodeAt(++position);
|
|
2745
|
-
}
|
|
3030
|
+
case 'function':
|
|
3031
|
+
return value.name ? `[function ${value.name}]` : '[function]';
|
|
2746
3032
|
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
code = body.charCodeAt(++position);
|
|
3033
|
+
case 'object':
|
|
3034
|
+
return formatObjectValue(value, seenValues);
|
|
2750
3035
|
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
}
|
|
2754
|
-
} else {
|
|
2755
|
-
position = readDigits(source, position, code);
|
|
2756
|
-
code = body.charCodeAt(position);
|
|
3036
|
+
default:
|
|
3037
|
+
return String(value);
|
|
2757
3038
|
}
|
|
3039
|
+
}
|
|
2758
3040
|
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
code = body.charCodeAt(++position);
|
|
2763
|
-
position = readDigits(source, position, code);
|
|
2764
|
-
code = body.charCodeAt(position);
|
|
3041
|
+
function formatObjectValue(value, previouslySeenValues) {
|
|
3042
|
+
if (value === null) {
|
|
3043
|
+
return 'null';
|
|
2765
3044
|
}
|
|
2766
3045
|
|
|
2767
|
-
if (
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
code = body.charCodeAt(++position);
|
|
2771
|
-
|
|
2772
|
-
if (code === 43 || code === 45) {
|
|
2773
|
-
// + -
|
|
2774
|
-
code = body.charCodeAt(++position);
|
|
2775
|
-
}
|
|
3046
|
+
if (previouslySeenValues.includes(value)) {
|
|
3047
|
+
return '[Circular]';
|
|
3048
|
+
}
|
|
2776
3049
|
|
|
2777
|
-
|
|
2778
|
-
code = body.charCodeAt(position);
|
|
2779
|
-
} // Numbers cannot be followed by . or NameStart
|
|
3050
|
+
const seenValues = [...previouslySeenValues, value];
|
|
2780
3051
|
|
|
3052
|
+
if (isJSONable(value)) {
|
|
3053
|
+
const jsonValue = value.toJSON(); // check for infinite recursion
|
|
2781
3054
|
|
|
2782
|
-
|
|
2783
|
-
|
|
3055
|
+
if (jsonValue !== value) {
|
|
3056
|
+
return typeof jsonValue === 'string'
|
|
3057
|
+
? jsonValue
|
|
3058
|
+
: formatValue(jsonValue, seenValues);
|
|
3059
|
+
}
|
|
3060
|
+
} else if (Array.isArray(value)) {
|
|
3061
|
+
return formatArray(value, seenValues);
|
|
2784
3062
|
}
|
|
2785
3063
|
|
|
2786
|
-
return
|
|
3064
|
+
return formatObject(value, seenValues);
|
|
2787
3065
|
}
|
|
2788
|
-
/**
|
|
2789
|
-
* Returns the new position in the source after reading digits.
|
|
2790
|
-
*/
|
|
2791
3066
|
|
|
3067
|
+
function isJSONable(value) {
|
|
3068
|
+
return typeof value.toJSON === 'function';
|
|
3069
|
+
}
|
|
2792
3070
|
|
|
2793
|
-
function
|
|
2794
|
-
|
|
2795
|
-
var position = start;
|
|
2796
|
-
var code = firstCode;
|
|
2797
|
-
|
|
2798
|
-
if (code >= 48 && code <= 57) {
|
|
2799
|
-
// 0 - 9
|
|
2800
|
-
do {
|
|
2801
|
-
code = body.charCodeAt(++position);
|
|
2802
|
-
} while (code >= 48 && code <= 57); // 0 - 9
|
|
3071
|
+
function formatObject(object, seenValues) {
|
|
3072
|
+
const entries = Object.entries(object);
|
|
2803
3073
|
|
|
3074
|
+
if (entries.length === 0) {
|
|
3075
|
+
return '{}';
|
|
3076
|
+
}
|
|
2804
3077
|
|
|
2805
|
-
|
|
3078
|
+
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
|
3079
|
+
return '[' + getObjectTag(object) + ']';
|
|
2806
3080
|
}
|
|
2807
3081
|
|
|
2808
|
-
|
|
3082
|
+
const properties = entries.map(
|
|
3083
|
+
([key, value]) => key + ': ' + formatValue(value, seenValues),
|
|
3084
|
+
);
|
|
3085
|
+
return '{ ' + properties.join(', ') + ' }';
|
|
2809
3086
|
}
|
|
2810
|
-
/**
|
|
2811
|
-
* Reads a string token from the source file.
|
|
2812
|
-
*
|
|
2813
|
-
* "([^"\\\u000A\u000D]|(\\(u[0-9a-fA-F]{4}|["\\/bfnrt])))*"
|
|
2814
|
-
*/
|
|
2815
3087
|
|
|
3088
|
+
function formatArray(array, seenValues) {
|
|
3089
|
+
if (array.length === 0) {
|
|
3090
|
+
return '[]';
|
|
3091
|
+
}
|
|
2816
3092
|
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
var chunkStart = position;
|
|
2821
|
-
var code = 0;
|
|
2822
|
-
var value = '';
|
|
2823
|
-
|
|
2824
|
-
while (position < body.length && !isNaN(code = body.charCodeAt(position)) && // not LineTerminator
|
|
2825
|
-
code !== 0x000a && code !== 0x000d) {
|
|
2826
|
-
// Closing Quote (")
|
|
2827
|
-
if (code === 34) {
|
|
2828
|
-
value += body.slice(chunkStart, position);
|
|
2829
|
-
return new Token(TokenKind.STRING, start, position + 1, line, col, prev, value);
|
|
2830
|
-
} // SourceCharacter
|
|
3093
|
+
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
|
3094
|
+
return '[Array]';
|
|
3095
|
+
}
|
|
2831
3096
|
|
|
3097
|
+
const len = Math.min(MAX_ARRAY_LENGTH, array.length);
|
|
3098
|
+
const remaining = array.length - len;
|
|
3099
|
+
const items = [];
|
|
2832
3100
|
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
3101
|
+
for (let i = 0; i < len; ++i) {
|
|
3102
|
+
items.push(formatValue(array[i], seenValues));
|
|
3103
|
+
}
|
|
2836
3104
|
|
|
2837
|
-
|
|
3105
|
+
if (remaining === 1) {
|
|
3106
|
+
items.push('... 1 more item');
|
|
3107
|
+
} else if (remaining > 1) {
|
|
3108
|
+
items.push(`... ${remaining} more items`);
|
|
3109
|
+
}
|
|
2838
3110
|
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
value += body.slice(chunkStart, position - 1);
|
|
2842
|
-
code = body.charCodeAt(position);
|
|
2843
|
-
|
|
2844
|
-
switch (code) {
|
|
2845
|
-
case 34:
|
|
2846
|
-
value += '"';
|
|
2847
|
-
break;
|
|
2848
|
-
|
|
2849
|
-
case 47:
|
|
2850
|
-
value += '/';
|
|
2851
|
-
break;
|
|
2852
|
-
|
|
2853
|
-
case 92:
|
|
2854
|
-
value += '\\';
|
|
2855
|
-
break;
|
|
2856
|
-
|
|
2857
|
-
case 98:
|
|
2858
|
-
value += '\b';
|
|
2859
|
-
break;
|
|
2860
|
-
|
|
2861
|
-
case 102:
|
|
2862
|
-
value += '\f';
|
|
2863
|
-
break;
|
|
2864
|
-
|
|
2865
|
-
case 110:
|
|
2866
|
-
value += '\n';
|
|
2867
|
-
break;
|
|
2868
|
-
|
|
2869
|
-
case 114:
|
|
2870
|
-
value += '\r';
|
|
2871
|
-
break;
|
|
2872
|
-
|
|
2873
|
-
case 116:
|
|
2874
|
-
value += '\t';
|
|
2875
|
-
break;
|
|
2876
|
-
|
|
2877
|
-
case 117:
|
|
2878
|
-
{
|
|
2879
|
-
// uXXXX
|
|
2880
|
-
var charCode = uniCharCode(body.charCodeAt(position + 1), body.charCodeAt(position + 2), body.charCodeAt(position + 3), body.charCodeAt(position + 4));
|
|
2881
|
-
|
|
2882
|
-
if (charCode < 0) {
|
|
2883
|
-
var invalidSequence = body.slice(position + 1, position + 5);
|
|
2884
|
-
throw syntaxError(source, position, "Invalid character escape sequence: \\u".concat(invalidSequence, "."));
|
|
2885
|
-
}
|
|
3111
|
+
return '[' + items.join(', ') + ']';
|
|
3112
|
+
}
|
|
2886
3113
|
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
3114
|
+
function getObjectTag(object) {
|
|
3115
|
+
const tag = Object.prototype.toString
|
|
3116
|
+
.call(object)
|
|
3117
|
+
.replace(/^\[object /, '')
|
|
3118
|
+
.replace(/]$/, '');
|
|
2891
3119
|
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
}
|
|
3120
|
+
if (tag === 'Object' && typeof object.constructor === 'function') {
|
|
3121
|
+
const name = object.constructor.name;
|
|
2895
3122
|
|
|
2896
|
-
|
|
2897
|
-
|
|
3123
|
+
if (typeof name === 'string' && name !== '') {
|
|
3124
|
+
return name;
|
|
2898
3125
|
}
|
|
2899
3126
|
}
|
|
2900
3127
|
|
|
2901
|
-
|
|
3128
|
+
return tag;
|
|
2902
3129
|
}
|
|
3130
|
+
|
|
2903
3131
|
/**
|
|
2904
|
-
*
|
|
2905
|
-
*
|
|
2906
|
-
*
|
|
3132
|
+
* A replacement for instanceof which includes an error warning when multi-realm
|
|
3133
|
+
* constructors are detected.
|
|
3134
|
+
* See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
|
|
3135
|
+
* See: https://webpack.js.org/guides/production/
|
|
2907
3136
|
*/
|
|
2908
3137
|
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
var rawValue = '';
|
|
2916
|
-
|
|
2917
|
-
while (position < body.length && !isNaN(code = body.charCodeAt(position))) {
|
|
2918
|
-
// Closing Triple-Quote (""")
|
|
2919
|
-
if (code === 34 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34) {
|
|
2920
|
-
rawValue += body.slice(chunkStart, position);
|
|
2921
|
-
return new Token(TokenKind.BLOCK_STRING, start, position + 3, line, col, prev, dedentBlockStringValue(rawValue));
|
|
2922
|
-
} // SourceCharacter
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
|
|
2926
|
-
throw syntaxError(source, position, "Invalid character within String: ".concat(printCharCode(code), "."));
|
|
2927
|
-
}
|
|
2928
|
-
|
|
2929
|
-
if (code === 10) {
|
|
2930
|
-
// new line
|
|
2931
|
-
++position;
|
|
2932
|
-
++lexer.line;
|
|
2933
|
-
lexer.lineStart = position;
|
|
2934
|
-
} else if (code === 13) {
|
|
2935
|
-
// carriage return
|
|
2936
|
-
if (body.charCodeAt(position + 1) === 10) {
|
|
2937
|
-
position += 2;
|
|
2938
|
-
} else {
|
|
2939
|
-
++position;
|
|
3138
|
+
const instanceOf =
|
|
3139
|
+
/* c8 ignore next 5 */
|
|
3140
|
+
// FIXME: https://github.com/graphql/graphql-js/issues/2317
|
|
3141
|
+
process.env.NODE_ENV === 'production'
|
|
3142
|
+
? function instanceOf(value, constructor) {
|
|
3143
|
+
return value instanceof constructor;
|
|
2940
3144
|
}
|
|
3145
|
+
: function instanceOf(value, constructor) {
|
|
3146
|
+
if (value instanceof constructor) {
|
|
3147
|
+
return true;
|
|
3148
|
+
}
|
|
2941
3149
|
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
3150
|
+
if (typeof value === 'object' && value !== null) {
|
|
3151
|
+
var _value$constructor;
|
|
3152
|
+
|
|
3153
|
+
// Prefer Symbol.toStringTag since it is immune to minification.
|
|
3154
|
+
const className = constructor.prototype[Symbol.toStringTag];
|
|
3155
|
+
const valueClassName = // We still need to support constructor's name to detect conflicts with older versions of this library.
|
|
3156
|
+
Symbol.toStringTag in value // @ts-expect-error TS bug see, https://github.com/microsoft/TypeScript/issues/38009
|
|
3157
|
+
? value[Symbol.toStringTag]
|
|
3158
|
+
: (_value$constructor = value.constructor) === null ||
|
|
3159
|
+
_value$constructor === void 0
|
|
3160
|
+
? void 0
|
|
3161
|
+
: _value$constructor.name;
|
|
3162
|
+
|
|
3163
|
+
if (className === valueClassName) {
|
|
3164
|
+
const stringifiedValue = inspect(value);
|
|
3165
|
+
throw new Error(`Cannot use ${className} "${stringifiedValue}" from another module or realm.
|
|
3166
|
+
|
|
3167
|
+
Ensure that there is only one instance of "graphql" in the node_modules
|
|
3168
|
+
directory. If different versions of "graphql" are the dependencies of other
|
|
3169
|
+
relied on modules, use "resolutions" to ensure only one version is installed.
|
|
3170
|
+
|
|
3171
|
+
https://yarnpkg.com/en/docs/selective-version-resolutions
|
|
3172
|
+
|
|
3173
|
+
Duplicate "graphql" modules cannot be used at the same time since different
|
|
3174
|
+
versions may have different capabilities and behavior. The data from one
|
|
3175
|
+
version used in the function from another could produce confusing and
|
|
3176
|
+
spurious results.`);
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
2966
3179
|
|
|
3180
|
+
return false;
|
|
3181
|
+
};
|
|
2967
3182
|
|
|
2968
|
-
function uniCharCode(a, b, c, d) {
|
|
2969
|
-
return char2hex(a) << 12 | char2hex(b) << 8 | char2hex(c) << 4 | char2hex(d);
|
|
2970
|
-
}
|
|
2971
3183
|
/**
|
|
2972
|
-
*
|
|
2973
|
-
*
|
|
2974
|
-
*
|
|
2975
|
-
*
|
|
2976
|
-
*
|
|
2977
|
-
* Returns -1 on error.
|
|
3184
|
+
* A representation of source input to GraphQL. The `name` and `locationOffset` parameters are
|
|
3185
|
+
* optional, but they are useful for clients who store GraphQL documents in source files.
|
|
3186
|
+
* For example, if the GraphQL input starts at line 40 in a file named `Foo.graphql`, it might
|
|
3187
|
+
* be useful for `name` to be `"Foo.graphql"` and location to be `{ line: 40, column: 1 }`.
|
|
3188
|
+
* The `line` and `column` properties in `locationOffset` are 1-indexed.
|
|
2978
3189
|
*/
|
|
3190
|
+
class Source {
|
|
3191
|
+
constructor(
|
|
3192
|
+
body,
|
|
3193
|
+
name = 'GraphQL request',
|
|
3194
|
+
locationOffset = {
|
|
3195
|
+
line: 1,
|
|
3196
|
+
column: 1,
|
|
3197
|
+
},
|
|
3198
|
+
) {
|
|
3199
|
+
typeof body === 'string' ||
|
|
3200
|
+
devAssert(false, `Body must be a string. Received: ${inspect(body)}.`);
|
|
3201
|
+
this.body = body;
|
|
3202
|
+
this.name = name;
|
|
3203
|
+
this.locationOffset = locationOffset;
|
|
3204
|
+
this.locationOffset.line > 0 ||
|
|
3205
|
+
devAssert(
|
|
3206
|
+
false,
|
|
3207
|
+
'line in locationOffset is 1-indexed and must be positive.',
|
|
3208
|
+
);
|
|
3209
|
+
this.locationOffset.column > 0 ||
|
|
3210
|
+
devAssert(
|
|
3211
|
+
false,
|
|
3212
|
+
'column in locationOffset is 1-indexed and must be positive.',
|
|
3213
|
+
);
|
|
3214
|
+
}
|
|
2979
3215
|
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
: a >= 65 && a <= 70 ? a - 55 // A-F
|
|
2984
|
-
: a >= 97 && a <= 102 ? a - 87 // a-f
|
|
2985
|
-
: -1;
|
|
3216
|
+
get [Symbol.toStringTag]() {
|
|
3217
|
+
return 'Source';
|
|
3218
|
+
}
|
|
2986
3219
|
}
|
|
2987
3220
|
/**
|
|
2988
|
-
*
|
|
3221
|
+
* Test if the given value is a Source object.
|
|
2989
3222
|
*
|
|
2990
|
-
*
|
|
3223
|
+
* @internal
|
|
2991
3224
|
*/
|
|
2992
3225
|
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
var body = source.body;
|
|
2996
|
-
var bodyLength = body.length;
|
|
2997
|
-
var position = start + 1;
|
|
2998
|
-
var code = 0;
|
|
2999
|
-
|
|
3000
|
-
while (position !== bodyLength && !isNaN(code = body.charCodeAt(position)) && (code === 95 || // _
|
|
3001
|
-
code >= 48 && code <= 57 || // 0-9
|
|
3002
|
-
code >= 65 && code <= 90 || // A-Z
|
|
3003
|
-
code >= 97 && code <= 122) // a-z
|
|
3004
|
-
) {
|
|
3005
|
-
++position;
|
|
3006
|
-
}
|
|
3007
|
-
|
|
3008
|
-
return new Token(TokenKind.NAME, start, position, line, col, prev, body.slice(start, position));
|
|
3009
|
-
} // _ A-Z a-z
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
function isNameStart(code) {
|
|
3013
|
-
return code === 95 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
3226
|
+
function isSource(source) {
|
|
3227
|
+
return instanceOf(source, Source);
|
|
3014
3228
|
}
|
|
3015
3229
|
|
|
3016
3230
|
/**
|
|
@@ -3022,7 +3236,7 @@ function isNameStart(code) {
|
|
|
3022
3236
|
* Throws GraphQLError if a syntax error is encountered.
|
|
3023
3237
|
*/
|
|
3024
3238
|
function parse$1(source, options) {
|
|
3025
|
-
|
|
3239
|
+
const parser = new Parser(source, options);
|
|
3026
3240
|
return parser.parseDocument();
|
|
3027
3241
|
}
|
|
3028
3242
|
/**
|
|
@@ -3037,9 +3251,9 @@ function parse$1(source, options) {
|
|
|
3037
3251
|
* @internal
|
|
3038
3252
|
*/
|
|
3039
3253
|
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3254
|
+
class Parser {
|
|
3255
|
+
constructor(source, options) {
|
|
3256
|
+
const sourceObj = isSource(source) ? source : new Source(source);
|
|
3043
3257
|
this._lexer = new Lexer(sourceObj);
|
|
3044
3258
|
this._options = options;
|
|
3045
3259
|
}
|
|
@@ -3047,30 +3261,27 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3047
3261
|
* Converts a name lex token into a name parse node.
|
|
3048
3262
|
*/
|
|
3049
3263
|
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
_proto.parseName = function parseName() {
|
|
3054
|
-
var token = this.expectToken(TokenKind.NAME);
|
|
3055
|
-
return {
|
|
3264
|
+
parseName() {
|
|
3265
|
+
const token = this.expectToken(TokenKind.NAME);
|
|
3266
|
+
return this.node(token, {
|
|
3056
3267
|
kind: Kind.NAME,
|
|
3057
3268
|
value: token.value,
|
|
3058
|
-
|
|
3059
|
-
};
|
|
3269
|
+
});
|
|
3060
3270
|
} // Implements the parsing rules in the Document section.
|
|
3061
3271
|
|
|
3062
3272
|
/**
|
|
3063
3273
|
* Document : Definition+
|
|
3064
3274
|
*/
|
|
3065
|
-
;
|
|
3066
3275
|
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
return {
|
|
3276
|
+
parseDocument() {
|
|
3277
|
+
return this.node(this._lexer.token, {
|
|
3070
3278
|
kind: Kind.DOCUMENT,
|
|
3071
|
-
definitions: this.many(
|
|
3072
|
-
|
|
3073
|
-
|
|
3279
|
+
definitions: this.many(
|
|
3280
|
+
TokenKind.SOF,
|
|
3281
|
+
this.parseDefinition,
|
|
3282
|
+
TokenKind.EOF,
|
|
3283
|
+
),
|
|
3284
|
+
});
|
|
3074
3285
|
}
|
|
3075
3286
|
/**
|
|
3076
3287
|
* Definition :
|
|
@@ -3081,40 +3292,81 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3081
3292
|
* ExecutableDefinition :
|
|
3082
3293
|
* - OperationDefinition
|
|
3083
3294
|
* - FragmentDefinition
|
|
3295
|
+
*
|
|
3296
|
+
* TypeSystemDefinition :
|
|
3297
|
+
* - SchemaDefinition
|
|
3298
|
+
* - TypeDefinition
|
|
3299
|
+
* - DirectiveDefinition
|
|
3300
|
+
*
|
|
3301
|
+
* TypeDefinition :
|
|
3302
|
+
* - ScalarTypeDefinition
|
|
3303
|
+
* - ObjectTypeDefinition
|
|
3304
|
+
* - InterfaceTypeDefinition
|
|
3305
|
+
* - UnionTypeDefinition
|
|
3306
|
+
* - EnumTypeDefinition
|
|
3307
|
+
* - InputObjectTypeDefinition
|
|
3084
3308
|
*/
|
|
3085
|
-
;
|
|
3086
3309
|
|
|
3087
|
-
|
|
3088
|
-
if (this.peek(TokenKind.
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
case 'mutation':
|
|
3092
|
-
case 'subscription':
|
|
3093
|
-
return this.parseOperationDefinition();
|
|
3310
|
+
parseDefinition() {
|
|
3311
|
+
if (this.peek(TokenKind.BRACE_L)) {
|
|
3312
|
+
return this.parseOperationDefinition();
|
|
3313
|
+
} // Many definitions begin with a description and require a lookahead.
|
|
3094
3314
|
|
|
3095
|
-
|
|
3096
|
-
|
|
3315
|
+
const hasDescription = this.peekDescription();
|
|
3316
|
+
const keywordToken = hasDescription
|
|
3317
|
+
? this._lexer.lookahead()
|
|
3318
|
+
: this._lexer.token;
|
|
3097
3319
|
|
|
3320
|
+
if (keywordToken.kind === TokenKind.NAME) {
|
|
3321
|
+
switch (keywordToken.value) {
|
|
3098
3322
|
case 'schema':
|
|
3323
|
+
return this.parseSchemaDefinition();
|
|
3324
|
+
|
|
3099
3325
|
case 'scalar':
|
|
3326
|
+
return this.parseScalarTypeDefinition();
|
|
3327
|
+
|
|
3100
3328
|
case 'type':
|
|
3329
|
+
return this.parseObjectTypeDefinition();
|
|
3330
|
+
|
|
3101
3331
|
case 'interface':
|
|
3332
|
+
return this.parseInterfaceTypeDefinition();
|
|
3333
|
+
|
|
3102
3334
|
case 'union':
|
|
3335
|
+
return this.parseUnionTypeDefinition();
|
|
3336
|
+
|
|
3103
3337
|
case 'enum':
|
|
3338
|
+
return this.parseEnumTypeDefinition();
|
|
3339
|
+
|
|
3104
3340
|
case 'input':
|
|
3341
|
+
return this.parseInputObjectTypeDefinition();
|
|
3342
|
+
|
|
3105
3343
|
case 'directive':
|
|
3106
|
-
return this.
|
|
3344
|
+
return this.parseDirectiveDefinition();
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3347
|
+
if (hasDescription) {
|
|
3348
|
+
throw syntaxError(
|
|
3349
|
+
this._lexer.source,
|
|
3350
|
+
this._lexer.token.start,
|
|
3351
|
+
'Unexpected description, descriptions are supported only on type definitions.',
|
|
3352
|
+
);
|
|
3353
|
+
}
|
|
3354
|
+
|
|
3355
|
+
switch (keywordToken.value) {
|
|
3356
|
+
case 'query':
|
|
3357
|
+
case 'mutation':
|
|
3358
|
+
case 'subscription':
|
|
3359
|
+
return this.parseOperationDefinition();
|
|
3360
|
+
|
|
3361
|
+
case 'fragment':
|
|
3362
|
+
return this.parseFragmentDefinition();
|
|
3107
3363
|
|
|
3108
3364
|
case 'extend':
|
|
3109
3365
|
return this.parseTypeSystemExtension();
|
|
3110
3366
|
}
|
|
3111
|
-
} else if (this.peek(TokenKind.BRACE_L)) {
|
|
3112
|
-
return this.parseOperationDefinition();
|
|
3113
|
-
} else if (this.peekDescription()) {
|
|
3114
|
-
return this.parseTypeSystemDefinition();
|
|
3115
3367
|
}
|
|
3116
3368
|
|
|
3117
|
-
throw this.unexpected();
|
|
3369
|
+
throw this.unexpected(keywordToken);
|
|
3118
3370
|
} // Implements the parsing rules in the Operations section.
|
|
3119
3371
|
|
|
3120
3372
|
/**
|
|
@@ -3122,57 +3374,53 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3122
3374
|
* - SelectionSet
|
|
3123
3375
|
* - OperationType Name? VariableDefinitions? Directives? SelectionSet
|
|
3124
3376
|
*/
|
|
3125
|
-
;
|
|
3126
3377
|
|
|
3127
|
-
|
|
3128
|
-
|
|
3378
|
+
parseOperationDefinition() {
|
|
3379
|
+
const start = this._lexer.token;
|
|
3129
3380
|
|
|
3130
3381
|
if (this.peek(TokenKind.BRACE_L)) {
|
|
3131
|
-
return {
|
|
3382
|
+
return this.node(start, {
|
|
3132
3383
|
kind: Kind.OPERATION_DEFINITION,
|
|
3133
|
-
operation:
|
|
3384
|
+
operation: OperationTypeNode.QUERY,
|
|
3134
3385
|
name: undefined,
|
|
3135
3386
|
variableDefinitions: [],
|
|
3136
3387
|
directives: [],
|
|
3137
3388
|
selectionSet: this.parseSelectionSet(),
|
|
3138
|
-
|
|
3139
|
-
};
|
|
3389
|
+
});
|
|
3140
3390
|
}
|
|
3141
3391
|
|
|
3142
|
-
|
|
3143
|
-
|
|
3392
|
+
const operation = this.parseOperationType();
|
|
3393
|
+
let name;
|
|
3144
3394
|
|
|
3145
3395
|
if (this.peek(TokenKind.NAME)) {
|
|
3146
3396
|
name = this.parseName();
|
|
3147
3397
|
}
|
|
3148
3398
|
|
|
3149
|
-
return {
|
|
3399
|
+
return this.node(start, {
|
|
3150
3400
|
kind: Kind.OPERATION_DEFINITION,
|
|
3151
|
-
operation
|
|
3152
|
-
name
|
|
3401
|
+
operation,
|
|
3402
|
+
name,
|
|
3153
3403
|
variableDefinitions: this.parseVariableDefinitions(),
|
|
3154
3404
|
directives: this.parseDirectives(false),
|
|
3155
3405
|
selectionSet: this.parseSelectionSet(),
|
|
3156
|
-
|
|
3157
|
-
};
|
|
3406
|
+
});
|
|
3158
3407
|
}
|
|
3159
3408
|
/**
|
|
3160
3409
|
* OperationType : one of query mutation subscription
|
|
3161
3410
|
*/
|
|
3162
|
-
;
|
|
3163
3411
|
|
|
3164
|
-
|
|
3165
|
-
|
|
3412
|
+
parseOperationType() {
|
|
3413
|
+
const operationToken = this.expectToken(TokenKind.NAME);
|
|
3166
3414
|
|
|
3167
3415
|
switch (operationToken.value) {
|
|
3168
3416
|
case 'query':
|
|
3169
|
-
return
|
|
3417
|
+
return OperationTypeNode.QUERY;
|
|
3170
3418
|
|
|
3171
3419
|
case 'mutation':
|
|
3172
|
-
return
|
|
3420
|
+
return OperationTypeNode.MUTATION;
|
|
3173
3421
|
|
|
3174
3422
|
case 'subscription':
|
|
3175
|
-
return
|
|
3423
|
+
return OperationTypeNode.SUBSCRIPTION;
|
|
3176
3424
|
}
|
|
3177
3425
|
|
|
3178
3426
|
throw this.unexpected(operationToken);
|
|
@@ -3180,53 +3428,56 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3180
3428
|
/**
|
|
3181
3429
|
* VariableDefinitions : ( VariableDefinition+ )
|
|
3182
3430
|
*/
|
|
3183
|
-
;
|
|
3184
3431
|
|
|
3185
|
-
|
|
3186
|
-
return this.optionalMany(
|
|
3432
|
+
parseVariableDefinitions() {
|
|
3433
|
+
return this.optionalMany(
|
|
3434
|
+
TokenKind.PAREN_L,
|
|
3435
|
+
this.parseVariableDefinition,
|
|
3436
|
+
TokenKind.PAREN_R,
|
|
3437
|
+
);
|
|
3187
3438
|
}
|
|
3188
3439
|
/**
|
|
3189
3440
|
* VariableDefinition : Variable : Type DefaultValue? Directives[Const]?
|
|
3190
3441
|
*/
|
|
3191
|
-
;
|
|
3192
3442
|
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
return {
|
|
3443
|
+
parseVariableDefinition() {
|
|
3444
|
+
return this.node(this._lexer.token, {
|
|
3196
3445
|
kind: Kind.VARIABLE_DEFINITION,
|
|
3197
3446
|
variable: this.parseVariable(),
|
|
3198
3447
|
type: (this.expectToken(TokenKind.COLON), this.parseTypeReference()),
|
|
3199
|
-
defaultValue: this.expectOptionalToken(TokenKind.EQUALS)
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3448
|
+
defaultValue: this.expectOptionalToken(TokenKind.EQUALS)
|
|
3449
|
+
? this.parseConstValueLiteral()
|
|
3450
|
+
: undefined,
|
|
3451
|
+
directives: this.parseConstDirectives(),
|
|
3452
|
+
});
|
|
3203
3453
|
}
|
|
3204
3454
|
/**
|
|
3205
3455
|
* Variable : $ Name
|
|
3206
3456
|
*/
|
|
3207
|
-
;
|
|
3208
3457
|
|
|
3209
|
-
|
|
3210
|
-
|
|
3458
|
+
parseVariable() {
|
|
3459
|
+
const start = this._lexer.token;
|
|
3211
3460
|
this.expectToken(TokenKind.DOLLAR);
|
|
3212
|
-
return {
|
|
3461
|
+
return this.node(start, {
|
|
3213
3462
|
kind: Kind.VARIABLE,
|
|
3214
3463
|
name: this.parseName(),
|
|
3215
|
-
|
|
3216
|
-
};
|
|
3464
|
+
});
|
|
3217
3465
|
}
|
|
3218
3466
|
/**
|
|
3467
|
+
* ```
|
|
3219
3468
|
* SelectionSet : { Selection+ }
|
|
3469
|
+
* ```
|
|
3220
3470
|
*/
|
|
3221
|
-
;
|
|
3222
3471
|
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
return {
|
|
3472
|
+
parseSelectionSet() {
|
|
3473
|
+
return this.node(this._lexer.token, {
|
|
3226
3474
|
kind: Kind.SELECTION_SET,
|
|
3227
|
-
selections: this.many(
|
|
3228
|
-
|
|
3229
|
-
|
|
3475
|
+
selections: this.many(
|
|
3476
|
+
TokenKind.BRACE_L,
|
|
3477
|
+
this.parseSelection,
|
|
3478
|
+
TokenKind.BRACE_R,
|
|
3479
|
+
),
|
|
3480
|
+
});
|
|
3230
3481
|
}
|
|
3231
3482
|
/**
|
|
3232
3483
|
* Selection :
|
|
@@ -3234,23 +3485,23 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3234
3485
|
* - FragmentSpread
|
|
3235
3486
|
* - InlineFragment
|
|
3236
3487
|
*/
|
|
3237
|
-
;
|
|
3238
3488
|
|
|
3239
|
-
|
|
3240
|
-
return this.peek(TokenKind.SPREAD)
|
|
3489
|
+
parseSelection() {
|
|
3490
|
+
return this.peek(TokenKind.SPREAD)
|
|
3491
|
+
? this.parseFragment()
|
|
3492
|
+
: this.parseField();
|
|
3241
3493
|
}
|
|
3242
3494
|
/**
|
|
3243
3495
|
* Field : Alias? Name Arguments? Directives? SelectionSet?
|
|
3244
3496
|
*
|
|
3245
3497
|
* Alias : Name :
|
|
3246
3498
|
*/
|
|
3247
|
-
;
|
|
3248
3499
|
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3500
|
+
parseField() {
|
|
3501
|
+
const start = this._lexer.token;
|
|
3502
|
+
const nameOrAlias = this.parseName();
|
|
3503
|
+
let alias;
|
|
3504
|
+
let name;
|
|
3254
3505
|
|
|
3255
3506
|
if (this.expectOptionalToken(TokenKind.COLON)) {
|
|
3256
3507
|
alias = nameOrAlias;
|
|
@@ -3259,50 +3510,42 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3259
3510
|
name = nameOrAlias;
|
|
3260
3511
|
}
|
|
3261
3512
|
|
|
3262
|
-
return {
|
|
3513
|
+
return this.node(start, {
|
|
3263
3514
|
kind: Kind.FIELD,
|
|
3264
|
-
alias
|
|
3265
|
-
name
|
|
3515
|
+
alias,
|
|
3516
|
+
name,
|
|
3266
3517
|
arguments: this.parseArguments(false),
|
|
3267
3518
|
directives: this.parseDirectives(false),
|
|
3268
|
-
selectionSet: this.peek(TokenKind.BRACE_L)
|
|
3269
|
-
|
|
3270
|
-
|
|
3519
|
+
selectionSet: this.peek(TokenKind.BRACE_L)
|
|
3520
|
+
? this.parseSelectionSet()
|
|
3521
|
+
: undefined,
|
|
3522
|
+
});
|
|
3271
3523
|
}
|
|
3272
3524
|
/**
|
|
3273
3525
|
* Arguments[Const] : ( Argument[?Const]+ )
|
|
3274
3526
|
*/
|
|
3275
|
-
;
|
|
3276
3527
|
|
|
3277
|
-
|
|
3278
|
-
|
|
3528
|
+
parseArguments(isConst) {
|
|
3529
|
+
const item = isConst ? this.parseConstArgument : this.parseArgument;
|
|
3279
3530
|
return this.optionalMany(TokenKind.PAREN_L, item, TokenKind.PAREN_R);
|
|
3280
3531
|
}
|
|
3281
3532
|
/**
|
|
3282
3533
|
* Argument[Const] : Name : Value[?Const]
|
|
3283
3534
|
*/
|
|
3284
|
-
;
|
|
3285
3535
|
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3536
|
+
parseArgument(isConst = false) {
|
|
3537
|
+
const start = this._lexer.token;
|
|
3538
|
+
const name = this.parseName();
|
|
3289
3539
|
this.expectToken(TokenKind.COLON);
|
|
3290
|
-
return {
|
|
3540
|
+
return this.node(start, {
|
|
3291
3541
|
kind: Kind.ARGUMENT,
|
|
3292
|
-
name
|
|
3293
|
-
value: this.parseValueLiteral(
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
};
|
|
3542
|
+
name,
|
|
3543
|
+
value: this.parseValueLiteral(isConst),
|
|
3544
|
+
});
|
|
3545
|
+
}
|
|
3297
3546
|
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
return {
|
|
3301
|
-
kind: Kind.ARGUMENT,
|
|
3302
|
-
name: this.parseName(),
|
|
3303
|
-
value: (this.expectToken(TokenKind.COLON), this.parseValueLiteral(true)),
|
|
3304
|
-
loc: this.loc(start)
|
|
3305
|
-
};
|
|
3547
|
+
parseConstArgument() {
|
|
3548
|
+
return this.parseArgument(true);
|
|
3306
3549
|
} // Implements the parsing rules in the Fragments section.
|
|
3307
3550
|
|
|
3308
3551
|
/**
|
|
@@ -3312,29 +3555,26 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3312
3555
|
*
|
|
3313
3556
|
* InlineFragment : ... TypeCondition? Directives? SelectionSet
|
|
3314
3557
|
*/
|
|
3315
|
-
;
|
|
3316
3558
|
|
|
3317
|
-
|
|
3318
|
-
|
|
3559
|
+
parseFragment() {
|
|
3560
|
+
const start = this._lexer.token;
|
|
3319
3561
|
this.expectToken(TokenKind.SPREAD);
|
|
3320
|
-
|
|
3562
|
+
const hasTypeCondition = this.expectOptionalKeyword('on');
|
|
3321
3563
|
|
|
3322
3564
|
if (!hasTypeCondition && this.peek(TokenKind.NAME)) {
|
|
3323
|
-
return {
|
|
3565
|
+
return this.node(start, {
|
|
3324
3566
|
kind: Kind.FRAGMENT_SPREAD,
|
|
3325
3567
|
name: this.parseFragmentName(),
|
|
3326
3568
|
directives: this.parseDirectives(false),
|
|
3327
|
-
|
|
3328
|
-
};
|
|
3569
|
+
});
|
|
3329
3570
|
}
|
|
3330
3571
|
|
|
3331
|
-
return {
|
|
3572
|
+
return this.node(start, {
|
|
3332
3573
|
kind: Kind.INLINE_FRAGMENT,
|
|
3333
3574
|
typeCondition: hasTypeCondition ? this.parseNamedType() : undefined,
|
|
3334
3575
|
directives: this.parseDirectives(false),
|
|
3335
3576
|
selectionSet: this.parseSelectionSet(),
|
|
3336
|
-
|
|
3337
|
-
};
|
|
3577
|
+
});
|
|
3338
3578
|
}
|
|
3339
3579
|
/**
|
|
3340
3580
|
* FragmentDefinition :
|
|
@@ -3342,43 +3582,43 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3342
3582
|
*
|
|
3343
3583
|
* TypeCondition : NamedType
|
|
3344
3584
|
*/
|
|
3345
|
-
;
|
|
3346
3585
|
|
|
3347
|
-
|
|
3586
|
+
parseFragmentDefinition() {
|
|
3348
3587
|
var _this$_options;
|
|
3349
3588
|
|
|
3350
|
-
|
|
3351
|
-
this.expectKeyword('fragment'); //
|
|
3589
|
+
const start = this._lexer.token;
|
|
3590
|
+
this.expectKeyword('fragment'); // Legacy support for defining variables within fragments changes
|
|
3352
3591
|
// the grammar of FragmentDefinition:
|
|
3353
3592
|
// - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
|
|
3354
3593
|
|
|
3355
|
-
if (
|
|
3356
|
-
|
|
3594
|
+
if (
|
|
3595
|
+
((_this$_options = this._options) === null || _this$_options === void 0
|
|
3596
|
+
? void 0
|
|
3597
|
+
: _this$_options.allowLegacyFragmentVariables) === true
|
|
3598
|
+
) {
|
|
3599
|
+
return this.node(start, {
|
|
3357
3600
|
kind: Kind.FRAGMENT_DEFINITION,
|
|
3358
3601
|
name: this.parseFragmentName(),
|
|
3359
3602
|
variableDefinitions: this.parseVariableDefinitions(),
|
|
3360
3603
|
typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
|
|
3361
3604
|
directives: this.parseDirectives(false),
|
|
3362
3605
|
selectionSet: this.parseSelectionSet(),
|
|
3363
|
-
|
|
3364
|
-
};
|
|
3606
|
+
});
|
|
3365
3607
|
}
|
|
3366
3608
|
|
|
3367
|
-
return {
|
|
3609
|
+
return this.node(start, {
|
|
3368
3610
|
kind: Kind.FRAGMENT_DEFINITION,
|
|
3369
3611
|
name: this.parseFragmentName(),
|
|
3370
3612
|
typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
|
|
3371
3613
|
directives: this.parseDirectives(false),
|
|
3372
3614
|
selectionSet: this.parseSelectionSet(),
|
|
3373
|
-
|
|
3374
|
-
};
|
|
3615
|
+
});
|
|
3375
3616
|
}
|
|
3376
3617
|
/**
|
|
3377
3618
|
* FragmentName : Name but not `on`
|
|
3378
3619
|
*/
|
|
3379
|
-
;
|
|
3380
3620
|
|
|
3381
|
-
|
|
3621
|
+
parseFragmentName() {
|
|
3382
3622
|
if (this._lexer.token.value === 'on') {
|
|
3383
3623
|
throw this.unexpected();
|
|
3384
3624
|
}
|
|
@@ -3404,10 +3644,9 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3404
3644
|
*
|
|
3405
3645
|
* EnumValue : Name but not `true`, `false` or `null`
|
|
3406
3646
|
*/
|
|
3407
|
-
;
|
|
3408
3647
|
|
|
3409
|
-
|
|
3410
|
-
|
|
3648
|
+
parseValueLiteral(isConst) {
|
|
3649
|
+
const token = this._lexer.token;
|
|
3411
3650
|
|
|
3412
3651
|
switch (token.kind) {
|
|
3413
3652
|
case TokenKind.BRACKET_L:
|
|
@@ -3419,20 +3658,18 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3419
3658
|
case TokenKind.INT:
|
|
3420
3659
|
this._lexer.advance();
|
|
3421
3660
|
|
|
3422
|
-
return {
|
|
3661
|
+
return this.node(token, {
|
|
3423
3662
|
kind: Kind.INT,
|
|
3424
3663
|
value: token.value,
|
|
3425
|
-
|
|
3426
|
-
};
|
|
3664
|
+
});
|
|
3427
3665
|
|
|
3428
3666
|
case TokenKind.FLOAT:
|
|
3429
3667
|
this._lexer.advance();
|
|
3430
3668
|
|
|
3431
|
-
return {
|
|
3669
|
+
return this.node(token, {
|
|
3432
3670
|
kind: Kind.FLOAT,
|
|
3433
3671
|
value: token.value,
|
|
3434
|
-
|
|
3435
|
-
};
|
|
3672
|
+
});
|
|
3436
3673
|
|
|
3437
3674
|
case TokenKind.STRING:
|
|
3438
3675
|
case TokenKind.BLOCK_STRING:
|
|
@@ -3443,124 +3680,118 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3443
3680
|
|
|
3444
3681
|
switch (token.value) {
|
|
3445
3682
|
case 'true':
|
|
3446
|
-
return {
|
|
3683
|
+
return this.node(token, {
|
|
3447
3684
|
kind: Kind.BOOLEAN,
|
|
3448
3685
|
value: true,
|
|
3449
|
-
|
|
3450
|
-
};
|
|
3686
|
+
});
|
|
3451
3687
|
|
|
3452
3688
|
case 'false':
|
|
3453
|
-
return {
|
|
3689
|
+
return this.node(token, {
|
|
3454
3690
|
kind: Kind.BOOLEAN,
|
|
3455
3691
|
value: false,
|
|
3456
|
-
|
|
3457
|
-
};
|
|
3692
|
+
});
|
|
3458
3693
|
|
|
3459
3694
|
case 'null':
|
|
3460
|
-
return {
|
|
3695
|
+
return this.node(token, {
|
|
3461
3696
|
kind: Kind.NULL,
|
|
3462
|
-
|
|
3463
|
-
};
|
|
3697
|
+
});
|
|
3464
3698
|
|
|
3465
3699
|
default:
|
|
3466
|
-
return {
|
|
3700
|
+
return this.node(token, {
|
|
3467
3701
|
kind: Kind.ENUM,
|
|
3468
3702
|
value: token.value,
|
|
3469
|
-
|
|
3470
|
-
};
|
|
3703
|
+
});
|
|
3471
3704
|
}
|
|
3472
3705
|
|
|
3473
3706
|
case TokenKind.DOLLAR:
|
|
3474
|
-
if (
|
|
3475
|
-
|
|
3707
|
+
if (isConst) {
|
|
3708
|
+
this.expectToken(TokenKind.DOLLAR);
|
|
3709
|
+
|
|
3710
|
+
if (this._lexer.token.kind === TokenKind.NAME) {
|
|
3711
|
+
const varName = this._lexer.token.value;
|
|
3712
|
+
throw syntaxError(
|
|
3713
|
+
this._lexer.source,
|
|
3714
|
+
token.start,
|
|
3715
|
+
`Unexpected variable "$${varName}" in constant value.`,
|
|
3716
|
+
);
|
|
3717
|
+
} else {
|
|
3718
|
+
throw this.unexpected(token);
|
|
3719
|
+
}
|
|
3476
3720
|
}
|
|
3477
3721
|
|
|
3478
|
-
|
|
3722
|
+
return this.parseVariable();
|
|
3723
|
+
|
|
3724
|
+
default:
|
|
3725
|
+
throw this.unexpected();
|
|
3479
3726
|
}
|
|
3727
|
+
}
|
|
3480
3728
|
|
|
3481
|
-
|
|
3482
|
-
|
|
3729
|
+
parseConstValueLiteral() {
|
|
3730
|
+
return this.parseValueLiteral(true);
|
|
3731
|
+
}
|
|
3483
3732
|
|
|
3484
|
-
|
|
3485
|
-
|
|
3733
|
+
parseStringLiteral() {
|
|
3734
|
+
const token = this._lexer.token;
|
|
3486
3735
|
|
|
3487
3736
|
this._lexer.advance();
|
|
3488
3737
|
|
|
3489
|
-
return {
|
|
3738
|
+
return this.node(token, {
|
|
3490
3739
|
kind: Kind.STRING,
|
|
3491
3740
|
value: token.value,
|
|
3492
3741
|
block: token.kind === TokenKind.BLOCK_STRING,
|
|
3493
|
-
|
|
3494
|
-
};
|
|
3742
|
+
});
|
|
3495
3743
|
}
|
|
3496
3744
|
/**
|
|
3497
3745
|
* ListValue[Const] :
|
|
3498
3746
|
* - [ ]
|
|
3499
3747
|
* - [ Value[?Const]+ ]
|
|
3500
3748
|
*/
|
|
3501
|
-
;
|
|
3502
|
-
|
|
3503
|
-
_proto.parseList = function parseList(isConst) {
|
|
3504
|
-
var _this = this;
|
|
3505
3749
|
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
var item = function item() {
|
|
3509
|
-
return _this.parseValueLiteral(isConst);
|
|
3510
|
-
};
|
|
3750
|
+
parseList(isConst) {
|
|
3751
|
+
const item = () => this.parseValueLiteral(isConst);
|
|
3511
3752
|
|
|
3512
|
-
return {
|
|
3753
|
+
return this.node(this._lexer.token, {
|
|
3513
3754
|
kind: Kind.LIST,
|
|
3514
3755
|
values: this.any(TokenKind.BRACKET_L, item, TokenKind.BRACKET_R),
|
|
3515
|
-
|
|
3516
|
-
};
|
|
3756
|
+
});
|
|
3517
3757
|
}
|
|
3518
3758
|
/**
|
|
3759
|
+
* ```
|
|
3519
3760
|
* ObjectValue[Const] :
|
|
3520
3761
|
* - { }
|
|
3521
3762
|
* - { ObjectField[?Const]+ }
|
|
3763
|
+
* ```
|
|
3522
3764
|
*/
|
|
3523
|
-
;
|
|
3524
|
-
|
|
3525
|
-
_proto.parseObject = function parseObject(isConst) {
|
|
3526
|
-
var _this2 = this;
|
|
3527
3765
|
|
|
3528
|
-
|
|
3766
|
+
parseObject(isConst) {
|
|
3767
|
+
const item = () => this.parseObjectField(isConst);
|
|
3529
3768
|
|
|
3530
|
-
|
|
3531
|
-
return _this2.parseObjectField(isConst);
|
|
3532
|
-
};
|
|
3533
|
-
|
|
3534
|
-
return {
|
|
3769
|
+
return this.node(this._lexer.token, {
|
|
3535
3770
|
kind: Kind.OBJECT,
|
|
3536
3771
|
fields: this.any(TokenKind.BRACE_L, item, TokenKind.BRACE_R),
|
|
3537
|
-
|
|
3538
|
-
};
|
|
3772
|
+
});
|
|
3539
3773
|
}
|
|
3540
3774
|
/**
|
|
3541
3775
|
* ObjectField[Const] : Name : Value[?Const]
|
|
3542
3776
|
*/
|
|
3543
|
-
;
|
|
3544
3777
|
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3778
|
+
parseObjectField(isConst) {
|
|
3779
|
+
const start = this._lexer.token;
|
|
3780
|
+
const name = this.parseName();
|
|
3548
3781
|
this.expectToken(TokenKind.COLON);
|
|
3549
|
-
return {
|
|
3782
|
+
return this.node(start, {
|
|
3550
3783
|
kind: Kind.OBJECT_FIELD,
|
|
3551
|
-
name
|
|
3784
|
+
name,
|
|
3552
3785
|
value: this.parseValueLiteral(isConst),
|
|
3553
|
-
|
|
3554
|
-
};
|
|
3786
|
+
});
|
|
3555
3787
|
} // Implements the parsing rules in the Directives section.
|
|
3556
3788
|
|
|
3557
3789
|
/**
|
|
3558
3790
|
* Directives[Const] : Directive[?Const]+
|
|
3559
3791
|
*/
|
|
3560
|
-
;
|
|
3561
3792
|
|
|
3562
|
-
|
|
3563
|
-
|
|
3793
|
+
parseDirectives(isConst) {
|
|
3794
|
+
const directives = [];
|
|
3564
3795
|
|
|
3565
3796
|
while (this.peek(TokenKind.AT)) {
|
|
3566
3797
|
directives.push(this.parseDirective(isConst));
|
|
@@ -3568,20 +3799,24 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3568
3799
|
|
|
3569
3800
|
return directives;
|
|
3570
3801
|
}
|
|
3802
|
+
|
|
3803
|
+
parseConstDirectives() {
|
|
3804
|
+
return this.parseDirectives(true);
|
|
3805
|
+
}
|
|
3571
3806
|
/**
|
|
3807
|
+
* ```
|
|
3572
3808
|
* Directive[Const] : @ Name Arguments[?Const]?
|
|
3809
|
+
* ```
|
|
3573
3810
|
*/
|
|
3574
|
-
;
|
|
3575
3811
|
|
|
3576
|
-
|
|
3577
|
-
|
|
3812
|
+
parseDirective(isConst) {
|
|
3813
|
+
const start = this._lexer.token;
|
|
3578
3814
|
this.expectToken(TokenKind.AT);
|
|
3579
|
-
return {
|
|
3815
|
+
return this.node(start, {
|
|
3580
3816
|
kind: Kind.DIRECTIVE,
|
|
3581
3817
|
name: this.parseName(),
|
|
3582
3818
|
arguments: this.parseArguments(isConst),
|
|
3583
|
-
|
|
3584
|
-
};
|
|
3819
|
+
});
|
|
3585
3820
|
} // Implements the parsing rules in the Types section.
|
|
3586
3821
|
|
|
3587
3822
|
/**
|
|
@@ -3590,30 +3825,27 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3590
3825
|
* - ListType
|
|
3591
3826
|
* - NonNullType
|
|
3592
3827
|
*/
|
|
3593
|
-
;
|
|
3594
3828
|
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3829
|
+
parseTypeReference() {
|
|
3830
|
+
const start = this._lexer.token;
|
|
3831
|
+
let type;
|
|
3598
3832
|
|
|
3599
3833
|
if (this.expectOptionalToken(TokenKind.BRACKET_L)) {
|
|
3600
|
-
|
|
3834
|
+
const innerType = this.parseTypeReference();
|
|
3601
3835
|
this.expectToken(TokenKind.BRACKET_R);
|
|
3602
|
-
type = {
|
|
3836
|
+
type = this.node(start, {
|
|
3603
3837
|
kind: Kind.LIST_TYPE,
|
|
3604
|
-
type:
|
|
3605
|
-
|
|
3606
|
-
};
|
|
3838
|
+
type: innerType,
|
|
3839
|
+
});
|
|
3607
3840
|
} else {
|
|
3608
3841
|
type = this.parseNamedType();
|
|
3609
3842
|
}
|
|
3610
3843
|
|
|
3611
3844
|
if (this.expectOptionalToken(TokenKind.BANG)) {
|
|
3612
|
-
return {
|
|
3845
|
+
return this.node(start, {
|
|
3613
3846
|
kind: Kind.NON_NULL_TYPE,
|
|
3614
|
-
type
|
|
3615
|
-
|
|
3616
|
-
};
|
|
3847
|
+
type,
|
|
3848
|
+
});
|
|
3617
3849
|
}
|
|
3618
3850
|
|
|
3619
3851
|
return type;
|
|
@@ -3621,404 +3853,343 @@ var Parser = /*#__PURE__*/function () {
|
|
|
3621
3853
|
/**
|
|
3622
3854
|
* NamedType : Name
|
|
3623
3855
|
*/
|
|
3624
|
-
;
|
|
3625
3856
|
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
return {
|
|
3857
|
+
parseNamedType() {
|
|
3858
|
+
return this.node(this._lexer.token, {
|
|
3629
3859
|
kind: Kind.NAMED_TYPE,
|
|
3630
3860
|
name: this.parseName(),
|
|
3631
|
-
|
|
3632
|
-
};
|
|
3861
|
+
});
|
|
3633
3862
|
} // Implements the parsing rules in the Type Definition section.
|
|
3634
3863
|
|
|
3635
|
-
|
|
3636
|
-
* TypeSystemDefinition :
|
|
3637
|
-
* - SchemaDefinition
|
|
3638
|
-
* - TypeDefinition
|
|
3639
|
-
* - DirectiveDefinition
|
|
3640
|
-
*
|
|
3641
|
-
* TypeDefinition :
|
|
3642
|
-
* - ScalarTypeDefinition
|
|
3643
|
-
* - ObjectTypeDefinition
|
|
3644
|
-
* - InterfaceTypeDefinition
|
|
3645
|
-
* - UnionTypeDefinition
|
|
3646
|
-
* - EnumTypeDefinition
|
|
3647
|
-
* - InputObjectTypeDefinition
|
|
3648
|
-
*/
|
|
3649
|
-
;
|
|
3650
|
-
|
|
3651
|
-
_proto.parseTypeSystemDefinition = function parseTypeSystemDefinition() {
|
|
3652
|
-
// Many definitions begin with a description and require a lookahead.
|
|
3653
|
-
var keywordToken = this.peekDescription() ? this._lexer.lookahead() : this._lexer.token;
|
|
3654
|
-
|
|
3655
|
-
if (keywordToken.kind === TokenKind.NAME) {
|
|
3656
|
-
switch (keywordToken.value) {
|
|
3657
|
-
case 'schema':
|
|
3658
|
-
return this.parseSchemaDefinition();
|
|
3659
|
-
|
|
3660
|
-
case 'scalar':
|
|
3661
|
-
return this.parseScalarTypeDefinition();
|
|
3662
|
-
|
|
3663
|
-
case 'type':
|
|
3664
|
-
return this.parseObjectTypeDefinition();
|
|
3665
|
-
|
|
3666
|
-
case 'interface':
|
|
3667
|
-
return this.parseInterfaceTypeDefinition();
|
|
3668
|
-
|
|
3669
|
-
case 'union':
|
|
3670
|
-
return this.parseUnionTypeDefinition();
|
|
3671
|
-
|
|
3672
|
-
case 'enum':
|
|
3673
|
-
return this.parseEnumTypeDefinition();
|
|
3674
|
-
|
|
3675
|
-
case 'input':
|
|
3676
|
-
return this.parseInputObjectTypeDefinition();
|
|
3677
|
-
|
|
3678
|
-
case 'directive':
|
|
3679
|
-
return this.parseDirectiveDefinition();
|
|
3680
|
-
}
|
|
3681
|
-
}
|
|
3682
|
-
|
|
3683
|
-
throw this.unexpected(keywordToken);
|
|
3684
|
-
};
|
|
3685
|
-
|
|
3686
|
-
_proto.peekDescription = function peekDescription() {
|
|
3864
|
+
peekDescription() {
|
|
3687
3865
|
return this.peek(TokenKind.STRING) || this.peek(TokenKind.BLOCK_STRING);
|
|
3688
3866
|
}
|
|
3689
3867
|
/**
|
|
3690
3868
|
* Description : StringValue
|
|
3691
3869
|
*/
|
|
3692
|
-
;
|
|
3693
3870
|
|
|
3694
|
-
|
|
3871
|
+
parseDescription() {
|
|
3695
3872
|
if (this.peekDescription()) {
|
|
3696
3873
|
return this.parseStringLiteral();
|
|
3697
3874
|
}
|
|
3698
3875
|
}
|
|
3699
3876
|
/**
|
|
3877
|
+
* ```
|
|
3700
3878
|
* SchemaDefinition : Description? schema Directives[Const]? { OperationTypeDefinition+ }
|
|
3879
|
+
* ```
|
|
3701
3880
|
*/
|
|
3702
|
-
;
|
|
3703
3881
|
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3882
|
+
parseSchemaDefinition() {
|
|
3883
|
+
const start = this._lexer.token;
|
|
3884
|
+
const description = this.parseDescription();
|
|
3707
3885
|
this.expectKeyword('schema');
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3886
|
+
const directives = this.parseConstDirectives();
|
|
3887
|
+
const operationTypes = this.many(
|
|
3888
|
+
TokenKind.BRACE_L,
|
|
3889
|
+
this.parseOperationTypeDefinition,
|
|
3890
|
+
TokenKind.BRACE_R,
|
|
3891
|
+
);
|
|
3892
|
+
return this.node(start, {
|
|
3711
3893
|
kind: Kind.SCHEMA_DEFINITION,
|
|
3712
|
-
description
|
|
3713
|
-
directives
|
|
3714
|
-
operationTypes
|
|
3715
|
-
|
|
3716
|
-
};
|
|
3894
|
+
description,
|
|
3895
|
+
directives,
|
|
3896
|
+
operationTypes,
|
|
3897
|
+
});
|
|
3717
3898
|
}
|
|
3718
3899
|
/**
|
|
3719
3900
|
* OperationTypeDefinition : OperationType : NamedType
|
|
3720
3901
|
*/
|
|
3721
|
-
;
|
|
3722
3902
|
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3903
|
+
parseOperationTypeDefinition() {
|
|
3904
|
+
const start = this._lexer.token;
|
|
3905
|
+
const operation = this.parseOperationType();
|
|
3726
3906
|
this.expectToken(TokenKind.COLON);
|
|
3727
|
-
|
|
3728
|
-
return {
|
|
3907
|
+
const type = this.parseNamedType();
|
|
3908
|
+
return this.node(start, {
|
|
3729
3909
|
kind: Kind.OPERATION_TYPE_DEFINITION,
|
|
3730
|
-
operation
|
|
3731
|
-
type
|
|
3732
|
-
|
|
3733
|
-
};
|
|
3910
|
+
operation,
|
|
3911
|
+
type,
|
|
3912
|
+
});
|
|
3734
3913
|
}
|
|
3735
3914
|
/**
|
|
3736
3915
|
* ScalarTypeDefinition : Description? scalar Name Directives[Const]?
|
|
3737
3916
|
*/
|
|
3738
|
-
;
|
|
3739
3917
|
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3918
|
+
parseScalarTypeDefinition() {
|
|
3919
|
+
const start = this._lexer.token;
|
|
3920
|
+
const description = this.parseDescription();
|
|
3743
3921
|
this.expectKeyword('scalar');
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
return {
|
|
3922
|
+
const name = this.parseName();
|
|
3923
|
+
const directives = this.parseConstDirectives();
|
|
3924
|
+
return this.node(start, {
|
|
3747
3925
|
kind: Kind.SCALAR_TYPE_DEFINITION,
|
|
3748
|
-
description
|
|
3749
|
-
name
|
|
3750
|
-
directives
|
|
3751
|
-
|
|
3752
|
-
};
|
|
3926
|
+
description,
|
|
3927
|
+
name,
|
|
3928
|
+
directives,
|
|
3929
|
+
});
|
|
3753
3930
|
}
|
|
3754
3931
|
/**
|
|
3755
3932
|
* ObjectTypeDefinition :
|
|
3756
3933
|
* Description?
|
|
3757
3934
|
* type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition?
|
|
3758
3935
|
*/
|
|
3759
|
-
;
|
|
3760
3936
|
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3937
|
+
parseObjectTypeDefinition() {
|
|
3938
|
+
const start = this._lexer.token;
|
|
3939
|
+
const description = this.parseDescription();
|
|
3764
3940
|
this.expectKeyword('type');
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
return {
|
|
3941
|
+
const name = this.parseName();
|
|
3942
|
+
const interfaces = this.parseImplementsInterfaces();
|
|
3943
|
+
const directives = this.parseConstDirectives();
|
|
3944
|
+
const fields = this.parseFieldsDefinition();
|
|
3945
|
+
return this.node(start, {
|
|
3770
3946
|
kind: Kind.OBJECT_TYPE_DEFINITION,
|
|
3771
|
-
description
|
|
3772
|
-
name
|
|
3773
|
-
interfaces
|
|
3774
|
-
directives
|
|
3775
|
-
fields
|
|
3776
|
-
|
|
3777
|
-
};
|
|
3947
|
+
description,
|
|
3948
|
+
name,
|
|
3949
|
+
interfaces,
|
|
3950
|
+
directives,
|
|
3951
|
+
fields,
|
|
3952
|
+
});
|
|
3778
3953
|
}
|
|
3779
3954
|
/**
|
|
3780
3955
|
* ImplementsInterfaces :
|
|
3781
3956
|
* - implements `&`? NamedType
|
|
3782
3957
|
* - ImplementsInterfaces & NamedType
|
|
3783
3958
|
*/
|
|
3784
|
-
;
|
|
3785
|
-
|
|
3786
|
-
_proto.parseImplementsInterfaces = function parseImplementsInterfaces() {
|
|
3787
|
-
var _this$_options2;
|
|
3788
|
-
|
|
3789
|
-
if (!this.expectOptionalKeyword('implements')) {
|
|
3790
|
-
return [];
|
|
3791
|
-
}
|
|
3792
|
-
|
|
3793
|
-
if (((_this$_options2 = this._options) === null || _this$_options2 === void 0 ? void 0 : _this$_options2.allowLegacySDLImplementsInterfaces) === true) {
|
|
3794
|
-
var types = []; // Optional leading ampersand
|
|
3795
|
-
|
|
3796
|
-
this.expectOptionalToken(TokenKind.AMP);
|
|
3797
|
-
|
|
3798
|
-
do {
|
|
3799
|
-
types.push(this.parseNamedType());
|
|
3800
|
-
} while (this.expectOptionalToken(TokenKind.AMP) || this.peek(TokenKind.NAME));
|
|
3801
3959
|
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3960
|
+
parseImplementsInterfaces() {
|
|
3961
|
+
return this.expectOptionalKeyword('implements')
|
|
3962
|
+
? this.delimitedMany(TokenKind.AMP, this.parseNamedType)
|
|
3963
|
+
: [];
|
|
3806
3964
|
}
|
|
3807
3965
|
/**
|
|
3966
|
+
* ```
|
|
3808
3967
|
* FieldsDefinition : { FieldDefinition+ }
|
|
3968
|
+
* ```
|
|
3809
3969
|
*/
|
|
3810
|
-
;
|
|
3811
|
-
|
|
3812
|
-
_proto.parseFieldsDefinition = function parseFieldsDefinition() {
|
|
3813
|
-
var _this$_options3;
|
|
3814
|
-
|
|
3815
|
-
// Legacy support for the SDL?
|
|
3816
|
-
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) {
|
|
3817
|
-
this._lexer.advance();
|
|
3818
|
-
|
|
3819
|
-
this._lexer.advance();
|
|
3820
|
-
|
|
3821
|
-
return [];
|
|
3822
|
-
}
|
|
3823
3970
|
|
|
3824
|
-
|
|
3971
|
+
parseFieldsDefinition() {
|
|
3972
|
+
return this.optionalMany(
|
|
3973
|
+
TokenKind.BRACE_L,
|
|
3974
|
+
this.parseFieldDefinition,
|
|
3975
|
+
TokenKind.BRACE_R,
|
|
3976
|
+
);
|
|
3825
3977
|
}
|
|
3826
3978
|
/**
|
|
3827
3979
|
* FieldDefinition :
|
|
3828
3980
|
* - Description? Name ArgumentsDefinition? : Type Directives[Const]?
|
|
3829
3981
|
*/
|
|
3830
|
-
;
|
|
3831
3982
|
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3983
|
+
parseFieldDefinition() {
|
|
3984
|
+
const start = this._lexer.token;
|
|
3985
|
+
const description = this.parseDescription();
|
|
3986
|
+
const name = this.parseName();
|
|
3987
|
+
const args = this.parseArgumentDefs();
|
|
3837
3988
|
this.expectToken(TokenKind.COLON);
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
return {
|
|
3989
|
+
const type = this.parseTypeReference();
|
|
3990
|
+
const directives = this.parseConstDirectives();
|
|
3991
|
+
return this.node(start, {
|
|
3841
3992
|
kind: Kind.FIELD_DEFINITION,
|
|
3842
|
-
description
|
|
3843
|
-
name
|
|
3993
|
+
description,
|
|
3994
|
+
name,
|
|
3844
3995
|
arguments: args,
|
|
3845
|
-
type
|
|
3846
|
-
directives
|
|
3847
|
-
|
|
3848
|
-
};
|
|
3996
|
+
type,
|
|
3997
|
+
directives,
|
|
3998
|
+
});
|
|
3849
3999
|
}
|
|
3850
4000
|
/**
|
|
3851
4001
|
* ArgumentsDefinition : ( InputValueDefinition+ )
|
|
3852
4002
|
*/
|
|
3853
|
-
;
|
|
3854
4003
|
|
|
3855
|
-
|
|
3856
|
-
return this.optionalMany(
|
|
4004
|
+
parseArgumentDefs() {
|
|
4005
|
+
return this.optionalMany(
|
|
4006
|
+
TokenKind.PAREN_L,
|
|
4007
|
+
this.parseInputValueDef,
|
|
4008
|
+
TokenKind.PAREN_R,
|
|
4009
|
+
);
|
|
3857
4010
|
}
|
|
3858
4011
|
/**
|
|
3859
4012
|
* InputValueDefinition :
|
|
3860
4013
|
* - Description? Name : Type DefaultValue? Directives[Const]?
|
|
3861
4014
|
*/
|
|
3862
|
-
;
|
|
3863
4015
|
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
4016
|
+
parseInputValueDef() {
|
|
4017
|
+
const start = this._lexer.token;
|
|
4018
|
+
const description = this.parseDescription();
|
|
4019
|
+
const name = this.parseName();
|
|
3868
4020
|
this.expectToken(TokenKind.COLON);
|
|
3869
|
-
|
|
3870
|
-
|
|
4021
|
+
const type = this.parseTypeReference();
|
|
4022
|
+
let defaultValue;
|
|
3871
4023
|
|
|
3872
4024
|
if (this.expectOptionalToken(TokenKind.EQUALS)) {
|
|
3873
|
-
defaultValue = this.
|
|
4025
|
+
defaultValue = this.parseConstValueLiteral();
|
|
3874
4026
|
}
|
|
3875
4027
|
|
|
3876
|
-
|
|
3877
|
-
return {
|
|
4028
|
+
const directives = this.parseConstDirectives();
|
|
4029
|
+
return this.node(start, {
|
|
3878
4030
|
kind: Kind.INPUT_VALUE_DEFINITION,
|
|
3879
|
-
description
|
|
3880
|
-
name
|
|
3881
|
-
type
|
|
3882
|
-
defaultValue
|
|
3883
|
-
directives
|
|
3884
|
-
|
|
3885
|
-
};
|
|
4031
|
+
description,
|
|
4032
|
+
name,
|
|
4033
|
+
type,
|
|
4034
|
+
defaultValue,
|
|
4035
|
+
directives,
|
|
4036
|
+
});
|
|
3886
4037
|
}
|
|
3887
4038
|
/**
|
|
3888
4039
|
* InterfaceTypeDefinition :
|
|
3889
4040
|
* - Description? interface Name Directives[Const]? FieldsDefinition?
|
|
3890
4041
|
*/
|
|
3891
|
-
;
|
|
3892
4042
|
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
4043
|
+
parseInterfaceTypeDefinition() {
|
|
4044
|
+
const start = this._lexer.token;
|
|
4045
|
+
const description = this.parseDescription();
|
|
3896
4046
|
this.expectKeyword('interface');
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
return {
|
|
4047
|
+
const name = this.parseName();
|
|
4048
|
+
const interfaces = this.parseImplementsInterfaces();
|
|
4049
|
+
const directives = this.parseConstDirectives();
|
|
4050
|
+
const fields = this.parseFieldsDefinition();
|
|
4051
|
+
return this.node(start, {
|
|
3902
4052
|
kind: Kind.INTERFACE_TYPE_DEFINITION,
|
|
3903
|
-
description
|
|
3904
|
-
name
|
|
3905
|
-
interfaces
|
|
3906
|
-
directives
|
|
3907
|
-
fields
|
|
3908
|
-
|
|
3909
|
-
};
|
|
4053
|
+
description,
|
|
4054
|
+
name,
|
|
4055
|
+
interfaces,
|
|
4056
|
+
directives,
|
|
4057
|
+
fields,
|
|
4058
|
+
});
|
|
3910
4059
|
}
|
|
3911
4060
|
/**
|
|
3912
4061
|
* UnionTypeDefinition :
|
|
3913
4062
|
* - Description? union Name Directives[Const]? UnionMemberTypes?
|
|
3914
4063
|
*/
|
|
3915
|
-
;
|
|
3916
4064
|
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
4065
|
+
parseUnionTypeDefinition() {
|
|
4066
|
+
const start = this._lexer.token;
|
|
4067
|
+
const description = this.parseDescription();
|
|
3920
4068
|
this.expectKeyword('union');
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
return {
|
|
4069
|
+
const name = this.parseName();
|
|
4070
|
+
const directives = this.parseConstDirectives();
|
|
4071
|
+
const types = this.parseUnionMemberTypes();
|
|
4072
|
+
return this.node(start, {
|
|
3925
4073
|
kind: Kind.UNION_TYPE_DEFINITION,
|
|
3926
|
-
description
|
|
3927
|
-
name
|
|
3928
|
-
directives
|
|
3929
|
-
types
|
|
3930
|
-
|
|
3931
|
-
};
|
|
4074
|
+
description,
|
|
4075
|
+
name,
|
|
4076
|
+
directives,
|
|
4077
|
+
types,
|
|
4078
|
+
});
|
|
3932
4079
|
}
|
|
3933
4080
|
/**
|
|
3934
4081
|
* UnionMemberTypes :
|
|
3935
4082
|
* - = `|`? NamedType
|
|
3936
4083
|
* - UnionMemberTypes | NamedType
|
|
3937
4084
|
*/
|
|
3938
|
-
;
|
|
3939
4085
|
|
|
3940
|
-
|
|
3941
|
-
return this.expectOptionalToken(TokenKind.EQUALS)
|
|
4086
|
+
parseUnionMemberTypes() {
|
|
4087
|
+
return this.expectOptionalToken(TokenKind.EQUALS)
|
|
4088
|
+
? this.delimitedMany(TokenKind.PIPE, this.parseNamedType)
|
|
4089
|
+
: [];
|
|
3942
4090
|
}
|
|
3943
4091
|
/**
|
|
3944
4092
|
* EnumTypeDefinition :
|
|
3945
4093
|
* - Description? enum Name Directives[Const]? EnumValuesDefinition?
|
|
3946
4094
|
*/
|
|
3947
|
-
;
|
|
3948
4095
|
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
4096
|
+
parseEnumTypeDefinition() {
|
|
4097
|
+
const start = this._lexer.token;
|
|
4098
|
+
const description = this.parseDescription();
|
|
3952
4099
|
this.expectKeyword('enum');
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
return {
|
|
4100
|
+
const name = this.parseName();
|
|
4101
|
+
const directives = this.parseConstDirectives();
|
|
4102
|
+
const values = this.parseEnumValuesDefinition();
|
|
4103
|
+
return this.node(start, {
|
|
3957
4104
|
kind: Kind.ENUM_TYPE_DEFINITION,
|
|
3958
|
-
description
|
|
3959
|
-
name
|
|
3960
|
-
directives
|
|
3961
|
-
values
|
|
3962
|
-
|
|
3963
|
-
};
|
|
4105
|
+
description,
|
|
4106
|
+
name,
|
|
4107
|
+
directives,
|
|
4108
|
+
values,
|
|
4109
|
+
});
|
|
3964
4110
|
}
|
|
3965
4111
|
/**
|
|
4112
|
+
* ```
|
|
3966
4113
|
* EnumValuesDefinition : { EnumValueDefinition+ }
|
|
4114
|
+
* ```
|
|
3967
4115
|
*/
|
|
3968
|
-
;
|
|
3969
4116
|
|
|
3970
|
-
|
|
3971
|
-
return this.optionalMany(
|
|
4117
|
+
parseEnumValuesDefinition() {
|
|
4118
|
+
return this.optionalMany(
|
|
4119
|
+
TokenKind.BRACE_L,
|
|
4120
|
+
this.parseEnumValueDefinition,
|
|
4121
|
+
TokenKind.BRACE_R,
|
|
4122
|
+
);
|
|
3972
4123
|
}
|
|
3973
4124
|
/**
|
|
3974
4125
|
* EnumValueDefinition : Description? EnumValue Directives[Const]?
|
|
3975
|
-
*
|
|
3976
|
-
* EnumValue : Name
|
|
3977
4126
|
*/
|
|
3978
|
-
;
|
|
3979
4127
|
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
return {
|
|
4128
|
+
parseEnumValueDefinition() {
|
|
4129
|
+
const start = this._lexer.token;
|
|
4130
|
+
const description = this.parseDescription();
|
|
4131
|
+
const name = this.parseEnumValueName();
|
|
4132
|
+
const directives = this.parseConstDirectives();
|
|
4133
|
+
return this.node(start, {
|
|
3986
4134
|
kind: Kind.ENUM_VALUE_DEFINITION,
|
|
3987
|
-
description
|
|
3988
|
-
name
|
|
3989
|
-
directives
|
|
3990
|
-
|
|
3991
|
-
|
|
4135
|
+
description,
|
|
4136
|
+
name,
|
|
4137
|
+
directives,
|
|
4138
|
+
});
|
|
4139
|
+
}
|
|
4140
|
+
/**
|
|
4141
|
+
* EnumValue : Name but not `true`, `false` or `null`
|
|
4142
|
+
*/
|
|
4143
|
+
|
|
4144
|
+
parseEnumValueName() {
|
|
4145
|
+
if (
|
|
4146
|
+
this._lexer.token.value === 'true' ||
|
|
4147
|
+
this._lexer.token.value === 'false' ||
|
|
4148
|
+
this._lexer.token.value === 'null'
|
|
4149
|
+
) {
|
|
4150
|
+
throw syntaxError(
|
|
4151
|
+
this._lexer.source,
|
|
4152
|
+
this._lexer.token.start,
|
|
4153
|
+
`${getTokenDesc(
|
|
4154
|
+
this._lexer.token,
|
|
4155
|
+
)} is reserved and cannot be used for an enum value.`,
|
|
4156
|
+
);
|
|
4157
|
+
}
|
|
4158
|
+
|
|
4159
|
+
return this.parseName();
|
|
3992
4160
|
}
|
|
3993
4161
|
/**
|
|
3994
4162
|
* InputObjectTypeDefinition :
|
|
3995
4163
|
* - Description? input Name Directives[Const]? InputFieldsDefinition?
|
|
3996
4164
|
*/
|
|
3997
|
-
;
|
|
3998
4165
|
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4166
|
+
parseInputObjectTypeDefinition() {
|
|
4167
|
+
const start = this._lexer.token;
|
|
4168
|
+
const description = this.parseDescription();
|
|
4002
4169
|
this.expectKeyword('input');
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
return {
|
|
4170
|
+
const name = this.parseName();
|
|
4171
|
+
const directives = this.parseConstDirectives();
|
|
4172
|
+
const fields = this.parseInputFieldsDefinition();
|
|
4173
|
+
return this.node(start, {
|
|
4007
4174
|
kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
4008
|
-
description
|
|
4009
|
-
name
|
|
4010
|
-
directives
|
|
4011
|
-
fields
|
|
4012
|
-
|
|
4013
|
-
};
|
|
4175
|
+
description,
|
|
4176
|
+
name,
|
|
4177
|
+
directives,
|
|
4178
|
+
fields,
|
|
4179
|
+
});
|
|
4014
4180
|
}
|
|
4015
4181
|
/**
|
|
4182
|
+
* ```
|
|
4016
4183
|
* InputFieldsDefinition : { InputValueDefinition+ }
|
|
4184
|
+
* ```
|
|
4017
4185
|
*/
|
|
4018
|
-
;
|
|
4019
4186
|
|
|
4020
|
-
|
|
4021
|
-
return this.optionalMany(
|
|
4187
|
+
parseInputFieldsDefinition() {
|
|
4188
|
+
return this.optionalMany(
|
|
4189
|
+
TokenKind.BRACE_L,
|
|
4190
|
+
this.parseInputValueDef,
|
|
4191
|
+
TokenKind.BRACE_R,
|
|
4192
|
+
);
|
|
4022
4193
|
}
|
|
4023
4194
|
/**
|
|
4024
4195
|
* TypeSystemExtension :
|
|
@@ -4033,10 +4204,9 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4033
4204
|
* - EnumTypeExtension
|
|
4034
4205
|
* - InputObjectTypeDefinition
|
|
4035
4206
|
*/
|
|
4036
|
-
;
|
|
4037
4207
|
|
|
4038
|
-
|
|
4039
|
-
|
|
4208
|
+
parseTypeSystemExtension() {
|
|
4209
|
+
const keywordToken = this._lexer.lookahead();
|
|
4040
4210
|
|
|
4041
4211
|
if (keywordToken.kind === TokenKind.NAME) {
|
|
4042
4212
|
switch (keywordToken.value) {
|
|
@@ -4066,53 +4236,55 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4066
4236
|
throw this.unexpected(keywordToken);
|
|
4067
4237
|
}
|
|
4068
4238
|
/**
|
|
4239
|
+
* ```
|
|
4069
4240
|
* SchemaExtension :
|
|
4070
4241
|
* - extend schema Directives[Const]? { OperationTypeDefinition+ }
|
|
4071
4242
|
* - extend schema Directives[Const]
|
|
4243
|
+
* ```
|
|
4072
4244
|
*/
|
|
4073
|
-
;
|
|
4074
4245
|
|
|
4075
|
-
|
|
4076
|
-
|
|
4246
|
+
parseSchemaExtension() {
|
|
4247
|
+
const start = this._lexer.token;
|
|
4077
4248
|
this.expectKeyword('extend');
|
|
4078
4249
|
this.expectKeyword('schema');
|
|
4079
|
-
|
|
4080
|
-
|
|
4250
|
+
const directives = this.parseConstDirectives();
|
|
4251
|
+
const operationTypes = this.optionalMany(
|
|
4252
|
+
TokenKind.BRACE_L,
|
|
4253
|
+
this.parseOperationTypeDefinition,
|
|
4254
|
+
TokenKind.BRACE_R,
|
|
4255
|
+
);
|
|
4081
4256
|
|
|
4082
4257
|
if (directives.length === 0 && operationTypes.length === 0) {
|
|
4083
4258
|
throw this.unexpected();
|
|
4084
4259
|
}
|
|
4085
4260
|
|
|
4086
|
-
return {
|
|
4261
|
+
return this.node(start, {
|
|
4087
4262
|
kind: Kind.SCHEMA_EXTENSION,
|
|
4088
|
-
directives
|
|
4089
|
-
operationTypes
|
|
4090
|
-
|
|
4091
|
-
};
|
|
4263
|
+
directives,
|
|
4264
|
+
operationTypes,
|
|
4265
|
+
});
|
|
4092
4266
|
}
|
|
4093
4267
|
/**
|
|
4094
4268
|
* ScalarTypeExtension :
|
|
4095
4269
|
* - extend scalar Name Directives[Const]
|
|
4096
4270
|
*/
|
|
4097
|
-
;
|
|
4098
4271
|
|
|
4099
|
-
|
|
4100
|
-
|
|
4272
|
+
parseScalarTypeExtension() {
|
|
4273
|
+
const start = this._lexer.token;
|
|
4101
4274
|
this.expectKeyword('extend');
|
|
4102
4275
|
this.expectKeyword('scalar');
|
|
4103
|
-
|
|
4104
|
-
|
|
4276
|
+
const name = this.parseName();
|
|
4277
|
+
const directives = this.parseConstDirectives();
|
|
4105
4278
|
|
|
4106
4279
|
if (directives.length === 0) {
|
|
4107
4280
|
throw this.unexpected();
|
|
4108
4281
|
}
|
|
4109
4282
|
|
|
4110
|
-
return {
|
|
4283
|
+
return this.node(start, {
|
|
4111
4284
|
kind: Kind.SCALAR_TYPE_EXTENSION,
|
|
4112
|
-
name
|
|
4113
|
-
directives
|
|
4114
|
-
|
|
4115
|
-
};
|
|
4285
|
+
name,
|
|
4286
|
+
directives,
|
|
4287
|
+
});
|
|
4116
4288
|
}
|
|
4117
4289
|
/**
|
|
4118
4290
|
* ObjectTypeExtension :
|
|
@@ -4120,29 +4292,31 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4120
4292
|
* - extend type Name ImplementsInterfaces? Directives[Const]
|
|
4121
4293
|
* - extend type Name ImplementsInterfaces
|
|
4122
4294
|
*/
|
|
4123
|
-
;
|
|
4124
4295
|
|
|
4125
|
-
|
|
4126
|
-
|
|
4296
|
+
parseObjectTypeExtension() {
|
|
4297
|
+
const start = this._lexer.token;
|
|
4127
4298
|
this.expectKeyword('extend');
|
|
4128
4299
|
this.expectKeyword('type');
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
if (
|
|
4300
|
+
const name = this.parseName();
|
|
4301
|
+
const interfaces = this.parseImplementsInterfaces();
|
|
4302
|
+
const directives = this.parseConstDirectives();
|
|
4303
|
+
const fields = this.parseFieldsDefinition();
|
|
4304
|
+
|
|
4305
|
+
if (
|
|
4306
|
+
interfaces.length === 0 &&
|
|
4307
|
+
directives.length === 0 &&
|
|
4308
|
+
fields.length === 0
|
|
4309
|
+
) {
|
|
4135
4310
|
throw this.unexpected();
|
|
4136
4311
|
}
|
|
4137
4312
|
|
|
4138
|
-
return {
|
|
4313
|
+
return this.node(start, {
|
|
4139
4314
|
kind: Kind.OBJECT_TYPE_EXTENSION,
|
|
4140
|
-
name
|
|
4141
|
-
interfaces
|
|
4142
|
-
directives
|
|
4143
|
-
fields
|
|
4144
|
-
|
|
4145
|
-
};
|
|
4315
|
+
name,
|
|
4316
|
+
interfaces,
|
|
4317
|
+
directives,
|
|
4318
|
+
fields,
|
|
4319
|
+
});
|
|
4146
4320
|
}
|
|
4147
4321
|
/**
|
|
4148
4322
|
* InterfaceTypeExtension :
|
|
@@ -4150,145 +4324,140 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4150
4324
|
* - extend interface Name ImplementsInterfaces? Directives[Const]
|
|
4151
4325
|
* - extend interface Name ImplementsInterfaces
|
|
4152
4326
|
*/
|
|
4153
|
-
;
|
|
4154
4327
|
|
|
4155
|
-
|
|
4156
|
-
|
|
4328
|
+
parseInterfaceTypeExtension() {
|
|
4329
|
+
const start = this._lexer.token;
|
|
4157
4330
|
this.expectKeyword('extend');
|
|
4158
4331
|
this.expectKeyword('interface');
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
if (
|
|
4332
|
+
const name = this.parseName();
|
|
4333
|
+
const interfaces = this.parseImplementsInterfaces();
|
|
4334
|
+
const directives = this.parseConstDirectives();
|
|
4335
|
+
const fields = this.parseFieldsDefinition();
|
|
4336
|
+
|
|
4337
|
+
if (
|
|
4338
|
+
interfaces.length === 0 &&
|
|
4339
|
+
directives.length === 0 &&
|
|
4340
|
+
fields.length === 0
|
|
4341
|
+
) {
|
|
4165
4342
|
throw this.unexpected();
|
|
4166
4343
|
}
|
|
4167
4344
|
|
|
4168
|
-
return {
|
|
4345
|
+
return this.node(start, {
|
|
4169
4346
|
kind: Kind.INTERFACE_TYPE_EXTENSION,
|
|
4170
|
-
name
|
|
4171
|
-
interfaces
|
|
4172
|
-
directives
|
|
4173
|
-
fields
|
|
4174
|
-
|
|
4175
|
-
};
|
|
4347
|
+
name,
|
|
4348
|
+
interfaces,
|
|
4349
|
+
directives,
|
|
4350
|
+
fields,
|
|
4351
|
+
});
|
|
4176
4352
|
}
|
|
4177
4353
|
/**
|
|
4178
4354
|
* UnionTypeExtension :
|
|
4179
4355
|
* - extend union Name Directives[Const]? UnionMemberTypes
|
|
4180
4356
|
* - extend union Name Directives[Const]
|
|
4181
4357
|
*/
|
|
4182
|
-
;
|
|
4183
4358
|
|
|
4184
|
-
|
|
4185
|
-
|
|
4359
|
+
parseUnionTypeExtension() {
|
|
4360
|
+
const start = this._lexer.token;
|
|
4186
4361
|
this.expectKeyword('extend');
|
|
4187
4362
|
this.expectKeyword('union');
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4363
|
+
const name = this.parseName();
|
|
4364
|
+
const directives = this.parseConstDirectives();
|
|
4365
|
+
const types = this.parseUnionMemberTypes();
|
|
4191
4366
|
|
|
4192
4367
|
if (directives.length === 0 && types.length === 0) {
|
|
4193
4368
|
throw this.unexpected();
|
|
4194
4369
|
}
|
|
4195
4370
|
|
|
4196
|
-
return {
|
|
4371
|
+
return this.node(start, {
|
|
4197
4372
|
kind: Kind.UNION_TYPE_EXTENSION,
|
|
4198
|
-
name
|
|
4199
|
-
directives
|
|
4200
|
-
types
|
|
4201
|
-
|
|
4202
|
-
};
|
|
4373
|
+
name,
|
|
4374
|
+
directives,
|
|
4375
|
+
types,
|
|
4376
|
+
});
|
|
4203
4377
|
}
|
|
4204
4378
|
/**
|
|
4205
4379
|
* EnumTypeExtension :
|
|
4206
4380
|
* - extend enum Name Directives[Const]? EnumValuesDefinition
|
|
4207
4381
|
* - extend enum Name Directives[Const]
|
|
4208
4382
|
*/
|
|
4209
|
-
;
|
|
4210
4383
|
|
|
4211
|
-
|
|
4212
|
-
|
|
4384
|
+
parseEnumTypeExtension() {
|
|
4385
|
+
const start = this._lexer.token;
|
|
4213
4386
|
this.expectKeyword('extend');
|
|
4214
4387
|
this.expectKeyword('enum');
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4388
|
+
const name = this.parseName();
|
|
4389
|
+
const directives = this.parseConstDirectives();
|
|
4390
|
+
const values = this.parseEnumValuesDefinition();
|
|
4218
4391
|
|
|
4219
4392
|
if (directives.length === 0 && values.length === 0) {
|
|
4220
4393
|
throw this.unexpected();
|
|
4221
4394
|
}
|
|
4222
4395
|
|
|
4223
|
-
return {
|
|
4396
|
+
return this.node(start, {
|
|
4224
4397
|
kind: Kind.ENUM_TYPE_EXTENSION,
|
|
4225
|
-
name
|
|
4226
|
-
directives
|
|
4227
|
-
values
|
|
4228
|
-
|
|
4229
|
-
};
|
|
4398
|
+
name,
|
|
4399
|
+
directives,
|
|
4400
|
+
values,
|
|
4401
|
+
});
|
|
4230
4402
|
}
|
|
4231
4403
|
/**
|
|
4232
4404
|
* InputObjectTypeExtension :
|
|
4233
4405
|
* - extend input Name Directives[Const]? InputFieldsDefinition
|
|
4234
4406
|
* - extend input Name Directives[Const]
|
|
4235
4407
|
*/
|
|
4236
|
-
;
|
|
4237
4408
|
|
|
4238
|
-
|
|
4239
|
-
|
|
4409
|
+
parseInputObjectTypeExtension() {
|
|
4410
|
+
const start = this._lexer.token;
|
|
4240
4411
|
this.expectKeyword('extend');
|
|
4241
4412
|
this.expectKeyword('input');
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4413
|
+
const name = this.parseName();
|
|
4414
|
+
const directives = this.parseConstDirectives();
|
|
4415
|
+
const fields = this.parseInputFieldsDefinition();
|
|
4245
4416
|
|
|
4246
4417
|
if (directives.length === 0 && fields.length === 0) {
|
|
4247
4418
|
throw this.unexpected();
|
|
4248
4419
|
}
|
|
4249
4420
|
|
|
4250
|
-
return {
|
|
4421
|
+
return this.node(start, {
|
|
4251
4422
|
kind: Kind.INPUT_OBJECT_TYPE_EXTENSION,
|
|
4252
|
-
name
|
|
4253
|
-
directives
|
|
4254
|
-
fields
|
|
4255
|
-
|
|
4256
|
-
};
|
|
4423
|
+
name,
|
|
4424
|
+
directives,
|
|
4425
|
+
fields,
|
|
4426
|
+
});
|
|
4257
4427
|
}
|
|
4258
4428
|
/**
|
|
4429
|
+
* ```
|
|
4259
4430
|
* DirectiveDefinition :
|
|
4260
4431
|
* - Description? directive @ Name ArgumentsDefinition? `repeatable`? on DirectiveLocations
|
|
4432
|
+
* ```
|
|
4261
4433
|
*/
|
|
4262
|
-
;
|
|
4263
4434
|
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4435
|
+
parseDirectiveDefinition() {
|
|
4436
|
+
const start = this._lexer.token;
|
|
4437
|
+
const description = this.parseDescription();
|
|
4267
4438
|
this.expectKeyword('directive');
|
|
4268
4439
|
this.expectToken(TokenKind.AT);
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4440
|
+
const name = this.parseName();
|
|
4441
|
+
const args = this.parseArgumentDefs();
|
|
4442
|
+
const repeatable = this.expectOptionalKeyword('repeatable');
|
|
4272
4443
|
this.expectKeyword('on');
|
|
4273
|
-
|
|
4274
|
-
return {
|
|
4444
|
+
const locations = this.parseDirectiveLocations();
|
|
4445
|
+
return this.node(start, {
|
|
4275
4446
|
kind: Kind.DIRECTIVE_DEFINITION,
|
|
4276
|
-
description
|
|
4277
|
-
name
|
|
4447
|
+
description,
|
|
4448
|
+
name,
|
|
4278
4449
|
arguments: args,
|
|
4279
|
-
repeatable
|
|
4280
|
-
locations
|
|
4281
|
-
|
|
4282
|
-
};
|
|
4450
|
+
repeatable,
|
|
4451
|
+
locations,
|
|
4452
|
+
});
|
|
4283
4453
|
}
|
|
4284
4454
|
/**
|
|
4285
4455
|
* DirectiveLocations :
|
|
4286
4456
|
* - `|`? DirectiveLocation
|
|
4287
4457
|
* - DirectiveLocations | DirectiveLocation
|
|
4288
4458
|
*/
|
|
4289
|
-
;
|
|
4290
4459
|
|
|
4291
|
-
|
|
4460
|
+
parseDirectiveLocations() {
|
|
4292
4461
|
return this.delimitedMany(TokenKind.PIPE, this.parseDirectiveLocation);
|
|
4293
4462
|
}
|
|
4294
4463
|
/*
|
|
@@ -4318,13 +4487,12 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4318
4487
|
* `INPUT_OBJECT`
|
|
4319
4488
|
* `INPUT_FIELD_DEFINITION`
|
|
4320
4489
|
*/
|
|
4321
|
-
;
|
|
4322
4490
|
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4491
|
+
parseDirectiveLocation() {
|
|
4492
|
+
const start = this._lexer.token;
|
|
4493
|
+
const name = this.parseName();
|
|
4326
4494
|
|
|
4327
|
-
if (DirectiveLocation
|
|
4495
|
+
if (Object.prototype.hasOwnProperty.call(DirectiveLocation, name.value)) {
|
|
4328
4496
|
return name;
|
|
4329
4497
|
}
|
|
4330
4498
|
|
|
@@ -4332,33 +4500,42 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4332
4500
|
} // Core parsing utility functions
|
|
4333
4501
|
|
|
4334
4502
|
/**
|
|
4335
|
-
* Returns a
|
|
4503
|
+
* Returns a node that, if configured to do so, sets a "loc" field as a
|
|
4504
|
+
* location object, used to identify the place in the source that created a
|
|
4505
|
+
* given parsed object.
|
|
4336
4506
|
*/
|
|
4337
|
-
;
|
|
4338
4507
|
|
|
4339
|
-
|
|
4340
|
-
var _this$
|
|
4508
|
+
node(startToken, node) {
|
|
4509
|
+
var _this$_options2;
|
|
4341
4510
|
|
|
4342
|
-
if (
|
|
4343
|
-
|
|
4511
|
+
if (
|
|
4512
|
+
((_this$_options2 = this._options) === null || _this$_options2 === void 0
|
|
4513
|
+
? void 0
|
|
4514
|
+
: _this$_options2.noLocation) !== true
|
|
4515
|
+
) {
|
|
4516
|
+
node.loc = new Location(
|
|
4517
|
+
startToken,
|
|
4518
|
+
this._lexer.lastToken,
|
|
4519
|
+
this._lexer.source,
|
|
4520
|
+
);
|
|
4344
4521
|
}
|
|
4522
|
+
|
|
4523
|
+
return node;
|
|
4345
4524
|
}
|
|
4346
4525
|
/**
|
|
4347
4526
|
* Determines if the next token is of a given kind
|
|
4348
4527
|
*/
|
|
4349
|
-
;
|
|
4350
4528
|
|
|
4351
|
-
|
|
4529
|
+
peek(kind) {
|
|
4352
4530
|
return this._lexer.token.kind === kind;
|
|
4353
4531
|
}
|
|
4354
4532
|
/**
|
|
4355
4533
|
* If the next token is of the given kind, return that token after advancing the lexer.
|
|
4356
4534
|
* Otherwise, do not change the parser state and throw an error.
|
|
4357
4535
|
*/
|
|
4358
|
-
;
|
|
4359
4536
|
|
|
4360
|
-
|
|
4361
|
-
|
|
4537
|
+
expectToken(kind) {
|
|
4538
|
+
const token = this._lexer.token;
|
|
4362
4539
|
|
|
4363
4540
|
if (token.kind === kind) {
|
|
4364
4541
|
this._lexer.advance();
|
|
@@ -4366,48 +4543,53 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4366
4543
|
return token;
|
|
4367
4544
|
}
|
|
4368
4545
|
|
|
4369
|
-
throw syntaxError(
|
|
4546
|
+
throw syntaxError(
|
|
4547
|
+
this._lexer.source,
|
|
4548
|
+
token.start,
|
|
4549
|
+
`Expected ${getTokenKindDesc(kind)}, found ${getTokenDesc(token)}.`,
|
|
4550
|
+
);
|
|
4370
4551
|
}
|
|
4371
4552
|
/**
|
|
4372
|
-
* If the next token is of the given kind, return
|
|
4373
|
-
* Otherwise, do not change the parser state and return
|
|
4553
|
+
* If the next token is of the given kind, return "true" after advancing the lexer.
|
|
4554
|
+
* Otherwise, do not change the parser state and return "false".
|
|
4374
4555
|
*/
|
|
4375
|
-
;
|
|
4376
4556
|
|
|
4377
|
-
|
|
4378
|
-
|
|
4557
|
+
expectOptionalToken(kind) {
|
|
4558
|
+
const token = this._lexer.token;
|
|
4379
4559
|
|
|
4380
4560
|
if (token.kind === kind) {
|
|
4381
4561
|
this._lexer.advance();
|
|
4382
4562
|
|
|
4383
|
-
return
|
|
4563
|
+
return true;
|
|
4384
4564
|
}
|
|
4385
4565
|
|
|
4386
|
-
return
|
|
4566
|
+
return false;
|
|
4387
4567
|
}
|
|
4388
4568
|
/**
|
|
4389
4569
|
* If the next token is a given keyword, advance the lexer.
|
|
4390
4570
|
* Otherwise, do not change the parser state and throw an error.
|
|
4391
4571
|
*/
|
|
4392
|
-
;
|
|
4393
4572
|
|
|
4394
|
-
|
|
4395
|
-
|
|
4573
|
+
expectKeyword(value) {
|
|
4574
|
+
const token = this._lexer.token;
|
|
4396
4575
|
|
|
4397
4576
|
if (token.kind === TokenKind.NAME && token.value === value) {
|
|
4398
4577
|
this._lexer.advance();
|
|
4399
4578
|
} else {
|
|
4400
|
-
throw syntaxError(
|
|
4579
|
+
throw syntaxError(
|
|
4580
|
+
this._lexer.source,
|
|
4581
|
+
token.start,
|
|
4582
|
+
`Expected "${value}", found ${getTokenDesc(token)}.`,
|
|
4583
|
+
);
|
|
4401
4584
|
}
|
|
4402
4585
|
}
|
|
4403
4586
|
/**
|
|
4404
4587
|
* If the next token is a given keyword, return "true" after advancing the lexer.
|
|
4405
4588
|
* Otherwise, do not change the parser state and return "false".
|
|
4406
4589
|
*/
|
|
4407
|
-
;
|
|
4408
4590
|
|
|
4409
|
-
|
|
4410
|
-
|
|
4591
|
+
expectOptionalKeyword(value) {
|
|
4592
|
+
const token = this._lexer.token;
|
|
4411
4593
|
|
|
4412
4594
|
if (token.kind === TokenKind.NAME && token.value === value) {
|
|
4413
4595
|
this._lexer.advance();
|
|
@@ -4420,22 +4602,25 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4420
4602
|
/**
|
|
4421
4603
|
* Helper function for creating an error when an unexpected lexed token is encountered.
|
|
4422
4604
|
*/
|
|
4423
|
-
;
|
|
4424
4605
|
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4606
|
+
unexpected(atToken) {
|
|
4607
|
+
const token =
|
|
4608
|
+
atToken !== null && atToken !== void 0 ? atToken : this._lexer.token;
|
|
4609
|
+
return syntaxError(
|
|
4610
|
+
this._lexer.source,
|
|
4611
|
+
token.start,
|
|
4612
|
+
`Unexpected ${getTokenDesc(token)}.`,
|
|
4613
|
+
);
|
|
4428
4614
|
}
|
|
4429
4615
|
/**
|
|
4430
4616
|
* Returns a possibly empty list of parse nodes, determined by the parseFn.
|
|
4431
4617
|
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
4432
4618
|
* Advances the parser to the next lex token after the closing token.
|
|
4433
4619
|
*/
|
|
4434
|
-
;
|
|
4435
4620
|
|
|
4436
|
-
|
|
4621
|
+
any(openKind, parseFn, closeKind) {
|
|
4437
4622
|
this.expectToken(openKind);
|
|
4438
|
-
|
|
4623
|
+
const nodes = [];
|
|
4439
4624
|
|
|
4440
4625
|
while (!this.expectOptionalToken(closeKind)) {
|
|
4441
4626
|
nodes.push(parseFn.call(this));
|
|
@@ -4449,11 +4634,10 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4449
4634
|
* that begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
4450
4635
|
* Advances the parser to the next lex token after the closing token.
|
|
4451
4636
|
*/
|
|
4452
|
-
;
|
|
4453
4637
|
|
|
4454
|
-
|
|
4638
|
+
optionalMany(openKind, parseFn, closeKind) {
|
|
4455
4639
|
if (this.expectOptionalToken(openKind)) {
|
|
4456
|
-
|
|
4640
|
+
const nodes = [];
|
|
4457
4641
|
|
|
4458
4642
|
do {
|
|
4459
4643
|
nodes.push(parseFn.call(this));
|
|
@@ -4469,11 +4653,10 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4469
4653
|
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
4470
4654
|
* Advances the parser to the next lex token after the closing token.
|
|
4471
4655
|
*/
|
|
4472
|
-
;
|
|
4473
4656
|
|
|
4474
|
-
|
|
4657
|
+
many(openKind, parseFn, closeKind) {
|
|
4475
4658
|
this.expectToken(openKind);
|
|
4476
|
-
|
|
4659
|
+
const nodes = [];
|
|
4477
4660
|
|
|
4478
4661
|
do {
|
|
4479
4662
|
nodes.push(parseFn.call(this));
|
|
@@ -4486,36 +4669,32 @@ var Parser = /*#__PURE__*/function () {
|
|
|
4486
4669
|
* This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
|
|
4487
4670
|
* Advances the parser to the next lex token after last item in the list.
|
|
4488
4671
|
*/
|
|
4489
|
-
;
|
|
4490
4672
|
|
|
4491
|
-
|
|
4673
|
+
delimitedMany(delimiterKind, parseFn) {
|
|
4492
4674
|
this.expectOptionalToken(delimiterKind);
|
|
4493
|
-
|
|
4675
|
+
const nodes = [];
|
|
4494
4676
|
|
|
4495
4677
|
do {
|
|
4496
4678
|
nodes.push(parseFn.call(this));
|
|
4497
4679
|
} while (this.expectOptionalToken(delimiterKind));
|
|
4498
4680
|
|
|
4499
4681
|
return nodes;
|
|
4500
|
-
}
|
|
4501
|
-
|
|
4502
|
-
return Parser;
|
|
4503
|
-
}();
|
|
4682
|
+
}
|
|
4683
|
+
}
|
|
4504
4684
|
/**
|
|
4505
4685
|
* A helper function to describe a token as a string for debugging.
|
|
4506
4686
|
*/
|
|
4507
4687
|
|
|
4508
4688
|
function getTokenDesc(token) {
|
|
4509
|
-
|
|
4510
|
-
return getTokenKindDesc(token.kind) + (value != null ?
|
|
4689
|
+
const value = token.value;
|
|
4690
|
+
return getTokenKindDesc(token.kind) + (value != null ? ` "${value}"` : '');
|
|
4511
4691
|
}
|
|
4512
4692
|
/**
|
|
4513
4693
|
* A helper function to describe a token kind as a string for debugging.
|
|
4514
4694
|
*/
|
|
4515
4695
|
|
|
4516
|
-
|
|
4517
4696
|
function getTokenKindDesc(kind) {
|
|
4518
|
-
return isPunctuatorTokenKind(kind) ? "
|
|
4697
|
+
return isPunctuatorTokenKind(kind) ? `"${kind}"` : kind;
|
|
4519
4698
|
}
|
|
4520
4699
|
|
|
4521
4700
|
/**
|
|
@@ -5896,56 +6075,71 @@ ${handlers.map((handler) => ` • ${handler.info.header}`).join('\n')}`;
|
|
|
5896
6075
|
return `Did you mean to request "${handlers[0].info.header}" instead?`;
|
|
5897
6076
|
}
|
|
5898
6077
|
function onUnhandledRequest(request, handlers, strategy = 'warn') {
|
|
5899
|
-
if (typeof strategy === 'function') {
|
|
5900
|
-
strategy(request);
|
|
5901
|
-
return;
|
|
5902
|
-
}
|
|
5903
|
-
/**
|
|
5904
|
-
* @note Ignore exceptions during GraphQL request parsing because at this point
|
|
5905
|
-
* we cannot assume the unhandled request is a valid GraphQL request.
|
|
5906
|
-
* If the GraphQL parsing fails, just don't treat it as a GraphQL request.
|
|
5907
|
-
*/
|
|
5908
6078
|
const parsedGraphQLQuery = tryCatch(() => parseGraphQLRequest(request));
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
6079
|
+
function generateHandlerSuggestion() {
|
|
6080
|
+
/**
|
|
6081
|
+
* @note Ignore exceptions during GraphQL request parsing because at this point
|
|
6082
|
+
* we cannot assume the unhandled request is a valid GraphQL request.
|
|
6083
|
+
* If the GraphQL parsing fails, just don't treat it as a GraphQL request.
|
|
6084
|
+
*/
|
|
6085
|
+
const handlerGroups = groupHandlersByType(handlers);
|
|
6086
|
+
const relevantHandlers = parsedGraphQLQuery
|
|
6087
|
+
? handlerGroups.graphql
|
|
6088
|
+
: handlerGroups.rest;
|
|
6089
|
+
const suggestedHandlers = getSuggestedHandler(request, relevantHandlers, parsedGraphQLQuery
|
|
6090
|
+
? getGraphQLHandlerScore(parsedGraphQLQuery)
|
|
6091
|
+
: getRestHandlerScore());
|
|
6092
|
+
return suggestedHandlers.length > 0
|
|
6093
|
+
? getSuggestedHandlersMessage(suggestedHandlers)
|
|
6094
|
+
: '';
|
|
6095
|
+
}
|
|
6096
|
+
function generateUnhandledRequestMessage() {
|
|
6097
|
+
const publicUrl = getPublicUrlFromRequest(request);
|
|
6098
|
+
const requestHeader = parsedGraphQLQuery
|
|
6099
|
+
? `${parsedGraphQLQuery.operationType} ${parsedGraphQLQuery.operationName} (${request.method} ${publicUrl})`
|
|
6100
|
+
: `${request.method} ${publicUrl}`;
|
|
6101
|
+
const handlerSuggestion = generateHandlerSuggestion();
|
|
6102
|
+
const messageTemplate = [
|
|
6103
|
+
`captured a request without a matching request handler:`,
|
|
6104
|
+
` \u2022 ${requestHeader}`,
|
|
6105
|
+
handlerSuggestion,
|
|
6106
|
+
`\
|
|
5928
6107
|
If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
5929
6108
|
Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
5930
6109
|
`,
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
6110
|
+
].filter(Boolean);
|
|
6111
|
+
return messageTemplate.join('\n\n');
|
|
6112
|
+
}
|
|
6113
|
+
function applyStrategy(strategy) {
|
|
6114
|
+
// Generate handler suggestions only when applying the strategy.
|
|
6115
|
+
// This saves bandwidth for scenarios when developers opt-out
|
|
6116
|
+
// from the default unhandled request handling strategy.
|
|
6117
|
+
const message = generateUnhandledRequestMessage();
|
|
6118
|
+
switch (strategy) {
|
|
6119
|
+
case 'error': {
|
|
6120
|
+
// Print a developer-friendly error.
|
|
6121
|
+
devUtils.error('Error: %s', message);
|
|
6122
|
+
// Throw an exception to halt request processing and not perform the original request.
|
|
6123
|
+
throw new Error(devUtils.formatMessage('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'));
|
|
6124
|
+
}
|
|
6125
|
+
case 'warn': {
|
|
6126
|
+
devUtils.warn('Warning: %s', message);
|
|
6127
|
+
break;
|
|
6128
|
+
}
|
|
6129
|
+
case 'bypass':
|
|
6130
|
+
break;
|
|
6131
|
+
default:
|
|
6132
|
+
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));
|
|
5943
6133
|
}
|
|
5944
|
-
case 'bypass':
|
|
5945
|
-
break;
|
|
5946
|
-
default:
|
|
5947
|
-
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));
|
|
5948
6134
|
}
|
|
6135
|
+
if (typeof strategy === 'function') {
|
|
6136
|
+
strategy(request, {
|
|
6137
|
+
warning: applyStrategy.bind(null, 'warn'),
|
|
6138
|
+
error: applyStrategy.bind(null, 'error'),
|
|
6139
|
+
});
|
|
6140
|
+
return;
|
|
6141
|
+
}
|
|
6142
|
+
applyStrategy(strategy);
|
|
5949
6143
|
}
|
|
5950
6144
|
|
|
5951
6145
|
function readResponseCookies(request, response) {
|
|
@@ -5958,7 +6152,7 @@ function handleRequest(request, handlers, options, emitter, handleRequestOptions
|
|
|
5958
6152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
5959
6153
|
emitter.emit('request:start', request);
|
|
5960
6154
|
// Perform bypassed requests (i.e. issued via "ctx.fetch") as-is.
|
|
5961
|
-
if (request.headers.get('x-msw-bypass')) {
|
|
6155
|
+
if (request.headers.get('x-msw-bypass') === 'true') {
|
|
5962
6156
|
emitter.emit('request:end', request);
|
|
5963
6157
|
(_a = handleRequestOptions === null || handleRequestOptions === void 0 ? void 0 : handleRequestOptions.onBypassResponse) === null || _a === void 0 ? void 0 : _a.call(handleRequestOptions, request);
|
|
5964
6158
|
return;
|