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