@redocly/replay 0.26.0-next.5 → 0.26.0-next.7
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/dist/{replay-index-BPu1BqHH.js → replay-index-8m7VljmC.js} +1 -1
- package/dist/{replay-index-BqiGs7Il.js → replay-index-BcXpxXjf.js} +1 -1
- package/dist/{replay-index-DF13GgIz.js → replay-index-BgDUTBwj.js} +1 -1
- package/dist/{replay-index-BBRlup3F.js → replay-index-C-dfM8Rr.js} +68273 -58628
- package/dist/replay-index-O28D-V6V.js +8150 -0
- package/dist/{replay-index-wnTXJKVO.js → replay-index-adaHAcf5.js} +1 -1
- package/dist/replay-lint-graphql-DBcPhw5r.js +3 -0
- package/dist/replay-lint-graphql-f9UVRzKF.js +1956 -0
- package/dist/replay-respect-run-C95-8OWk.js +78 -0
- package/dist/{replay-respect-run-CSAlWxzM.js → replay-respect-run-iSMABVqQ.js} +3343 -3821
- package/dist/{replay-tauri-path-B3yadp55.js → replay-tauri-path-1DP2Jpon.js} +2 -2
- package/dist/{replay-tauri-path-DZ9ttuuZ.js → replay-tauri-path-DQ1wCI81.js} +1 -1
- package/dist/replay.cjs +1 -1
- package/dist/replay.js +12 -12
- package/package.json +7 -6
- package/dist/replay-index-CCclpj9c.js +0 -8090
- package/dist/replay-respect-run-Bg3z0U_Y.js +0 -81
|
@@ -0,0 +1,1956 @@
|
|
|
1
|
+
import { M as R, T as L, N as k, O as g, P as B, Q as M, R as A, S as U, U as V, V as a, W as T, X as K, Y as G, Z as v, _ as $, $ as Y, a0 as j } from "./replay-index-C-dfM8Rr.js";
|
|
2
|
+
function u(n, t, e) {
|
|
3
|
+
return new R(`Syntax Error: ${e}`, {
|
|
4
|
+
source: n,
|
|
5
|
+
positions: [t]
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
var r;
|
|
9
|
+
(function(n) {
|
|
10
|
+
n.SOF = "<SOF>", n.EOF = "<EOF>", n.BANG = "!", n.DOLLAR = "$", n.AMP = "&", n.PAREN_L = "(", n.PAREN_R = ")", n.DOT = ".", n.SPREAD = "...", n.COLON = ":", n.EQUALS = "=", n.AT = "@", n.BRACKET_L = "[", n.BRACKET_R = "]", n.BRACE_L = "{", n.PIPE = "|", n.BRACE_R = "}", n.NAME = "Name", n.INT = "Int", n.FLOAT = "Float", n.STRING = "String", n.BLOCK_STRING = "BlockString", n.COMMENT = "Comment";
|
|
11
|
+
})(r || (r = {}));
|
|
12
|
+
class q {
|
|
13
|
+
/** Source document used to derive error locations. */
|
|
14
|
+
/** Most recent non-ignored token returned by the lexer. */
|
|
15
|
+
/** Current non-ignored token at the lexer cursor. */
|
|
16
|
+
/** The (1-indexed) line containing the current token. */
|
|
17
|
+
/** Character offset where the current line starts. */
|
|
18
|
+
/**
|
|
19
|
+
* Creates a Lexer instance.
|
|
20
|
+
* @param source - Source document used to derive error locations.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { Lexer, Source, TokenKind } from 'graphql/language';
|
|
24
|
+
*
|
|
25
|
+
* const lexer = new Lexer(new Source('{ hello }'));
|
|
26
|
+
*
|
|
27
|
+
* lexer.token.kind; // => TokenKind.SOF
|
|
28
|
+
* lexer.advance().kind; // => TokenKind.BRACE_L
|
|
29
|
+
* lexer.advance().value; // => 'hello'
|
|
30
|
+
* lexer.advance().kind; // => TokenKind.BRACE_R
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
constructor(t) {
|
|
34
|
+
const e = new L(r.SOF, 0, 0, 0, 0);
|
|
35
|
+
this.source = t, this.lastToken = e, this.token = e, this.line = 1, this.lineStart = 0;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
39
|
+
* @returns The built-in string tag for this object.
|
|
40
|
+
*/
|
|
41
|
+
get [Symbol.toStringTag]() {
|
|
42
|
+
return "Lexer";
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Advances the token stream to the next non-ignored token.
|
|
46
|
+
* @returns The next non-ignored token.
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { Lexer, Source } from 'graphql/language';
|
|
50
|
+
*
|
|
51
|
+
* const lexer = new Lexer(new Source('{ hello }'));
|
|
52
|
+
* const token = lexer.advance();
|
|
53
|
+
*
|
|
54
|
+
* token.kind; // => '{'
|
|
55
|
+
* lexer.token; // => token
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
advance() {
|
|
59
|
+
return this.lastToken = this.token, this.token = this.lookahead();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Looks ahead and returns the next non-ignored token, but does not change
|
|
63
|
+
* the state of Lexer.
|
|
64
|
+
* @returns The next non-ignored token without advancing the lexer.
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { Lexer, Source } from 'graphql/language';
|
|
68
|
+
*
|
|
69
|
+
* const lexer = new Lexer(new Source('{ hello }'));
|
|
70
|
+
* const token = lexer.lookahead();
|
|
71
|
+
*
|
|
72
|
+
* token.kind; // => '{'
|
|
73
|
+
* lexer.token.kind; // => '<SOF>'
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
lookahead() {
|
|
77
|
+
let t = this.token;
|
|
78
|
+
if (t.kind !== r.EOF)
|
|
79
|
+
do
|
|
80
|
+
if (t.next)
|
|
81
|
+
t = t.next;
|
|
82
|
+
else {
|
|
83
|
+
const e = z(this, t.end);
|
|
84
|
+
t.next = e, e.prev = t, t = e;
|
|
85
|
+
}
|
|
86
|
+
while (t.kind === r.COMMENT);
|
|
87
|
+
return t;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function Q(n) {
|
|
91
|
+
return n === r.BANG || n === r.DOLLAR || n === r.AMP || n === r.PAREN_L || n === r.PAREN_R || n === r.DOT || n === r.SPREAD || n === r.COLON || n === r.EQUALS || n === r.AT || n === r.BRACKET_L || n === r.BRACKET_R || n === r.BRACE_L || n === r.PIPE || n === r.BRACE_R;
|
|
92
|
+
}
|
|
93
|
+
function E(n) {
|
|
94
|
+
return n >= 0 && n <= 55295 || n >= 57344 && n <= 1114111;
|
|
95
|
+
}
|
|
96
|
+
function _(n, t) {
|
|
97
|
+
return S(n.charCodeAt(t)) && w(n.charCodeAt(t + 1));
|
|
98
|
+
}
|
|
99
|
+
function S(n) {
|
|
100
|
+
return n >= 55296 && n <= 56319;
|
|
101
|
+
}
|
|
102
|
+
function w(n) {
|
|
103
|
+
return n >= 56320 && n <= 57343;
|
|
104
|
+
}
|
|
105
|
+
function x(n, t) {
|
|
106
|
+
const e = n.source.body.codePointAt(t);
|
|
107
|
+
if (e === void 0)
|
|
108
|
+
return r.EOF;
|
|
109
|
+
if (e >= 32 && e <= 126) {
|
|
110
|
+
const i = String.fromCodePoint(e);
|
|
111
|
+
return i === '"' ? `'"'` : `"${i}"`;
|
|
112
|
+
}
|
|
113
|
+
return "U+" + e.toString(16).toUpperCase().padStart(4, "0");
|
|
114
|
+
}
|
|
115
|
+
function h(n, t, e, i, s) {
|
|
116
|
+
const o = n.line, c = 1 + e - n.lineStart;
|
|
117
|
+
return new L(t, e, i, o, c, s);
|
|
118
|
+
}
|
|
119
|
+
function z(n, t) {
|
|
120
|
+
const e = n.source.body, i = e.length;
|
|
121
|
+
let s = t;
|
|
122
|
+
for (; s < i; ) {
|
|
123
|
+
const o = e.charCodeAt(s);
|
|
124
|
+
switch (o) {
|
|
125
|
+
// Ignored ::
|
|
126
|
+
// - UnicodeBOM
|
|
127
|
+
// - WhiteSpace
|
|
128
|
+
// - LineTerminator
|
|
129
|
+
// - Comment
|
|
130
|
+
// - Comma
|
|
131
|
+
//
|
|
132
|
+
// UnicodeBOM :: "Byte Order Mark (U+FEFF)"
|
|
133
|
+
//
|
|
134
|
+
// WhiteSpace ::
|
|
135
|
+
// - "Horizontal Tab (U+0009)"
|
|
136
|
+
// - "Space (U+0020)"
|
|
137
|
+
//
|
|
138
|
+
// Comma :: ,
|
|
139
|
+
case 65279:
|
|
140
|
+
// <BOM>
|
|
141
|
+
case 9:
|
|
142
|
+
// \t
|
|
143
|
+
case 32:
|
|
144
|
+
// <space>
|
|
145
|
+
case 44:
|
|
146
|
+
++s;
|
|
147
|
+
continue;
|
|
148
|
+
// LineTerminator ::
|
|
149
|
+
// - "New Line (U+000A)"
|
|
150
|
+
// - "Carriage Return (U+000D)" [lookahead != "New Line (U+000A)"]
|
|
151
|
+
// - "Carriage Return (U+000D)" "New Line (U+000A)"
|
|
152
|
+
case 10:
|
|
153
|
+
++s, ++n.line, n.lineStart = s;
|
|
154
|
+
continue;
|
|
155
|
+
case 13:
|
|
156
|
+
e.charCodeAt(s + 1) === 10 ? s += 2 : ++s, ++n.line, n.lineStart = s;
|
|
157
|
+
continue;
|
|
158
|
+
// Comment
|
|
159
|
+
case 35:
|
|
160
|
+
return X(n, s);
|
|
161
|
+
// Token ::
|
|
162
|
+
// - Punctuator
|
|
163
|
+
// - Name
|
|
164
|
+
// - IntValue
|
|
165
|
+
// - FloatValue
|
|
166
|
+
// - StringValue
|
|
167
|
+
//
|
|
168
|
+
// Punctuator :: one of ! $ & ( ) ... : = @ [ ] { | }
|
|
169
|
+
case 33:
|
|
170
|
+
return h(n, r.BANG, s, s + 1);
|
|
171
|
+
case 36:
|
|
172
|
+
return h(n, r.DOLLAR, s, s + 1);
|
|
173
|
+
case 38:
|
|
174
|
+
return h(n, r.AMP, s, s + 1);
|
|
175
|
+
case 40:
|
|
176
|
+
return h(n, r.PAREN_L, s, s + 1);
|
|
177
|
+
case 41:
|
|
178
|
+
return h(n, r.PAREN_R, s, s + 1);
|
|
179
|
+
case 46:
|
|
180
|
+
if (e.charCodeAt(s + 1) === 46 && e.charCodeAt(s + 2) === 46)
|
|
181
|
+
return h(n, r.SPREAD, s, s + 3);
|
|
182
|
+
break;
|
|
183
|
+
case 58:
|
|
184
|
+
return h(n, r.COLON, s, s + 1);
|
|
185
|
+
case 61:
|
|
186
|
+
return h(n, r.EQUALS, s, s + 1);
|
|
187
|
+
case 64:
|
|
188
|
+
return h(n, r.AT, s, s + 1);
|
|
189
|
+
case 91:
|
|
190
|
+
return h(n, r.BRACKET_L, s, s + 1);
|
|
191
|
+
case 93:
|
|
192
|
+
return h(n, r.BRACKET_R, s, s + 1);
|
|
193
|
+
case 123:
|
|
194
|
+
return h(n, r.BRACE_L, s, s + 1);
|
|
195
|
+
case 124:
|
|
196
|
+
return h(n, r.PIPE, s, s + 1);
|
|
197
|
+
case 125:
|
|
198
|
+
return h(n, r.BRACE_R, s, s + 1);
|
|
199
|
+
// StringValue
|
|
200
|
+
case 34:
|
|
201
|
+
return e.charCodeAt(s + 1) === 34 && e.charCodeAt(s + 2) === 34 ? te(n, s) : H(n, s);
|
|
202
|
+
}
|
|
203
|
+
if (k(o) || o === 45)
|
|
204
|
+
return J(n, s, o);
|
|
205
|
+
if (g(o))
|
|
206
|
+
return se(n, s);
|
|
207
|
+
throw u(
|
|
208
|
+
n.source,
|
|
209
|
+
s,
|
|
210
|
+
o === 39 ? `Unexpected single quote character ('), did you mean to use a double quote (")?` : E(o) || _(e, s) ? `Unexpected character: ${x(n, s)}.` : `Invalid character: ${x(n, s)}.`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
return h(n, r.EOF, i, i);
|
|
214
|
+
}
|
|
215
|
+
function X(n, t) {
|
|
216
|
+
const e = n.source.body, i = e.length;
|
|
217
|
+
let s = t + 1;
|
|
218
|
+
for (; s < i; ) {
|
|
219
|
+
const o = e.charCodeAt(s);
|
|
220
|
+
if (o === 10 || o === 13)
|
|
221
|
+
break;
|
|
222
|
+
if (E(o))
|
|
223
|
+
++s;
|
|
224
|
+
else if (_(e, s))
|
|
225
|
+
s += 2;
|
|
226
|
+
else
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
return h(
|
|
230
|
+
n,
|
|
231
|
+
r.COMMENT,
|
|
232
|
+
t,
|
|
233
|
+
s,
|
|
234
|
+
e.slice(t + 1, s)
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
function J(n, t, e) {
|
|
238
|
+
const i = n.source.body;
|
|
239
|
+
let s = t, o = e, c = !1;
|
|
240
|
+
if (o === 45 && (o = i.charCodeAt(++s)), o === 48) {
|
|
241
|
+
if (o = i.charCodeAt(++s), k(o))
|
|
242
|
+
throw u(
|
|
243
|
+
n.source,
|
|
244
|
+
s,
|
|
245
|
+
`Invalid number, unexpected digit after 0: ${x(
|
|
246
|
+
n,
|
|
247
|
+
s
|
|
248
|
+
)}.`
|
|
249
|
+
);
|
|
250
|
+
} else
|
|
251
|
+
s = D(n, s, o), o = i.charCodeAt(s);
|
|
252
|
+
if (o === 46 && (c = !0, o = i.charCodeAt(++s), s = D(n, s, o), o = i.charCodeAt(s)), (o === 69 || o === 101) && (c = !0, o = i.charCodeAt(++s), (o === 43 || o === 45) && (o = i.charCodeAt(++s)), s = D(n, s, o), o = i.charCodeAt(s)), o === 46 || g(o))
|
|
253
|
+
throw u(
|
|
254
|
+
n.source,
|
|
255
|
+
s,
|
|
256
|
+
`Invalid number, expected digit but got: ${x(
|
|
257
|
+
n,
|
|
258
|
+
s
|
|
259
|
+
)}.`
|
|
260
|
+
);
|
|
261
|
+
return h(
|
|
262
|
+
n,
|
|
263
|
+
c ? r.FLOAT : r.INT,
|
|
264
|
+
t,
|
|
265
|
+
s,
|
|
266
|
+
i.slice(t, s)
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
function D(n, t, e) {
|
|
270
|
+
if (!k(e))
|
|
271
|
+
throw u(
|
|
272
|
+
n.source,
|
|
273
|
+
t,
|
|
274
|
+
`Invalid number, expected digit but got: ${x(
|
|
275
|
+
n,
|
|
276
|
+
t
|
|
277
|
+
)}.`
|
|
278
|
+
);
|
|
279
|
+
const i = n.source.body;
|
|
280
|
+
let s = t + 1;
|
|
281
|
+
for (; k(i.charCodeAt(s)); )
|
|
282
|
+
++s;
|
|
283
|
+
return s;
|
|
284
|
+
}
|
|
285
|
+
function H(n, t) {
|
|
286
|
+
const e = n.source.body, i = e.length;
|
|
287
|
+
let s = t + 1, o = s, c = "";
|
|
288
|
+
for (; s < i; ) {
|
|
289
|
+
const p = e.charCodeAt(s);
|
|
290
|
+
if (p === 34)
|
|
291
|
+
return c += e.slice(o, s), h(n, r.STRING, t, s + 1, c);
|
|
292
|
+
if (p === 92) {
|
|
293
|
+
c += e.slice(o, s);
|
|
294
|
+
const d = e.charCodeAt(s + 1) === 117 ? e.charCodeAt(s + 2) === 123 ? W(n, s) : Z(n, s) : ee(n, s);
|
|
295
|
+
c += d.value, s += d.size, o = s;
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (p === 10 || p === 13)
|
|
299
|
+
break;
|
|
300
|
+
if (E(p))
|
|
301
|
+
++s;
|
|
302
|
+
else if (_(e, s))
|
|
303
|
+
s += 2;
|
|
304
|
+
else
|
|
305
|
+
throw u(
|
|
306
|
+
n.source,
|
|
307
|
+
s,
|
|
308
|
+
`Invalid character within String: ${x(
|
|
309
|
+
n,
|
|
310
|
+
s
|
|
311
|
+
)}.`
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
throw u(n.source, s, "Unterminated string.");
|
|
315
|
+
}
|
|
316
|
+
function W(n, t) {
|
|
317
|
+
const e = n.source.body;
|
|
318
|
+
let i = 0, s = 3;
|
|
319
|
+
for (; s < 12; ) {
|
|
320
|
+
const o = e.charCodeAt(t + s++);
|
|
321
|
+
if (o === 125) {
|
|
322
|
+
if (s < 5 || !E(i))
|
|
323
|
+
break;
|
|
324
|
+
return {
|
|
325
|
+
value: String.fromCodePoint(i),
|
|
326
|
+
size: s
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
if (i = i << 4 | m(o), i < 0)
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
throw u(
|
|
333
|
+
n.source,
|
|
334
|
+
t,
|
|
335
|
+
`Invalid Unicode escape sequence: "${e.slice(
|
|
336
|
+
t,
|
|
337
|
+
t + s
|
|
338
|
+
)}".`
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
function Z(n, t) {
|
|
342
|
+
const e = n.source.body, i = C(e, t + 2);
|
|
343
|
+
if (E(i))
|
|
344
|
+
return {
|
|
345
|
+
value: String.fromCodePoint(i),
|
|
346
|
+
size: 6
|
|
347
|
+
};
|
|
348
|
+
if (S(i) && e.charCodeAt(t + 6) === 92 && e.charCodeAt(t + 7) === 117) {
|
|
349
|
+
const s = C(e, t + 8);
|
|
350
|
+
if (w(s))
|
|
351
|
+
return {
|
|
352
|
+
value: String.fromCodePoint(i, s),
|
|
353
|
+
size: 12
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
throw u(
|
|
357
|
+
n.source,
|
|
358
|
+
t,
|
|
359
|
+
`Invalid Unicode escape sequence: "${e.slice(t, t + 6)}".`
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
function C(n, t) {
|
|
363
|
+
return m(n.charCodeAt(t)) << 12 | m(n.charCodeAt(t + 1)) << 8 | m(n.charCodeAt(t + 2)) << 4 | m(n.charCodeAt(t + 3));
|
|
364
|
+
}
|
|
365
|
+
function m(n) {
|
|
366
|
+
return n >= 48 && n <= 57 ? n - 48 : n >= 65 && n <= 70 ? n - 55 : n >= 97 && n <= 102 ? n - 87 : -1;
|
|
367
|
+
}
|
|
368
|
+
function ee(n, t) {
|
|
369
|
+
const e = n.source.body;
|
|
370
|
+
switch (e.charCodeAt(t + 1)) {
|
|
371
|
+
case 34:
|
|
372
|
+
return {
|
|
373
|
+
value: '"',
|
|
374
|
+
size: 2
|
|
375
|
+
};
|
|
376
|
+
case 92:
|
|
377
|
+
return {
|
|
378
|
+
value: "\\",
|
|
379
|
+
size: 2
|
|
380
|
+
};
|
|
381
|
+
case 47:
|
|
382
|
+
return {
|
|
383
|
+
value: "/",
|
|
384
|
+
size: 2
|
|
385
|
+
};
|
|
386
|
+
case 98:
|
|
387
|
+
return {
|
|
388
|
+
value: "\b",
|
|
389
|
+
size: 2
|
|
390
|
+
};
|
|
391
|
+
case 102:
|
|
392
|
+
return {
|
|
393
|
+
value: "\f",
|
|
394
|
+
size: 2
|
|
395
|
+
};
|
|
396
|
+
case 110:
|
|
397
|
+
return {
|
|
398
|
+
value: `
|
|
399
|
+
`,
|
|
400
|
+
size: 2
|
|
401
|
+
};
|
|
402
|
+
case 114:
|
|
403
|
+
return {
|
|
404
|
+
value: "\r",
|
|
405
|
+
size: 2
|
|
406
|
+
};
|
|
407
|
+
case 116:
|
|
408
|
+
return {
|
|
409
|
+
value: " ",
|
|
410
|
+
size: 2
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
throw u(
|
|
414
|
+
n.source,
|
|
415
|
+
t,
|
|
416
|
+
`Invalid character escape sequence: "${e.slice(
|
|
417
|
+
t,
|
|
418
|
+
t + 2
|
|
419
|
+
)}".`
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
function te(n, t) {
|
|
423
|
+
const e = n.source.body, i = e.length;
|
|
424
|
+
let s = n.lineStart, o = t + 3, c = o, p = "";
|
|
425
|
+
const d = [];
|
|
426
|
+
for (; o < i; ) {
|
|
427
|
+
const f = e.charCodeAt(o);
|
|
428
|
+
if (f === 34 && e.charCodeAt(o + 1) === 34 && e.charCodeAt(o + 2) === 34) {
|
|
429
|
+
p += e.slice(c, o), d.push(p);
|
|
430
|
+
const l = h(
|
|
431
|
+
n,
|
|
432
|
+
r.BLOCK_STRING,
|
|
433
|
+
t,
|
|
434
|
+
o + 3,
|
|
435
|
+
// Return a string of the lines joined with U+000A.
|
|
436
|
+
B(d).join(`
|
|
437
|
+
`)
|
|
438
|
+
);
|
|
439
|
+
return n.line += d.length - 1, n.lineStart = s, l;
|
|
440
|
+
}
|
|
441
|
+
if (f === 92 && e.charCodeAt(o + 1) === 34 && e.charCodeAt(o + 2) === 34 && e.charCodeAt(o + 3) === 34) {
|
|
442
|
+
p += e.slice(c, o), c = o + 1, o += 4;
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
if (f === 10 || f === 13) {
|
|
446
|
+
p += e.slice(c, o), d.push(p), f === 13 && e.charCodeAt(o + 1) === 10 ? o += 2 : ++o, p = "", c = o, s = o;
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
if (E(f))
|
|
450
|
+
++o;
|
|
451
|
+
else if (_(e, o))
|
|
452
|
+
o += 2;
|
|
453
|
+
else
|
|
454
|
+
throw u(
|
|
455
|
+
n.source,
|
|
456
|
+
o,
|
|
457
|
+
`Invalid character within String: ${x(
|
|
458
|
+
n,
|
|
459
|
+
o
|
|
460
|
+
)}.`
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
throw u(n.source, o, "Unterminated string.");
|
|
464
|
+
}
|
|
465
|
+
function se(n, t) {
|
|
466
|
+
const e = n.source.body, i = e.length;
|
|
467
|
+
let s = t + 1;
|
|
468
|
+
for (; s < i; ) {
|
|
469
|
+
const o = e.charCodeAt(s);
|
|
470
|
+
if (M(o))
|
|
471
|
+
++s;
|
|
472
|
+
else
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
return h(
|
|
476
|
+
n,
|
|
477
|
+
r.NAME,
|
|
478
|
+
t,
|
|
479
|
+
s,
|
|
480
|
+
e.slice(t, s)
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
class y {
|
|
484
|
+
/** The GraphQL source text. */
|
|
485
|
+
/** Name used in diagnostics for this source, such as a file path or request name. */
|
|
486
|
+
/** One-indexed line and column where this source begins. */
|
|
487
|
+
/**
|
|
488
|
+
* Creates a Source instance.
|
|
489
|
+
* @param body - The GraphQL source text.
|
|
490
|
+
* @param name - Name used in diagnostics for this source.
|
|
491
|
+
* @param locationOffset - One-indexed line and column where this source begins.
|
|
492
|
+
* @example
|
|
493
|
+
* ```ts
|
|
494
|
+
* import { Source } from 'graphql/language';
|
|
495
|
+
*
|
|
496
|
+
* const source = new Source(
|
|
497
|
+
* 'type Query { greeting: String }',
|
|
498
|
+
* 'schema.graphql',
|
|
499
|
+
* { line: 10, column: 1 },
|
|
500
|
+
* );
|
|
501
|
+
*
|
|
502
|
+
* source.body; // => 'type Query { greeting: String }'
|
|
503
|
+
* source.name; // => 'schema.graphql'
|
|
504
|
+
* source.locationOffset; // => { line: 10, column: 1 }
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
507
|
+
constructor(t, e = "GraphQL request", i = {
|
|
508
|
+
line: 1,
|
|
509
|
+
column: 1
|
|
510
|
+
}) {
|
|
511
|
+
typeof t == "string" || A(!1, `Body must be a string. Received: ${U(t)}.`), this.body = t, this.name = e, this.locationOffset = i, this.locationOffset.line > 0 || A(
|
|
512
|
+
!1,
|
|
513
|
+
"line in locationOffset is 1-indexed and must be positive."
|
|
514
|
+
), this.locationOffset.column > 0 || A(
|
|
515
|
+
!1,
|
|
516
|
+
"column in locationOffset is 1-indexed and must be positive."
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
521
|
+
* @returns The built-in string tag for this object.
|
|
522
|
+
*/
|
|
523
|
+
get [Symbol.toStringTag]() {
|
|
524
|
+
return "Source";
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
function ne(n) {
|
|
528
|
+
return V(n, y);
|
|
529
|
+
}
|
|
530
|
+
function ie(n, t) {
|
|
531
|
+
const e = new re(n, t), i = e.parseDocument();
|
|
532
|
+
return Object.defineProperty(i, "tokenCount", {
|
|
533
|
+
enumerable: !1,
|
|
534
|
+
value: e.tokenCount
|
|
535
|
+
}), i;
|
|
536
|
+
}
|
|
537
|
+
class re {
|
|
538
|
+
constructor(t, e = {}) {
|
|
539
|
+
const { lexer: i, ...s } = e;
|
|
540
|
+
if (i)
|
|
541
|
+
this._lexer = i;
|
|
542
|
+
else {
|
|
543
|
+
const o = ne(t) ? t : new y(t);
|
|
544
|
+
this._lexer = new q(o);
|
|
545
|
+
}
|
|
546
|
+
this._options = s, this._tokenCounter = 0;
|
|
547
|
+
}
|
|
548
|
+
get tokenCount() {
|
|
549
|
+
return this._tokenCounter;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Converts a name lex token into a name parse node.
|
|
553
|
+
*
|
|
554
|
+
* @internal
|
|
555
|
+
*/
|
|
556
|
+
parseName() {
|
|
557
|
+
const t = this.expectToken(r.NAME);
|
|
558
|
+
return this.node(t, {
|
|
559
|
+
kind: a.NAME,
|
|
560
|
+
value: t.value
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
// Implements the parsing rules in the Document section.
|
|
564
|
+
/**
|
|
565
|
+
* Document : Definition+
|
|
566
|
+
*
|
|
567
|
+
* @internal
|
|
568
|
+
*/
|
|
569
|
+
parseDocument() {
|
|
570
|
+
return this.node(this._lexer.token, {
|
|
571
|
+
kind: a.DOCUMENT,
|
|
572
|
+
definitions: this.many(
|
|
573
|
+
r.SOF,
|
|
574
|
+
this.parseDefinition,
|
|
575
|
+
r.EOF
|
|
576
|
+
)
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Definition :
|
|
581
|
+
* - ExecutableDefinition
|
|
582
|
+
* - TypeSystemDefinition
|
|
583
|
+
* - TypeSystemExtension
|
|
584
|
+
*
|
|
585
|
+
* ExecutableDefinition :
|
|
586
|
+
* - OperationDefinition
|
|
587
|
+
* - FragmentDefinition
|
|
588
|
+
*
|
|
589
|
+
* TypeSystemDefinition :
|
|
590
|
+
* - SchemaDefinition
|
|
591
|
+
* - TypeDefinition
|
|
592
|
+
* - DirectiveDefinition
|
|
593
|
+
*
|
|
594
|
+
* TypeDefinition :
|
|
595
|
+
* - ScalarTypeDefinition
|
|
596
|
+
* - ObjectTypeDefinition
|
|
597
|
+
* - InterfaceTypeDefinition
|
|
598
|
+
* - UnionTypeDefinition
|
|
599
|
+
* - EnumTypeDefinition
|
|
600
|
+
* - InputObjectTypeDefinition
|
|
601
|
+
*
|
|
602
|
+
* @internal
|
|
603
|
+
*/
|
|
604
|
+
parseDefinition() {
|
|
605
|
+
if (this.peek(r.BRACE_L))
|
|
606
|
+
return this.parseOperationDefinition();
|
|
607
|
+
const t = this.peekDescription(), e = t ? this._lexer.lookahead() : this._lexer.token;
|
|
608
|
+
if (t && e.kind === r.BRACE_L)
|
|
609
|
+
throw u(
|
|
610
|
+
this._lexer.source,
|
|
611
|
+
this._lexer.token.start,
|
|
612
|
+
"Unexpected description, descriptions are not supported on shorthand queries."
|
|
613
|
+
);
|
|
614
|
+
if (e.kind === r.NAME) {
|
|
615
|
+
switch (e.value) {
|
|
616
|
+
case "schema":
|
|
617
|
+
return this.parseSchemaDefinition();
|
|
618
|
+
case "scalar":
|
|
619
|
+
return this.parseScalarTypeDefinition();
|
|
620
|
+
case "type":
|
|
621
|
+
return this.parseObjectTypeDefinition();
|
|
622
|
+
case "interface":
|
|
623
|
+
return this.parseInterfaceTypeDefinition();
|
|
624
|
+
case "union":
|
|
625
|
+
return this.parseUnionTypeDefinition();
|
|
626
|
+
case "enum":
|
|
627
|
+
return this.parseEnumTypeDefinition();
|
|
628
|
+
case "input":
|
|
629
|
+
return this.parseInputObjectTypeDefinition();
|
|
630
|
+
case "directive":
|
|
631
|
+
return this.parseDirectiveDefinition();
|
|
632
|
+
}
|
|
633
|
+
switch (e.value) {
|
|
634
|
+
case "query":
|
|
635
|
+
case "mutation":
|
|
636
|
+
case "subscription":
|
|
637
|
+
return this.parseOperationDefinition();
|
|
638
|
+
case "fragment":
|
|
639
|
+
return this.parseFragmentDefinition();
|
|
640
|
+
}
|
|
641
|
+
if (t)
|
|
642
|
+
throw u(
|
|
643
|
+
this._lexer.source,
|
|
644
|
+
this._lexer.token.start,
|
|
645
|
+
"Unexpected description, only GraphQL definitions support descriptions."
|
|
646
|
+
);
|
|
647
|
+
if (e.value === "extend")
|
|
648
|
+
return this.parseTypeSystemExtension();
|
|
649
|
+
}
|
|
650
|
+
throw this.unexpected(e);
|
|
651
|
+
}
|
|
652
|
+
// Implements the parsing rules in the Operations section.
|
|
653
|
+
/**
|
|
654
|
+
* OperationDefinition :
|
|
655
|
+
* - SelectionSet
|
|
656
|
+
* - OperationType Name? VariableDefinitions? Directives? SelectionSet
|
|
657
|
+
*
|
|
658
|
+
* @internal
|
|
659
|
+
*/
|
|
660
|
+
parseOperationDefinition() {
|
|
661
|
+
const t = this._lexer.token;
|
|
662
|
+
if (this.peek(r.BRACE_L))
|
|
663
|
+
return this.node(t, {
|
|
664
|
+
kind: a.OPERATION_DEFINITION,
|
|
665
|
+
operation: T.QUERY,
|
|
666
|
+
description: void 0,
|
|
667
|
+
name: void 0,
|
|
668
|
+
variableDefinitions: [],
|
|
669
|
+
directives: [],
|
|
670
|
+
selectionSet: this.parseSelectionSet()
|
|
671
|
+
});
|
|
672
|
+
const e = this.parseDescription(), i = this.parseOperationType();
|
|
673
|
+
let s;
|
|
674
|
+
return this.peek(r.NAME) && (s = this.parseName()), this.node(t, {
|
|
675
|
+
kind: a.OPERATION_DEFINITION,
|
|
676
|
+
operation: i,
|
|
677
|
+
description: e,
|
|
678
|
+
name: s,
|
|
679
|
+
variableDefinitions: this.parseVariableDefinitions(),
|
|
680
|
+
directives: this.parseDirectives(!1),
|
|
681
|
+
selectionSet: this.parseSelectionSet()
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* OperationType : one of query mutation subscription
|
|
686
|
+
*
|
|
687
|
+
* @internal
|
|
688
|
+
*/
|
|
689
|
+
parseOperationType() {
|
|
690
|
+
const t = this.expectToken(r.NAME);
|
|
691
|
+
switch (t.value) {
|
|
692
|
+
case "query":
|
|
693
|
+
return T.QUERY;
|
|
694
|
+
case "mutation":
|
|
695
|
+
return T.MUTATION;
|
|
696
|
+
case "subscription":
|
|
697
|
+
return T.SUBSCRIPTION;
|
|
698
|
+
}
|
|
699
|
+
throw this.unexpected(t);
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* VariableDefinitions : ( VariableDefinition+ )
|
|
703
|
+
*
|
|
704
|
+
* @internal
|
|
705
|
+
*/
|
|
706
|
+
parseVariableDefinitions() {
|
|
707
|
+
return this.optionalMany(
|
|
708
|
+
r.PAREN_L,
|
|
709
|
+
this.parseVariableDefinition,
|
|
710
|
+
r.PAREN_R
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* VariableDefinition : Variable : Type DefaultValue? Directives[Const]?
|
|
715
|
+
*
|
|
716
|
+
* @internal
|
|
717
|
+
*/
|
|
718
|
+
parseVariableDefinition() {
|
|
719
|
+
return this.node(this._lexer.token, {
|
|
720
|
+
kind: a.VARIABLE_DEFINITION,
|
|
721
|
+
description: this.parseDescription(),
|
|
722
|
+
variable: this.parseVariable(),
|
|
723
|
+
type: (this.expectToken(r.COLON), this.parseTypeReference()),
|
|
724
|
+
defaultValue: this.expectOptionalToken(r.EQUALS) ? this.parseConstValueLiteral() : void 0,
|
|
725
|
+
directives: this.parseConstDirectives()
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Variable : $ Name
|
|
730
|
+
*
|
|
731
|
+
* @internal
|
|
732
|
+
*/
|
|
733
|
+
parseVariable() {
|
|
734
|
+
const t = this._lexer.token;
|
|
735
|
+
return this.expectToken(r.DOLLAR), this.node(t, {
|
|
736
|
+
kind: a.VARIABLE,
|
|
737
|
+
name: this.parseName()
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* ```
|
|
742
|
+
* SelectionSet : { Selection+ }
|
|
743
|
+
* ```
|
|
744
|
+
*
|
|
745
|
+
* @internal
|
|
746
|
+
*/
|
|
747
|
+
parseSelectionSet() {
|
|
748
|
+
return this.node(this._lexer.token, {
|
|
749
|
+
kind: a.SELECTION_SET,
|
|
750
|
+
selections: this.many(
|
|
751
|
+
r.BRACE_L,
|
|
752
|
+
this.parseSelection,
|
|
753
|
+
r.BRACE_R
|
|
754
|
+
)
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Selection :
|
|
759
|
+
* - Field
|
|
760
|
+
* - FragmentSpread
|
|
761
|
+
* - InlineFragment
|
|
762
|
+
*
|
|
763
|
+
* @internal
|
|
764
|
+
*/
|
|
765
|
+
parseSelection() {
|
|
766
|
+
return this.peek(r.SPREAD) ? this.parseFragment() : this.parseField();
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Field : Alias? Name Arguments? Directives? SelectionSet?
|
|
770
|
+
*
|
|
771
|
+
* Alias : Name :
|
|
772
|
+
*
|
|
773
|
+
* @internal
|
|
774
|
+
*/
|
|
775
|
+
parseField() {
|
|
776
|
+
const t = this._lexer.token, e = this.parseName();
|
|
777
|
+
let i, s;
|
|
778
|
+
return this.expectOptionalToken(r.COLON) ? (i = e, s = this.parseName()) : s = e, this.node(t, {
|
|
779
|
+
kind: a.FIELD,
|
|
780
|
+
alias: i,
|
|
781
|
+
name: s,
|
|
782
|
+
arguments: this.parseArguments(!1),
|
|
783
|
+
directives: this.parseDirectives(!1),
|
|
784
|
+
selectionSet: this.peek(r.BRACE_L) ? this.parseSelectionSet() : void 0
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Arguments[Const] : ( Argument[?Const]+ )
|
|
789
|
+
*
|
|
790
|
+
* @internal
|
|
791
|
+
*/
|
|
792
|
+
parseArguments(t) {
|
|
793
|
+
const e = t ? this.parseConstArgument : this.parseArgument;
|
|
794
|
+
return this.optionalMany(r.PAREN_L, e, r.PAREN_R);
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Argument[Const] : Name : Value[?Const]
|
|
798
|
+
*
|
|
799
|
+
* @internal
|
|
800
|
+
*/
|
|
801
|
+
parseArgument(t = !1) {
|
|
802
|
+
const e = this._lexer.token, i = this.parseName();
|
|
803
|
+
return this.expectToken(r.COLON), this.node(e, {
|
|
804
|
+
kind: a.ARGUMENT,
|
|
805
|
+
name: i,
|
|
806
|
+
value: this.parseValueLiteral(t)
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
parseConstArgument() {
|
|
810
|
+
return this.parseArgument(!0);
|
|
811
|
+
}
|
|
812
|
+
// Implements the parsing rules in the Fragments section.
|
|
813
|
+
/**
|
|
814
|
+
* Corresponds to both FragmentSpread and InlineFragment in the spec.
|
|
815
|
+
*
|
|
816
|
+
* FragmentSpread : ... FragmentName Directives?
|
|
817
|
+
*
|
|
818
|
+
* InlineFragment : ... TypeCondition? Directives? SelectionSet
|
|
819
|
+
*
|
|
820
|
+
* @internal
|
|
821
|
+
*/
|
|
822
|
+
parseFragment() {
|
|
823
|
+
const t = this._lexer.token;
|
|
824
|
+
this.expectToken(r.SPREAD);
|
|
825
|
+
const e = this.expectOptionalKeyword("on");
|
|
826
|
+
return !e && this.peek(r.NAME) ? this.node(t, {
|
|
827
|
+
kind: a.FRAGMENT_SPREAD,
|
|
828
|
+
name: this.parseFragmentName(),
|
|
829
|
+
directives: this.parseDirectives(!1)
|
|
830
|
+
}) : this.node(t, {
|
|
831
|
+
kind: a.INLINE_FRAGMENT,
|
|
832
|
+
typeCondition: e ? this.parseNamedType() : void 0,
|
|
833
|
+
directives: this.parseDirectives(!1),
|
|
834
|
+
selectionSet: this.parseSelectionSet()
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* FragmentDefinition :
|
|
839
|
+
* - fragment FragmentName on TypeCondition Directives? SelectionSet
|
|
840
|
+
*
|
|
841
|
+
* TypeCondition : NamedType
|
|
842
|
+
*
|
|
843
|
+
* @internal
|
|
844
|
+
*/
|
|
845
|
+
parseFragmentDefinition() {
|
|
846
|
+
const t = this._lexer.token, e = this.parseDescription();
|
|
847
|
+
return this.expectKeyword("fragment"), this._options.allowLegacyFragmentVariables === !0 ? this.node(t, {
|
|
848
|
+
kind: a.FRAGMENT_DEFINITION,
|
|
849
|
+
description: e,
|
|
850
|
+
name: this.parseFragmentName(),
|
|
851
|
+
variableDefinitions: this.parseVariableDefinitions(),
|
|
852
|
+
typeCondition: (this.expectKeyword("on"), this.parseNamedType()),
|
|
853
|
+
directives: this.parseDirectives(!1),
|
|
854
|
+
selectionSet: this.parseSelectionSet()
|
|
855
|
+
}) : this.node(t, {
|
|
856
|
+
kind: a.FRAGMENT_DEFINITION,
|
|
857
|
+
description: e,
|
|
858
|
+
name: this.parseFragmentName(),
|
|
859
|
+
typeCondition: (this.expectKeyword("on"), this.parseNamedType()),
|
|
860
|
+
directives: this.parseDirectives(!1),
|
|
861
|
+
selectionSet: this.parseSelectionSet()
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* FragmentName : Name but not `on`
|
|
866
|
+
*
|
|
867
|
+
* @internal
|
|
868
|
+
*/
|
|
869
|
+
parseFragmentName() {
|
|
870
|
+
if (this._lexer.token.value === "on")
|
|
871
|
+
throw this.unexpected();
|
|
872
|
+
return this.parseName();
|
|
873
|
+
}
|
|
874
|
+
// Implements the parsing rules in the Values section.
|
|
875
|
+
/**
|
|
876
|
+
* Value[Const] :
|
|
877
|
+
* - [~Const] Variable
|
|
878
|
+
* - IntValue
|
|
879
|
+
* - FloatValue
|
|
880
|
+
* - StringValue
|
|
881
|
+
* - BooleanValue
|
|
882
|
+
* - NullValue
|
|
883
|
+
* - EnumValue
|
|
884
|
+
* - ListValue[?Const]
|
|
885
|
+
* - ObjectValue[?Const]
|
|
886
|
+
*
|
|
887
|
+
* BooleanValue : one of `true` `false`
|
|
888
|
+
*
|
|
889
|
+
* NullValue : `null`
|
|
890
|
+
*
|
|
891
|
+
* EnumValue : Name but not `true`, `false` or `null`
|
|
892
|
+
*
|
|
893
|
+
* @internal
|
|
894
|
+
*/
|
|
895
|
+
parseValueLiteral(t) {
|
|
896
|
+
const e = this._lexer.token;
|
|
897
|
+
switch (e.kind) {
|
|
898
|
+
case r.BRACKET_L:
|
|
899
|
+
return this.parseList(t);
|
|
900
|
+
case r.BRACE_L:
|
|
901
|
+
return this.parseObject(t);
|
|
902
|
+
case r.INT:
|
|
903
|
+
return this.advanceLexer(), this.node(e, {
|
|
904
|
+
kind: a.INT,
|
|
905
|
+
value: e.value
|
|
906
|
+
});
|
|
907
|
+
case r.FLOAT:
|
|
908
|
+
return this.advanceLexer(), this.node(e, {
|
|
909
|
+
kind: a.FLOAT,
|
|
910
|
+
value: e.value
|
|
911
|
+
});
|
|
912
|
+
case r.STRING:
|
|
913
|
+
case r.BLOCK_STRING:
|
|
914
|
+
return this.parseStringLiteral();
|
|
915
|
+
case r.NAME:
|
|
916
|
+
switch (this.advanceLexer(), e.value) {
|
|
917
|
+
case "true":
|
|
918
|
+
return this.node(e, {
|
|
919
|
+
kind: a.BOOLEAN,
|
|
920
|
+
value: !0
|
|
921
|
+
});
|
|
922
|
+
case "false":
|
|
923
|
+
return this.node(e, {
|
|
924
|
+
kind: a.BOOLEAN,
|
|
925
|
+
value: !1
|
|
926
|
+
});
|
|
927
|
+
case "null":
|
|
928
|
+
return this.node(e, {
|
|
929
|
+
kind: a.NULL
|
|
930
|
+
});
|
|
931
|
+
default:
|
|
932
|
+
return this.node(e, {
|
|
933
|
+
kind: a.ENUM,
|
|
934
|
+
value: e.value
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
case r.DOLLAR:
|
|
938
|
+
if (t)
|
|
939
|
+
if (this.expectToken(r.DOLLAR), this._lexer.token.kind === r.NAME) {
|
|
940
|
+
const i = this._lexer.token.value;
|
|
941
|
+
throw u(
|
|
942
|
+
this._lexer.source,
|
|
943
|
+
e.start,
|
|
944
|
+
`Unexpected variable "$${i}" in constant value.`
|
|
945
|
+
);
|
|
946
|
+
} else
|
|
947
|
+
throw this.unexpected(e);
|
|
948
|
+
return this.parseVariable();
|
|
949
|
+
default:
|
|
950
|
+
throw this.unexpected();
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
parseConstValueLiteral() {
|
|
954
|
+
return this.parseValueLiteral(!0);
|
|
955
|
+
}
|
|
956
|
+
parseStringLiteral() {
|
|
957
|
+
const t = this._lexer.token;
|
|
958
|
+
return this.advanceLexer(), this.node(t, {
|
|
959
|
+
kind: a.STRING,
|
|
960
|
+
value: t.value,
|
|
961
|
+
block: t.kind === r.BLOCK_STRING
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* ListValue[Const] :
|
|
966
|
+
* - [ ]
|
|
967
|
+
* - [ Value[?Const]+ ]
|
|
968
|
+
*
|
|
969
|
+
* @internal
|
|
970
|
+
*/
|
|
971
|
+
parseList(t) {
|
|
972
|
+
const e = () => this.parseValueLiteral(t);
|
|
973
|
+
return this.node(this._lexer.token, {
|
|
974
|
+
kind: a.LIST,
|
|
975
|
+
values: this.any(r.BRACKET_L, e, r.BRACKET_R)
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* ```
|
|
980
|
+
* ObjectValue[Const] :
|
|
981
|
+
* - { }
|
|
982
|
+
* - { ObjectField[?Const]+ }
|
|
983
|
+
* ```
|
|
984
|
+
*
|
|
985
|
+
* @internal
|
|
986
|
+
*/
|
|
987
|
+
parseObject(t) {
|
|
988
|
+
const e = () => this.parseObjectField(t);
|
|
989
|
+
return this.node(this._lexer.token, {
|
|
990
|
+
kind: a.OBJECT,
|
|
991
|
+
fields: this.any(r.BRACE_L, e, r.BRACE_R)
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* ObjectField[Const] : Name : Value[?Const]
|
|
996
|
+
*
|
|
997
|
+
* @internal
|
|
998
|
+
*/
|
|
999
|
+
parseObjectField(t) {
|
|
1000
|
+
const e = this._lexer.token, i = this.parseName();
|
|
1001
|
+
return this.expectToken(r.COLON), this.node(e, {
|
|
1002
|
+
kind: a.OBJECT_FIELD,
|
|
1003
|
+
name: i,
|
|
1004
|
+
value: this.parseValueLiteral(t)
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
// Implements the parsing rules in the Directives section.
|
|
1008
|
+
/**
|
|
1009
|
+
* Directives[Const] : Directive[?Const]+
|
|
1010
|
+
*
|
|
1011
|
+
* @internal
|
|
1012
|
+
*/
|
|
1013
|
+
parseDirectives(t) {
|
|
1014
|
+
const e = [];
|
|
1015
|
+
for (; this.peek(r.AT); )
|
|
1016
|
+
e.push(this.parseDirective(t));
|
|
1017
|
+
return e;
|
|
1018
|
+
}
|
|
1019
|
+
parseConstDirectives() {
|
|
1020
|
+
return this.parseDirectives(!0);
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* ```
|
|
1024
|
+
* Directive[Const] : @ Name Arguments[?Const]?
|
|
1025
|
+
* ```
|
|
1026
|
+
*
|
|
1027
|
+
* @internal
|
|
1028
|
+
*/
|
|
1029
|
+
parseDirective(t) {
|
|
1030
|
+
const e = this._lexer.token;
|
|
1031
|
+
return this.expectToken(r.AT), this.node(e, {
|
|
1032
|
+
kind: a.DIRECTIVE,
|
|
1033
|
+
name: this.parseName(),
|
|
1034
|
+
arguments: this.parseArguments(t)
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
// Implements the parsing rules in the Types section.
|
|
1038
|
+
/**
|
|
1039
|
+
* Type :
|
|
1040
|
+
* - NamedType
|
|
1041
|
+
* - ListType
|
|
1042
|
+
* - NonNullType
|
|
1043
|
+
*
|
|
1044
|
+
* @internal
|
|
1045
|
+
*/
|
|
1046
|
+
parseTypeReference() {
|
|
1047
|
+
const t = this._lexer.token;
|
|
1048
|
+
let e;
|
|
1049
|
+
if (this.expectOptionalToken(r.BRACKET_L)) {
|
|
1050
|
+
const i = this.parseTypeReference();
|
|
1051
|
+
this.expectToken(r.BRACKET_R), e = this.node(t, {
|
|
1052
|
+
kind: a.LIST_TYPE,
|
|
1053
|
+
type: i
|
|
1054
|
+
});
|
|
1055
|
+
} else
|
|
1056
|
+
e = this.parseNamedType();
|
|
1057
|
+
return this.expectOptionalToken(r.BANG) ? this.node(t, {
|
|
1058
|
+
kind: a.NON_NULL_TYPE,
|
|
1059
|
+
type: e
|
|
1060
|
+
}) : e;
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* NamedType : Name
|
|
1064
|
+
*
|
|
1065
|
+
* @internal
|
|
1066
|
+
*/
|
|
1067
|
+
parseNamedType() {
|
|
1068
|
+
return this.node(this._lexer.token, {
|
|
1069
|
+
kind: a.NAMED_TYPE,
|
|
1070
|
+
name: this.parseName()
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
// Implements the parsing rules in the Type Definition section.
|
|
1074
|
+
peekDescription() {
|
|
1075
|
+
return this.peek(r.STRING) || this.peek(r.BLOCK_STRING);
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Description : StringValue
|
|
1079
|
+
*
|
|
1080
|
+
* @internal
|
|
1081
|
+
*/
|
|
1082
|
+
parseDescription() {
|
|
1083
|
+
if (this.peekDescription())
|
|
1084
|
+
return this.parseStringLiteral();
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* ```
|
|
1088
|
+
* SchemaDefinition : Description? schema Directives[Const]? { OperationTypeDefinition+ }
|
|
1089
|
+
* ```
|
|
1090
|
+
*
|
|
1091
|
+
* @internal
|
|
1092
|
+
*/
|
|
1093
|
+
parseSchemaDefinition() {
|
|
1094
|
+
const t = this._lexer.token, e = this.parseDescription();
|
|
1095
|
+
this.expectKeyword("schema");
|
|
1096
|
+
const i = this.parseConstDirectives(), s = this.many(
|
|
1097
|
+
r.BRACE_L,
|
|
1098
|
+
this.parseOperationTypeDefinition,
|
|
1099
|
+
r.BRACE_R
|
|
1100
|
+
);
|
|
1101
|
+
return this.node(t, {
|
|
1102
|
+
kind: a.SCHEMA_DEFINITION,
|
|
1103
|
+
description: e,
|
|
1104
|
+
directives: i,
|
|
1105
|
+
operationTypes: s
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* OperationTypeDefinition : OperationType : NamedType
|
|
1110
|
+
*
|
|
1111
|
+
* @internal
|
|
1112
|
+
*/
|
|
1113
|
+
parseOperationTypeDefinition() {
|
|
1114
|
+
const t = this._lexer.token, e = this.parseOperationType();
|
|
1115
|
+
this.expectToken(r.COLON);
|
|
1116
|
+
const i = this.parseNamedType();
|
|
1117
|
+
return this.node(t, {
|
|
1118
|
+
kind: a.OPERATION_TYPE_DEFINITION,
|
|
1119
|
+
operation: e,
|
|
1120
|
+
type: i
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* ScalarTypeDefinition : Description? scalar Name Directives[Const]?
|
|
1125
|
+
*
|
|
1126
|
+
* @internal
|
|
1127
|
+
*/
|
|
1128
|
+
parseScalarTypeDefinition() {
|
|
1129
|
+
const t = this._lexer.token, e = this.parseDescription();
|
|
1130
|
+
this.expectKeyword("scalar");
|
|
1131
|
+
const i = this.parseName(), s = this.parseConstDirectives();
|
|
1132
|
+
return this.node(t, {
|
|
1133
|
+
kind: a.SCALAR_TYPE_DEFINITION,
|
|
1134
|
+
description: e,
|
|
1135
|
+
name: i,
|
|
1136
|
+
directives: s
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* ObjectTypeDefinition :
|
|
1141
|
+
* Description?
|
|
1142
|
+
* type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition?
|
|
1143
|
+
*
|
|
1144
|
+
* @internal
|
|
1145
|
+
*/
|
|
1146
|
+
parseObjectTypeDefinition() {
|
|
1147
|
+
const t = this._lexer.token, e = this.parseDescription();
|
|
1148
|
+
this.expectKeyword("type");
|
|
1149
|
+
const i = this.parseName(), s = this.parseImplementsInterfaces(), o = this.parseConstDirectives(), c = this.parseFieldsDefinition();
|
|
1150
|
+
return this.node(t, {
|
|
1151
|
+
kind: a.OBJECT_TYPE_DEFINITION,
|
|
1152
|
+
description: e,
|
|
1153
|
+
name: i,
|
|
1154
|
+
interfaces: s,
|
|
1155
|
+
directives: o,
|
|
1156
|
+
fields: c
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* ImplementsInterfaces :
|
|
1161
|
+
* - implements `&`? NamedType
|
|
1162
|
+
* - ImplementsInterfaces & NamedType
|
|
1163
|
+
*
|
|
1164
|
+
* @internal
|
|
1165
|
+
*/
|
|
1166
|
+
parseImplementsInterfaces() {
|
|
1167
|
+
return this.expectOptionalKeyword("implements") ? this.delimitedMany(r.AMP, this.parseNamedType) : [];
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* ```
|
|
1171
|
+
* FieldsDefinition : { FieldDefinition+ }
|
|
1172
|
+
* ```
|
|
1173
|
+
*
|
|
1174
|
+
* @internal
|
|
1175
|
+
*/
|
|
1176
|
+
parseFieldsDefinition() {
|
|
1177
|
+
return this.optionalMany(
|
|
1178
|
+
r.BRACE_L,
|
|
1179
|
+
this.parseFieldDefinition,
|
|
1180
|
+
r.BRACE_R
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* FieldDefinition :
|
|
1185
|
+
* - Description? Name ArgumentsDefinition? : Type Directives[Const]?
|
|
1186
|
+
*
|
|
1187
|
+
* @internal
|
|
1188
|
+
*/
|
|
1189
|
+
parseFieldDefinition() {
|
|
1190
|
+
const t = this._lexer.token, e = this.parseDescription(), i = this.parseName(), s = this.parseArgumentDefs();
|
|
1191
|
+
this.expectToken(r.COLON);
|
|
1192
|
+
const o = this.parseTypeReference(), c = this.parseConstDirectives();
|
|
1193
|
+
return this.node(t, {
|
|
1194
|
+
kind: a.FIELD_DEFINITION,
|
|
1195
|
+
description: e,
|
|
1196
|
+
name: i,
|
|
1197
|
+
arguments: s,
|
|
1198
|
+
type: o,
|
|
1199
|
+
directives: c
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* ArgumentsDefinition : ( InputValueDefinition+ )
|
|
1204
|
+
*
|
|
1205
|
+
* @internal
|
|
1206
|
+
*/
|
|
1207
|
+
parseArgumentDefs() {
|
|
1208
|
+
return this.optionalMany(
|
|
1209
|
+
r.PAREN_L,
|
|
1210
|
+
this.parseInputValueDef,
|
|
1211
|
+
r.PAREN_R
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* InputValueDefinition :
|
|
1216
|
+
* - Description? Name : Type DefaultValue? Directives[Const]?
|
|
1217
|
+
*
|
|
1218
|
+
* @internal
|
|
1219
|
+
*/
|
|
1220
|
+
parseInputValueDef() {
|
|
1221
|
+
const t = this._lexer.token, e = this.parseDescription(), i = this.parseName();
|
|
1222
|
+
this.expectToken(r.COLON);
|
|
1223
|
+
const s = this.parseTypeReference();
|
|
1224
|
+
let o;
|
|
1225
|
+
this.expectOptionalToken(r.EQUALS) && (o = this.parseConstValueLiteral());
|
|
1226
|
+
const c = this.parseConstDirectives();
|
|
1227
|
+
return this.node(t, {
|
|
1228
|
+
kind: a.INPUT_VALUE_DEFINITION,
|
|
1229
|
+
description: e,
|
|
1230
|
+
name: i,
|
|
1231
|
+
type: s,
|
|
1232
|
+
defaultValue: o,
|
|
1233
|
+
directives: c
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* InterfaceTypeDefinition :
|
|
1238
|
+
* - Description? interface Name Directives[Const]? FieldsDefinition?
|
|
1239
|
+
*
|
|
1240
|
+
* @internal
|
|
1241
|
+
*/
|
|
1242
|
+
parseInterfaceTypeDefinition() {
|
|
1243
|
+
const t = this._lexer.token, e = this.parseDescription();
|
|
1244
|
+
this.expectKeyword("interface");
|
|
1245
|
+
const i = this.parseName(), s = this.parseImplementsInterfaces(), o = this.parseConstDirectives(), c = this.parseFieldsDefinition();
|
|
1246
|
+
return this.node(t, {
|
|
1247
|
+
kind: a.INTERFACE_TYPE_DEFINITION,
|
|
1248
|
+
description: e,
|
|
1249
|
+
name: i,
|
|
1250
|
+
interfaces: s,
|
|
1251
|
+
directives: o,
|
|
1252
|
+
fields: c
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* UnionTypeDefinition :
|
|
1257
|
+
* - Description? union Name Directives[Const]? UnionMemberTypes?
|
|
1258
|
+
*
|
|
1259
|
+
* @internal
|
|
1260
|
+
*/
|
|
1261
|
+
parseUnionTypeDefinition() {
|
|
1262
|
+
const t = this._lexer.token, e = this.parseDescription();
|
|
1263
|
+
this.expectKeyword("union");
|
|
1264
|
+
const i = this.parseName(), s = this.parseConstDirectives(), o = this.parseUnionMemberTypes();
|
|
1265
|
+
return this.node(t, {
|
|
1266
|
+
kind: a.UNION_TYPE_DEFINITION,
|
|
1267
|
+
description: e,
|
|
1268
|
+
name: i,
|
|
1269
|
+
directives: s,
|
|
1270
|
+
types: o
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* UnionMemberTypes :
|
|
1275
|
+
* - = `|`? NamedType
|
|
1276
|
+
* - UnionMemberTypes | NamedType
|
|
1277
|
+
*
|
|
1278
|
+
* @internal
|
|
1279
|
+
*/
|
|
1280
|
+
parseUnionMemberTypes() {
|
|
1281
|
+
return this.expectOptionalToken(r.EQUALS) ? this.delimitedMany(r.PIPE, this.parseNamedType) : [];
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* EnumTypeDefinition :
|
|
1285
|
+
* - Description? enum Name Directives[Const]? EnumValuesDefinition?
|
|
1286
|
+
*
|
|
1287
|
+
* @internal
|
|
1288
|
+
*/
|
|
1289
|
+
parseEnumTypeDefinition() {
|
|
1290
|
+
const t = this._lexer.token, e = this.parseDescription();
|
|
1291
|
+
this.expectKeyword("enum");
|
|
1292
|
+
const i = this.parseName(), s = this.parseConstDirectives(), o = this.parseEnumValuesDefinition();
|
|
1293
|
+
return this.node(t, {
|
|
1294
|
+
kind: a.ENUM_TYPE_DEFINITION,
|
|
1295
|
+
description: e,
|
|
1296
|
+
name: i,
|
|
1297
|
+
directives: s,
|
|
1298
|
+
values: o
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
/**
|
|
1302
|
+
* ```
|
|
1303
|
+
* EnumValuesDefinition : { EnumValueDefinition+ }
|
|
1304
|
+
* ```
|
|
1305
|
+
*
|
|
1306
|
+
* @internal
|
|
1307
|
+
*/
|
|
1308
|
+
parseEnumValuesDefinition() {
|
|
1309
|
+
return this.optionalMany(
|
|
1310
|
+
r.BRACE_L,
|
|
1311
|
+
this.parseEnumValueDefinition,
|
|
1312
|
+
r.BRACE_R
|
|
1313
|
+
);
|
|
1314
|
+
}
|
|
1315
|
+
/**
|
|
1316
|
+
* EnumValueDefinition : Description? EnumValue Directives[Const]?
|
|
1317
|
+
*
|
|
1318
|
+
* @internal
|
|
1319
|
+
*/
|
|
1320
|
+
parseEnumValueDefinition() {
|
|
1321
|
+
const t = this._lexer.token, e = this.parseDescription(), i = this.parseEnumValueName(), s = this.parseConstDirectives();
|
|
1322
|
+
return this.node(t, {
|
|
1323
|
+
kind: a.ENUM_VALUE_DEFINITION,
|
|
1324
|
+
description: e,
|
|
1325
|
+
name: i,
|
|
1326
|
+
directives: s
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* EnumValue : Name but not `true`, `false` or `null`
|
|
1331
|
+
*
|
|
1332
|
+
* @internal
|
|
1333
|
+
*/
|
|
1334
|
+
parseEnumValueName() {
|
|
1335
|
+
if (this._lexer.token.value === "true" || this._lexer.token.value === "false" || this._lexer.token.value === "null")
|
|
1336
|
+
throw u(
|
|
1337
|
+
this._lexer.source,
|
|
1338
|
+
this._lexer.token.start,
|
|
1339
|
+
`${N(
|
|
1340
|
+
this._lexer.token
|
|
1341
|
+
)} is reserved and cannot be used for an enum value.`
|
|
1342
|
+
);
|
|
1343
|
+
return this.parseName();
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* InputObjectTypeDefinition :
|
|
1347
|
+
* - Description? input Name Directives[Const]? InputFieldsDefinition?
|
|
1348
|
+
*
|
|
1349
|
+
* @internal
|
|
1350
|
+
*/
|
|
1351
|
+
parseInputObjectTypeDefinition() {
|
|
1352
|
+
const t = this._lexer.token, e = this.parseDescription();
|
|
1353
|
+
this.expectKeyword("input");
|
|
1354
|
+
const i = this.parseName(), s = this.parseConstDirectives(), o = this.parseInputFieldsDefinition();
|
|
1355
|
+
return this.node(t, {
|
|
1356
|
+
kind: a.INPUT_OBJECT_TYPE_DEFINITION,
|
|
1357
|
+
description: e,
|
|
1358
|
+
name: i,
|
|
1359
|
+
directives: s,
|
|
1360
|
+
fields: o
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* ```
|
|
1365
|
+
* InputFieldsDefinition : { InputValueDefinition+ }
|
|
1366
|
+
* ```
|
|
1367
|
+
*
|
|
1368
|
+
* @internal
|
|
1369
|
+
*/
|
|
1370
|
+
parseInputFieldsDefinition() {
|
|
1371
|
+
return this.optionalMany(
|
|
1372
|
+
r.BRACE_L,
|
|
1373
|
+
this.parseInputValueDef,
|
|
1374
|
+
r.BRACE_R
|
|
1375
|
+
);
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* TypeSystemExtension :
|
|
1379
|
+
* - SchemaExtension
|
|
1380
|
+
* - TypeExtension
|
|
1381
|
+
*
|
|
1382
|
+
* TypeExtension :
|
|
1383
|
+
* - ScalarTypeExtension
|
|
1384
|
+
* - ObjectTypeExtension
|
|
1385
|
+
* - InterfaceTypeExtension
|
|
1386
|
+
* - UnionTypeExtension
|
|
1387
|
+
* - EnumTypeExtension
|
|
1388
|
+
* - InputObjectTypeDefinition
|
|
1389
|
+
* - DirectiveDefinitionExtension
|
|
1390
|
+
*
|
|
1391
|
+
* @internal
|
|
1392
|
+
*/
|
|
1393
|
+
parseTypeSystemExtension() {
|
|
1394
|
+
const t = this._lexer.lookahead();
|
|
1395
|
+
if (t.kind === r.NAME)
|
|
1396
|
+
switch (t.value) {
|
|
1397
|
+
case "schema":
|
|
1398
|
+
return this.parseSchemaExtension();
|
|
1399
|
+
case "scalar":
|
|
1400
|
+
return this.parseScalarTypeExtension();
|
|
1401
|
+
case "type":
|
|
1402
|
+
return this.parseObjectTypeExtension();
|
|
1403
|
+
case "interface":
|
|
1404
|
+
return this.parseInterfaceTypeExtension();
|
|
1405
|
+
case "union":
|
|
1406
|
+
return this.parseUnionTypeExtension();
|
|
1407
|
+
case "enum":
|
|
1408
|
+
return this.parseEnumTypeExtension();
|
|
1409
|
+
case "input":
|
|
1410
|
+
return this.parseInputObjectTypeExtension();
|
|
1411
|
+
case "directive":
|
|
1412
|
+
if (this._options.experimentalDirectivesOnDirectiveDefinitions)
|
|
1413
|
+
return this.parseDirectiveDefinitionExtension();
|
|
1414
|
+
break;
|
|
1415
|
+
}
|
|
1416
|
+
throw this.unexpected(t);
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* ```
|
|
1420
|
+
* SchemaExtension :
|
|
1421
|
+
* - extend schema Directives[Const]? { OperationTypeDefinition+ }
|
|
1422
|
+
* - extend schema Directives[Const]
|
|
1423
|
+
* ```
|
|
1424
|
+
*
|
|
1425
|
+
* @internal
|
|
1426
|
+
*/
|
|
1427
|
+
parseSchemaExtension() {
|
|
1428
|
+
const t = this._lexer.token;
|
|
1429
|
+
this.expectKeyword("extend"), this.expectKeyword("schema");
|
|
1430
|
+
const e = this.parseConstDirectives(), i = this.optionalMany(
|
|
1431
|
+
r.BRACE_L,
|
|
1432
|
+
this.parseOperationTypeDefinition,
|
|
1433
|
+
r.BRACE_R
|
|
1434
|
+
);
|
|
1435
|
+
if (e.length === 0 && i.length === 0)
|
|
1436
|
+
throw this.unexpected();
|
|
1437
|
+
return this.node(t, {
|
|
1438
|
+
kind: a.SCHEMA_EXTENSION,
|
|
1439
|
+
directives: e,
|
|
1440
|
+
operationTypes: i
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* ScalarTypeExtension :
|
|
1445
|
+
* - extend scalar Name Directives[Const]
|
|
1446
|
+
*
|
|
1447
|
+
* @internal
|
|
1448
|
+
*/
|
|
1449
|
+
parseScalarTypeExtension() {
|
|
1450
|
+
const t = this._lexer.token;
|
|
1451
|
+
this.expectKeyword("extend"), this.expectKeyword("scalar");
|
|
1452
|
+
const e = this.parseName(), i = this.parseConstDirectives();
|
|
1453
|
+
if (i.length === 0)
|
|
1454
|
+
throw this.unexpected();
|
|
1455
|
+
return this.node(t, {
|
|
1456
|
+
kind: a.SCALAR_TYPE_EXTENSION,
|
|
1457
|
+
name: e,
|
|
1458
|
+
directives: i
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* ObjectTypeExtension :
|
|
1463
|
+
* - extend type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition
|
|
1464
|
+
* - extend type Name ImplementsInterfaces? Directives[Const]
|
|
1465
|
+
* - extend type Name ImplementsInterfaces
|
|
1466
|
+
*
|
|
1467
|
+
* @internal
|
|
1468
|
+
*/
|
|
1469
|
+
parseObjectTypeExtension() {
|
|
1470
|
+
const t = this._lexer.token;
|
|
1471
|
+
this.expectKeyword("extend"), this.expectKeyword("type");
|
|
1472
|
+
const e = this.parseName(), i = this.parseImplementsInterfaces(), s = this.parseConstDirectives(), o = this.parseFieldsDefinition();
|
|
1473
|
+
if (i.length === 0 && s.length === 0 && o.length === 0)
|
|
1474
|
+
throw this.unexpected();
|
|
1475
|
+
return this.node(t, {
|
|
1476
|
+
kind: a.OBJECT_TYPE_EXTENSION,
|
|
1477
|
+
name: e,
|
|
1478
|
+
interfaces: i,
|
|
1479
|
+
directives: s,
|
|
1480
|
+
fields: o
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
/**
|
|
1484
|
+
* InterfaceTypeExtension :
|
|
1485
|
+
* - extend interface Name ImplementsInterfaces? Directives[Const]? FieldsDefinition
|
|
1486
|
+
* - extend interface Name ImplementsInterfaces? Directives[Const]
|
|
1487
|
+
* - extend interface Name ImplementsInterfaces
|
|
1488
|
+
*
|
|
1489
|
+
* @internal
|
|
1490
|
+
*/
|
|
1491
|
+
parseInterfaceTypeExtension() {
|
|
1492
|
+
const t = this._lexer.token;
|
|
1493
|
+
this.expectKeyword("extend"), this.expectKeyword("interface");
|
|
1494
|
+
const e = this.parseName(), i = this.parseImplementsInterfaces(), s = this.parseConstDirectives(), o = this.parseFieldsDefinition();
|
|
1495
|
+
if (i.length === 0 && s.length === 0 && o.length === 0)
|
|
1496
|
+
throw this.unexpected();
|
|
1497
|
+
return this.node(t, {
|
|
1498
|
+
kind: a.INTERFACE_TYPE_EXTENSION,
|
|
1499
|
+
name: e,
|
|
1500
|
+
interfaces: i,
|
|
1501
|
+
directives: s,
|
|
1502
|
+
fields: o
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
/**
|
|
1506
|
+
* UnionTypeExtension :
|
|
1507
|
+
* - extend union Name Directives[Const]? UnionMemberTypes
|
|
1508
|
+
* - extend union Name Directives[Const]
|
|
1509
|
+
*
|
|
1510
|
+
* @internal
|
|
1511
|
+
*/
|
|
1512
|
+
parseUnionTypeExtension() {
|
|
1513
|
+
const t = this._lexer.token;
|
|
1514
|
+
this.expectKeyword("extend"), this.expectKeyword("union");
|
|
1515
|
+
const e = this.parseName(), i = this.parseConstDirectives(), s = this.parseUnionMemberTypes();
|
|
1516
|
+
if (i.length === 0 && s.length === 0)
|
|
1517
|
+
throw this.unexpected();
|
|
1518
|
+
return this.node(t, {
|
|
1519
|
+
kind: a.UNION_TYPE_EXTENSION,
|
|
1520
|
+
name: e,
|
|
1521
|
+
directives: i,
|
|
1522
|
+
types: s
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* EnumTypeExtension :
|
|
1527
|
+
* - extend enum Name Directives[Const]? EnumValuesDefinition
|
|
1528
|
+
* - extend enum Name Directives[Const]
|
|
1529
|
+
*
|
|
1530
|
+
* @internal
|
|
1531
|
+
*/
|
|
1532
|
+
parseEnumTypeExtension() {
|
|
1533
|
+
const t = this._lexer.token;
|
|
1534
|
+
this.expectKeyword("extend"), this.expectKeyword("enum");
|
|
1535
|
+
const e = this.parseName(), i = this.parseConstDirectives(), s = this.parseEnumValuesDefinition();
|
|
1536
|
+
if (i.length === 0 && s.length === 0)
|
|
1537
|
+
throw this.unexpected();
|
|
1538
|
+
return this.node(t, {
|
|
1539
|
+
kind: a.ENUM_TYPE_EXTENSION,
|
|
1540
|
+
name: e,
|
|
1541
|
+
directives: i,
|
|
1542
|
+
values: s
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
/**
|
|
1546
|
+
* InputObjectTypeExtension :
|
|
1547
|
+
* - extend input Name Directives[Const]? InputFieldsDefinition
|
|
1548
|
+
* - extend input Name Directives[Const]
|
|
1549
|
+
*
|
|
1550
|
+
* @internal
|
|
1551
|
+
*/
|
|
1552
|
+
parseInputObjectTypeExtension() {
|
|
1553
|
+
const t = this._lexer.token;
|
|
1554
|
+
this.expectKeyword("extend"), this.expectKeyword("input");
|
|
1555
|
+
const e = this.parseName(), i = this.parseConstDirectives(), s = this.parseInputFieldsDefinition();
|
|
1556
|
+
if (i.length === 0 && s.length === 0)
|
|
1557
|
+
throw this.unexpected();
|
|
1558
|
+
return this.node(t, {
|
|
1559
|
+
kind: a.INPUT_OBJECT_TYPE_EXTENSION,
|
|
1560
|
+
name: e,
|
|
1561
|
+
directives: i,
|
|
1562
|
+
fields: s
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
parseDirectiveDefinitionExtension() {
|
|
1566
|
+
const t = this._lexer.token;
|
|
1567
|
+
this.expectKeyword("extend"), this.expectKeyword("directive"), this.expectToken(r.AT);
|
|
1568
|
+
const e = this.parseName(), i = this.parseConstDirectives();
|
|
1569
|
+
if (i.length === 0)
|
|
1570
|
+
throw this.unexpected();
|
|
1571
|
+
return this.node(t, {
|
|
1572
|
+
kind: a.DIRECTIVE_EXTENSION,
|
|
1573
|
+
name: e,
|
|
1574
|
+
directives: i
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1577
|
+
/**
|
|
1578
|
+
* ```
|
|
1579
|
+
* DirectiveDefinition :
|
|
1580
|
+
* - Description? directive @ Name ArgumentsDefinition? `repeatable`? on DirectiveLocations
|
|
1581
|
+
* ```
|
|
1582
|
+
*
|
|
1583
|
+
* @internal
|
|
1584
|
+
*/
|
|
1585
|
+
parseDirectiveDefinition() {
|
|
1586
|
+
const t = this._lexer.token, e = this.parseDescription();
|
|
1587
|
+
this.expectKeyword("directive"), this.expectToken(r.AT);
|
|
1588
|
+
const i = this.parseName(), s = this.parseArgumentDefs(), o = this._options.experimentalDirectivesOnDirectiveDefinitions ? this.parseConstDirectives() : [], c = this.expectOptionalKeyword("repeatable");
|
|
1589
|
+
this.expectKeyword("on");
|
|
1590
|
+
const p = this.parseDirectiveLocations();
|
|
1591
|
+
return this.node(t, {
|
|
1592
|
+
kind: a.DIRECTIVE_DEFINITION,
|
|
1593
|
+
description: e,
|
|
1594
|
+
name: i,
|
|
1595
|
+
arguments: s,
|
|
1596
|
+
directives: o,
|
|
1597
|
+
repeatable: c,
|
|
1598
|
+
locations: p
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
/**
|
|
1602
|
+
* DirectiveLocations :
|
|
1603
|
+
* - `|`? DirectiveLocation
|
|
1604
|
+
* - DirectiveLocations | DirectiveLocation
|
|
1605
|
+
*
|
|
1606
|
+
* @internal
|
|
1607
|
+
*/
|
|
1608
|
+
parseDirectiveLocations() {
|
|
1609
|
+
return this.delimitedMany(r.PIPE, this.parseDirectiveLocation);
|
|
1610
|
+
}
|
|
1611
|
+
/*
|
|
1612
|
+
* DirectiveLocation :
|
|
1613
|
+
* - ExecutableDirectiveLocation
|
|
1614
|
+
* - TypeSystemDirectiveLocation
|
|
1615
|
+
*
|
|
1616
|
+
* ExecutableDirectiveLocation : one of
|
|
1617
|
+
* `QUERY`
|
|
1618
|
+
* `MUTATION`
|
|
1619
|
+
* `SUBSCRIPTION`
|
|
1620
|
+
* `FIELD`
|
|
1621
|
+
* `FRAGMENT_DEFINITION`
|
|
1622
|
+
* `FRAGMENT_SPREAD`
|
|
1623
|
+
* `INLINE_FRAGMENT`
|
|
1624
|
+
*
|
|
1625
|
+
* TypeSystemDirectiveLocation : one of
|
|
1626
|
+
* `SCHEMA`
|
|
1627
|
+
* `SCALAR`
|
|
1628
|
+
* `OBJECT`
|
|
1629
|
+
* `FIELD_DEFINITION`
|
|
1630
|
+
* `ARGUMENT_DEFINITION`
|
|
1631
|
+
* `INTERFACE`
|
|
1632
|
+
* `UNION`
|
|
1633
|
+
* `ENUM`
|
|
1634
|
+
* `ENUM_VALUE`
|
|
1635
|
+
* `INPUT_OBJECT`
|
|
1636
|
+
* `INPUT_FIELD_DEFINITION`
|
|
1637
|
+
* `DIRECTIVE_DEFINITION`
|
|
1638
|
+
*/
|
|
1639
|
+
parseDirectiveLocation() {
|
|
1640
|
+
const t = this._lexer.token, e = this.parseName();
|
|
1641
|
+
if (Object.prototype.hasOwnProperty.call(K, e.value))
|
|
1642
|
+
return e;
|
|
1643
|
+
throw this.unexpected(t);
|
|
1644
|
+
}
|
|
1645
|
+
// Schema Coordinates
|
|
1646
|
+
/**
|
|
1647
|
+
* SchemaCoordinate :
|
|
1648
|
+
* - Name
|
|
1649
|
+
* - Name . Name
|
|
1650
|
+
* - Name . Name ( Name : )
|
|
1651
|
+
* - \@ Name
|
|
1652
|
+
* - \@ Name ( Name : )
|
|
1653
|
+
* @returns Parsed schema coordinate AST.
|
|
1654
|
+
* @example
|
|
1655
|
+
* ```ts
|
|
1656
|
+
* import { Parser, Source } from 'graphql/language';
|
|
1657
|
+
*
|
|
1658
|
+
* const typeCoordinate = new Parser(new Source('User.name')).parseSchemaCoordinate();
|
|
1659
|
+
* const directiveCoordinate = new Parser(new Source('@include(if:)')).parseSchemaCoordinate();
|
|
1660
|
+
*
|
|
1661
|
+
* typeCoordinate.name.value; // => 'User'
|
|
1662
|
+
* typeCoordinate.memberName?.value; // => 'name'
|
|
1663
|
+
* directiveCoordinate.name.value; // => 'deprecated'
|
|
1664
|
+
* directiveCoordinate.argumentName?.value; // => 'reason'
|
|
1665
|
+
* ```
|
|
1666
|
+
*/
|
|
1667
|
+
parseSchemaCoordinate() {
|
|
1668
|
+
const t = this._lexer.token, e = this.expectOptionalToken(r.AT), i = this.parseName();
|
|
1669
|
+
let s;
|
|
1670
|
+
!e && this.expectOptionalToken(r.DOT) && (s = this.parseName());
|
|
1671
|
+
let o;
|
|
1672
|
+
return (e || s) && this.expectOptionalToken(r.PAREN_L) && (o = this.parseName(), this.expectToken(r.COLON), this.expectToken(r.PAREN_R)), e ? o ? this.node(t, {
|
|
1673
|
+
kind: a.DIRECTIVE_ARGUMENT_COORDINATE,
|
|
1674
|
+
name: i,
|
|
1675
|
+
argumentName: o
|
|
1676
|
+
}) : this.node(t, {
|
|
1677
|
+
kind: a.DIRECTIVE_COORDINATE,
|
|
1678
|
+
name: i
|
|
1679
|
+
}) : s ? o ? this.node(t, {
|
|
1680
|
+
kind: a.ARGUMENT_COORDINATE,
|
|
1681
|
+
name: i,
|
|
1682
|
+
fieldName: s,
|
|
1683
|
+
argumentName: o
|
|
1684
|
+
}) : this.node(t, {
|
|
1685
|
+
kind: a.MEMBER_COORDINATE,
|
|
1686
|
+
name: i,
|
|
1687
|
+
memberName: s
|
|
1688
|
+
}) : this.node(t, {
|
|
1689
|
+
kind: a.TYPE_COORDINATE,
|
|
1690
|
+
name: i
|
|
1691
|
+
});
|
|
1692
|
+
}
|
|
1693
|
+
// Core parsing utility functions
|
|
1694
|
+
/**
|
|
1695
|
+
* Returns a node that, if configured to do so, sets a "loc" field as a
|
|
1696
|
+
* location object, used to identify the place in the source that created a
|
|
1697
|
+
* given parsed object.
|
|
1698
|
+
*
|
|
1699
|
+
* @internal
|
|
1700
|
+
*/
|
|
1701
|
+
node(t, e) {
|
|
1702
|
+
return this._options.noLocation !== !0 && (e.loc = new G(
|
|
1703
|
+
t,
|
|
1704
|
+
this._lexer.lastToken,
|
|
1705
|
+
this._lexer.source
|
|
1706
|
+
)), e;
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Determines if the next token is of a given kind
|
|
1710
|
+
*
|
|
1711
|
+
* @internal
|
|
1712
|
+
*/
|
|
1713
|
+
peek(t) {
|
|
1714
|
+
return this._lexer.token.kind === t;
|
|
1715
|
+
}
|
|
1716
|
+
/**
|
|
1717
|
+
* If the next token is of the given kind, return that token after advancing the lexer.
|
|
1718
|
+
* Otherwise, do not change the parser state and throw an error.
|
|
1719
|
+
*
|
|
1720
|
+
* @internal
|
|
1721
|
+
*/
|
|
1722
|
+
expectToken(t) {
|
|
1723
|
+
const e = this._lexer.token;
|
|
1724
|
+
if (e.kind === t)
|
|
1725
|
+
return this.advanceLexer(), e;
|
|
1726
|
+
throw u(
|
|
1727
|
+
this._lexer.source,
|
|
1728
|
+
e.start,
|
|
1729
|
+
`Expected ${b(t)}, found ${N(e)}.`
|
|
1730
|
+
);
|
|
1731
|
+
}
|
|
1732
|
+
/**
|
|
1733
|
+
* If the next token is of the given kind, return "true" after advancing the lexer.
|
|
1734
|
+
* Otherwise, do not change the parser state and return "false".
|
|
1735
|
+
*
|
|
1736
|
+
* @internal
|
|
1737
|
+
*/
|
|
1738
|
+
expectOptionalToken(t) {
|
|
1739
|
+
return this._lexer.token.kind === t ? (this.advanceLexer(), !0) : !1;
|
|
1740
|
+
}
|
|
1741
|
+
/**
|
|
1742
|
+
* If the next token is a given keyword, advance the lexer.
|
|
1743
|
+
* Otherwise, do not change the parser state and throw an error.
|
|
1744
|
+
*
|
|
1745
|
+
* @internal
|
|
1746
|
+
*/
|
|
1747
|
+
expectKeyword(t) {
|
|
1748
|
+
const e = this._lexer.token;
|
|
1749
|
+
if (e.kind === r.NAME && e.value === t)
|
|
1750
|
+
this.advanceLexer();
|
|
1751
|
+
else
|
|
1752
|
+
throw u(
|
|
1753
|
+
this._lexer.source,
|
|
1754
|
+
e.start,
|
|
1755
|
+
`Expected "${t}", found ${N(e)}.`
|
|
1756
|
+
);
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* If the next token is a given keyword, return "true" after advancing the lexer.
|
|
1760
|
+
* Otherwise, do not change the parser state and return "false".
|
|
1761
|
+
*
|
|
1762
|
+
* @internal
|
|
1763
|
+
*/
|
|
1764
|
+
expectOptionalKeyword(t) {
|
|
1765
|
+
const e = this._lexer.token;
|
|
1766
|
+
return e.kind === r.NAME && e.value === t ? (this.advanceLexer(), !0) : !1;
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
* Helper function for creating an error when an unexpected lexed token is encountered.
|
|
1770
|
+
*
|
|
1771
|
+
* @internal
|
|
1772
|
+
*/
|
|
1773
|
+
unexpected(t) {
|
|
1774
|
+
const e = t ?? this._lexer.token;
|
|
1775
|
+
return u(
|
|
1776
|
+
this._lexer.source,
|
|
1777
|
+
e.start,
|
|
1778
|
+
`Unexpected ${N(e)}.`
|
|
1779
|
+
);
|
|
1780
|
+
}
|
|
1781
|
+
/**
|
|
1782
|
+
* Returns a possibly empty list of parse nodes, determined by the parseFn.
|
|
1783
|
+
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1784
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1785
|
+
*
|
|
1786
|
+
* @internal
|
|
1787
|
+
*/
|
|
1788
|
+
any(t, e, i) {
|
|
1789
|
+
this.expectToken(t);
|
|
1790
|
+
const s = [];
|
|
1791
|
+
for (; !this.expectOptionalToken(i); )
|
|
1792
|
+
s.push(e.call(this));
|
|
1793
|
+
return s;
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Returns a list of parse nodes, determined by the parseFn.
|
|
1797
|
+
* It can be empty only if open token is missing otherwise it will always return non-empty list
|
|
1798
|
+
* that begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1799
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1800
|
+
*
|
|
1801
|
+
* @internal
|
|
1802
|
+
*/
|
|
1803
|
+
optionalMany(t, e, i) {
|
|
1804
|
+
if (this.expectOptionalToken(t)) {
|
|
1805
|
+
const s = [];
|
|
1806
|
+
do
|
|
1807
|
+
s.push(e.call(this));
|
|
1808
|
+
while (!this.expectOptionalToken(i));
|
|
1809
|
+
return s;
|
|
1810
|
+
}
|
|
1811
|
+
return [];
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* Returns a non-empty list of parse nodes, determined by the parseFn.
|
|
1815
|
+
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1816
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1817
|
+
*
|
|
1818
|
+
* @internal
|
|
1819
|
+
*/
|
|
1820
|
+
many(t, e, i) {
|
|
1821
|
+
this.expectToken(t);
|
|
1822
|
+
const s = [];
|
|
1823
|
+
do
|
|
1824
|
+
s.push(e.call(this));
|
|
1825
|
+
while (!this.expectOptionalToken(i));
|
|
1826
|
+
return s;
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* Returns a non-empty list of parse nodes, determined by the parseFn.
|
|
1830
|
+
* This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
|
|
1831
|
+
* Advances the parser to the next lex token after last item in the list.
|
|
1832
|
+
*
|
|
1833
|
+
* @internal
|
|
1834
|
+
*/
|
|
1835
|
+
delimitedMany(t, e) {
|
|
1836
|
+
this.expectOptionalToken(t);
|
|
1837
|
+
const i = [];
|
|
1838
|
+
do
|
|
1839
|
+
i.push(e.call(this));
|
|
1840
|
+
while (this.expectOptionalToken(t));
|
|
1841
|
+
return i;
|
|
1842
|
+
}
|
|
1843
|
+
advanceLexer() {
|
|
1844
|
+
const { maxTokens: t } = this._options, e = this._lexer.advance();
|
|
1845
|
+
if (e.kind !== r.EOF && (++this._tokenCounter, t !== void 0 && this._tokenCounter > t))
|
|
1846
|
+
throw u(
|
|
1847
|
+
this._lexer.source,
|
|
1848
|
+
e.start,
|
|
1849
|
+
`Document contains more that ${t} tokens. Parsing aborted.`
|
|
1850
|
+
);
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
function N(n) {
|
|
1854
|
+
const t = n.value;
|
|
1855
|
+
return b(n.kind) + (t != null ? ` "${t}"` : "");
|
|
1856
|
+
}
|
|
1857
|
+
function b(n) {
|
|
1858
|
+
return Q(n) ? `"${n}"` : n;
|
|
1859
|
+
}
|
|
1860
|
+
function oe(n, t) {
|
|
1861
|
+
const e = {};
|
|
1862
|
+
for (const i of Object.keys(n)) {
|
|
1863
|
+
const s = n[i];
|
|
1864
|
+
if (!s)
|
|
1865
|
+
continue;
|
|
1866
|
+
const o = typeof s == "function" ? s : s.enter, c = typeof s == "function" ? void 0 : s.leave;
|
|
1867
|
+
e[i] = {
|
|
1868
|
+
...o ? { enter: I(o, t) } : {},
|
|
1869
|
+
...c ? { leave: I(c, t) } : {}
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
return e;
|
|
1873
|
+
}
|
|
1874
|
+
function I(n, t) {
|
|
1875
|
+
return (e, i, s, o, c) => {
|
|
1876
|
+
n(e, ae(e, t, c));
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
function ae(n, t, e = []) {
|
|
1880
|
+
const { ruleId: i, severity: s, message: o, source: c, config: p, problems: d } = t, f = e.filter((l) => !Array.isArray(l));
|
|
1881
|
+
return {
|
|
1882
|
+
source: c,
|
|
1883
|
+
config: p,
|
|
1884
|
+
ancestors: f,
|
|
1885
|
+
report(l) {
|
|
1886
|
+
const P = l.node ?? n, O = l.loc ?? ce(P), F = {
|
|
1887
|
+
source: c,
|
|
1888
|
+
pointer: void 0,
|
|
1889
|
+
start: O?.start ?? { line: 1, col: 1 },
|
|
1890
|
+
end: O?.end
|
|
1891
|
+
};
|
|
1892
|
+
d.push({
|
|
1893
|
+
ruleId: l.ruleId ?? i,
|
|
1894
|
+
severity: l.severity ?? s,
|
|
1895
|
+
message: o ? o.replace("{{message}}", l.message) : l.message,
|
|
1896
|
+
suggest: l.suggest ?? [],
|
|
1897
|
+
location: [F]
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1901
|
+
}
|
|
1902
|
+
function ce(n) {
|
|
1903
|
+
if (!n?.loc)
|
|
1904
|
+
return;
|
|
1905
|
+
const t = v(n.loc.source, n.loc.start), e = v(n.loc.source, n.loc.end);
|
|
1906
|
+
return {
|
|
1907
|
+
start: { line: t.line, col: t.column },
|
|
1908
|
+
end: { line: e.line, col: e.column }
|
|
1909
|
+
};
|
|
1910
|
+
}
|
|
1911
|
+
function de(n) {
|
|
1912
|
+
const { document: t, config: e } = n, i = t.source;
|
|
1913
|
+
if (i.body.trim() === "")
|
|
1914
|
+
return [
|
|
1915
|
+
{
|
|
1916
|
+
ruleId: "struct",
|
|
1917
|
+
severity: "error",
|
|
1918
|
+
message: "The GraphQL document is empty. Expected at least one type definition.",
|
|
1919
|
+
suggest: [],
|
|
1920
|
+
location: [{ source: i, pointer: void 0, start: { line: 1, col: 1 } }]
|
|
1921
|
+
}
|
|
1922
|
+
];
|
|
1923
|
+
let s;
|
|
1924
|
+
try {
|
|
1925
|
+
s = ie(new y(i.body, i.absoluteRef));
|
|
1926
|
+
} catch (d) {
|
|
1927
|
+
if (d instanceof R)
|
|
1928
|
+
return [he(d, i)];
|
|
1929
|
+
throw d;
|
|
1930
|
+
}
|
|
1931
|
+
const o = e.getRulesForSpecVersion("graphql") ?? [], c = $(o, e, "rules", "graphql");
|
|
1932
|
+
return pe({ ast: s, source: i, config: e, rules: c }).map((d) => e.addProblemToIgnore(d));
|
|
1933
|
+
}
|
|
1934
|
+
function he(n, t) {
|
|
1935
|
+
const e = n.locations?.[0];
|
|
1936
|
+
return {
|
|
1937
|
+
ruleId: "struct",
|
|
1938
|
+
severity: "error",
|
|
1939
|
+
message: n.message,
|
|
1940
|
+
suggest: [],
|
|
1941
|
+
location: [
|
|
1942
|
+
{
|
|
1943
|
+
source: t,
|
|
1944
|
+
pointer: void 0,
|
|
1945
|
+
start: e ? { line: e.line, col: e.column } : { line: 1, col: 1 }
|
|
1946
|
+
}
|
|
1947
|
+
]
|
|
1948
|
+
};
|
|
1949
|
+
}
|
|
1950
|
+
function pe(n) {
|
|
1951
|
+
const { ast: t, source: e, config: i, rules: s } = n, o = [], c = s.map(({ ruleId: p, severity: d, message: f, visitor: l }) => oe(l, { ruleId: p, severity: d, message: f, source: e, config: i, problems: o }));
|
|
1952
|
+
return c.length > 0 && Y(t, j(c)), o;
|
|
1953
|
+
}
|
|
1954
|
+
export {
|
|
1955
|
+
de as lintGraphqlDocument
|
|
1956
|
+
};
|