graphql 16.4.0 → 16.6.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.
@@ -14,7 +14,7 @@ import type { Source } from '../language/source';
14
14
  export interface GraphQLErrorExtensions {
15
15
  [attributeName: string]: unknown;
16
16
  }
17
- export interface GraphQLErrorArgs {
17
+ export interface GraphQLErrorOptions {
18
18
  nodes?: ReadonlyArray<ASTNode> | ASTNode | null;
19
19
  source?: Maybe<Source>;
20
20
  positions?: Maybe<ReadonlyArray<number>>;
@@ -75,9 +75,9 @@ export declare class GraphQLError extends Error {
75
75
  * Extension fields to add to the formatted error.
76
76
  */
77
77
  readonly extensions: GraphQLErrorExtensions;
78
- constructor(message: string, args?: GraphQLErrorArgs);
78
+ constructor(message: string, options?: GraphQLErrorOptions);
79
79
  /**
80
- * @deprecated Please use the `GraphQLErrorArgs` constructor overload instead.
80
+ * @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
81
81
  */
82
82
  constructor(
83
83
  message: string,
@@ -13,7 +13,7 @@ var _location = require('../language/location.js');
13
13
 
14
14
  var _printLocation = require('../language/printLocation.js');
15
15
 
16
- function toNormalizedArgs(args) {
16
+ function toNormalizedOptions(args) {
17
17
  const firstArg = args[0];
18
18
 
19
19
  if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
@@ -80,13 +80,13 @@ class GraphQLError extends Error {
80
80
  */
81
81
 
82
82
  /**
83
- * @deprecated Please use the `GraphQLErrorArgs` constructor overload instead.
83
+ * @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
84
84
  */
85
85
  constructor(message, ...rawArgs) {
86
86
  var _this$nodes, _nodeLocations$, _ref;
87
87
 
88
88
  const { nodes, source, positions, path, originalError, extensions } =
89
- toNormalizedArgs(rawArgs);
89
+ toNormalizedOptions(rawArgs);
90
90
  super(message);
91
91
  this.name = 'GraphQLError';
92
92
  this.path = path !== null && path !== void 0 ? path : undefined;
@@ -5,7 +5,7 @@ import {
5
5
  printSourceLocation,
6
6
  } from '../language/printLocation.mjs';
7
7
 
8
- function toNormalizedArgs(args) {
8
+ function toNormalizedOptions(args) {
9
9
  const firstArg = args[0];
10
10
 
11
11
  if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
@@ -72,13 +72,13 @@ export class GraphQLError extends Error {
72
72
  */
73
73
 
74
74
  /**
75
- * @deprecated Please use the `GraphQLErrorArgs` constructor overload instead.
75
+ * @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
76
76
  */
77
77
  constructor(message, ...rawArgs) {
78
78
  var _this$nodes, _nodeLocations$, _ref;
79
79
 
80
80
  const { nodes, source, positions, path, originalError, extensions } =
81
- toNormalizedArgs(rawArgs);
81
+ toNormalizedOptions(rawArgs);
82
82
  super(message);
83
83
  this.name = 'GraphQLError';
84
84
  this.path = path !== null && path !== void 0 ? path : undefined;
package/error/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { GraphQLError, printError, formatError } from './GraphQLError';
2
2
  export type {
3
+ GraphQLErrorOptions,
3
4
  GraphQLFormattedError,
4
5
  GraphQLErrorExtensions,
5
6
  } from './GraphQLError';
@@ -55,6 +55,10 @@ export declare function subscribe(
55
55
  * or otherwise separating these two steps. For more on this, see the
56
56
  * "Supporting Subscriptions at Scale" information in the GraphQL specification.
57
57
  */
58
+ export declare function createSourceEventStream(
59
+ args: ExecutionArgs,
60
+ ): Promise<AsyncIterable<unknown> | ExecutionResult>;
61
+ /** @deprecated will be removed in next major version in favor of named arguments */
58
62
  export declare function createSourceEventStream(
59
63
  schema: GraphQLSchema,
60
64
  document: DocumentNode,
@@ -54,25 +54,7 @@ async function subscribe(args) {
54
54
  false,
55
55
  'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.',
56
56
  );
57
- const {
58
- schema,
59
- document,
60
- rootValue,
61
- contextValue,
62
- variableValues,
63
- operationName,
64
- fieldResolver,
65
- subscribeFieldResolver,
66
- } = args;
67
- const resultOrStream = await createSourceEventStream(
68
- schema,
69
- document,
70
- rootValue,
71
- contextValue,
72
- variableValues,
73
- operationName,
74
- subscribeFieldResolver,
75
- );
57
+ const resultOrStream = await createSourceEventStream(args);
76
58
 
77
59
  if (!(0, _isAsyncIterable.isAsyncIterable)(resultOrStream)) {
78
60
  return resultOrStream;
@@ -84,21 +66,32 @@ async function subscribe(args) {
84
66
  // "ExecuteQuery" algorithm, for which `execute` is also used.
85
67
 
86
68
  const mapSourceToResponse = (payload) =>
87
- (0, _execute.execute)({
88
- schema,
89
- document,
90
- rootValue: payload,
91
- contextValue,
92
- variableValues,
93
- operationName,
94
- fieldResolver,
95
- }); // Map every source value to a ExecutionResult value as described above.
69
+ (0, _execute.execute)({ ...args, rootValue: payload }); // Map every source value to a ExecutionResult value as described above.
96
70
 
97
71
  return (0, _mapAsyncIterator.mapAsyncIterator)(
98
72
  resultOrStream,
99
73
  mapSourceToResponse,
100
74
  );
101
75
  }
76
+
77
+ function toNormalizedArgs(args) {
78
+ const firstArg = args[0];
79
+
80
+ if (firstArg && 'document' in firstArg) {
81
+ return firstArg;
82
+ }
83
+
84
+ return {
85
+ schema: firstArg,
86
+ // FIXME: when underlying TS bug fixed, see https://github.com/microsoft/TypeScript/issues/31613
87
+ document: args[1],
88
+ rootValue: args[2],
89
+ contextValue: args[3],
90
+ variableValues: args[4],
91
+ operationName: args[5],
92
+ subscribeFieldResolver: args[6],
93
+ };
94
+ }
102
95
  /**
103
96
  * Implements the "CreateSourceEventStream" algorithm described in the
104
97
  * GraphQL specification, resolving the subscription source event stream.
@@ -128,29 +121,15 @@ async function subscribe(args) {
128
121
  * "Supporting Subscriptions at Scale" information in the GraphQL specification.
129
122
  */
130
123
 
131
- async function createSourceEventStream(
132
- schema,
133
- document,
134
- rootValue,
135
- contextValue,
136
- variableValues,
137
- operationName,
138
- subscribeFieldResolver,
139
- ) {
140
- // If arguments are missing or incorrectly typed, this is an internal
124
+ async function createSourceEventStream(...rawArgs) {
125
+ const args = toNormalizedArgs(rawArgs);
126
+ const { schema, document, variableValues } = args; // If arguments are missing or incorrectly typed, this is an internal
141
127
  // developer mistake which should throw an early error.
128
+
142
129
  (0, _execute.assertValidExecutionArguments)(schema, document, variableValues); // If a valid execution context cannot be created due to incorrect arguments,
143
130
  // a "Response" with only errors is returned.
144
131
 
145
- const exeContext = (0, _execute.buildExecutionContext)({
146
- schema,
147
- document,
148
- rootValue,
149
- contextValue,
150
- variableValues,
151
- operationName,
152
- subscribeFieldResolver,
153
- }); // Return early errors if execution context failed.
132
+ const exeContext = (0, _execute.buildExecutionContext)(args); // Return early errors if execution context failed.
154
133
 
155
134
  if (!('schema' in exeContext)) {
156
135
  return {
@@ -43,25 +43,7 @@ export async function subscribe(args) {
43
43
  false,
44
44
  'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.',
45
45
  );
46
- const {
47
- schema,
48
- document,
49
- rootValue,
50
- contextValue,
51
- variableValues,
52
- operationName,
53
- fieldResolver,
54
- subscribeFieldResolver,
55
- } = args;
56
- const resultOrStream = await createSourceEventStream(
57
- schema,
58
- document,
59
- rootValue,
60
- contextValue,
61
- variableValues,
62
- operationName,
63
- subscribeFieldResolver,
64
- );
46
+ const resultOrStream = await createSourceEventStream(args);
65
47
 
66
48
  if (!isAsyncIterable(resultOrStream)) {
67
49
  return resultOrStream;
@@ -73,18 +55,29 @@ export async function subscribe(args) {
73
55
  // "ExecuteQuery" algorithm, for which `execute` is also used.
74
56
 
75
57
  const mapSourceToResponse = (payload) =>
76
- execute({
77
- schema,
78
- document,
79
- rootValue: payload,
80
- contextValue,
81
- variableValues,
82
- operationName,
83
- fieldResolver,
84
- }); // Map every source value to a ExecutionResult value as described above.
58
+ execute({ ...args, rootValue: payload }); // Map every source value to a ExecutionResult value as described above.
85
59
 
86
60
  return mapAsyncIterator(resultOrStream, mapSourceToResponse);
87
61
  }
62
+
63
+ function toNormalizedArgs(args) {
64
+ const firstArg = args[0];
65
+
66
+ if (firstArg && 'document' in firstArg) {
67
+ return firstArg;
68
+ }
69
+
70
+ return {
71
+ schema: firstArg,
72
+ // FIXME: when underlying TS bug fixed, see https://github.com/microsoft/TypeScript/issues/31613
73
+ document: args[1],
74
+ rootValue: args[2],
75
+ contextValue: args[3],
76
+ variableValues: args[4],
77
+ operationName: args[5],
78
+ subscribeFieldResolver: args[6],
79
+ };
80
+ }
88
81
  /**
89
82
  * Implements the "CreateSourceEventStream" algorithm described in the
90
83
  * GraphQL specification, resolving the subscription source event stream.
@@ -114,29 +107,15 @@ export async function subscribe(args) {
114
107
  * "Supporting Subscriptions at Scale" information in the GraphQL specification.
115
108
  */
116
109
 
117
- export async function createSourceEventStream(
118
- schema,
119
- document,
120
- rootValue,
121
- contextValue,
122
- variableValues,
123
- operationName,
124
- subscribeFieldResolver,
125
- ) {
126
- // If arguments are missing or incorrectly typed, this is an internal
110
+ export async function createSourceEventStream(...rawArgs) {
111
+ const args = toNormalizedArgs(rawArgs);
112
+ const { schema, document, variableValues } = args; // If arguments are missing or incorrectly typed, this is an internal
127
113
  // developer mistake which should throw an early error.
114
+
128
115
  assertValidExecutionArguments(schema, document, variableValues); // If a valid execution context cannot be created due to incorrect arguments,
129
116
  // a "Response" with only errors is returned.
130
117
 
131
- const exeContext = buildExecutionContext({
132
- schema,
133
- document,
134
- rootValue,
135
- contextValue,
136
- variableValues,
137
- operationName,
138
- subscribeFieldResolver,
139
- }); // Return early errors if execution context failed.
118
+ const exeContext = buildExecutionContext(args); // Return early errors if execution context failed.
140
119
 
141
120
  if (!('schema' in exeContext)) {
142
121
  return {
package/index.d.ts CHANGED
@@ -346,6 +346,7 @@ export {
346
346
  formatError,
347
347
  } from './error/index';
348
348
  export type {
349
+ GraphQLErrorOptions,
349
350
  GraphQLFormattedError,
350
351
  GraphQLErrorExtensions,
351
352
  } from './error/index';
package/language/ast.d.ts CHANGED
@@ -179,11 +179,12 @@ export interface OperationDefinitionNode {
179
179
  readonly directives?: ReadonlyArray<DirectiveNode>;
180
180
  readonly selectionSet: SelectionSetNode;
181
181
  }
182
- export declare enum OperationTypeNode {
182
+ declare enum OperationTypeNode {
183
183
  QUERY = 'query',
184
184
  MUTATION = 'mutation',
185
185
  SUBSCRIPTION = 'subscription',
186
186
  }
187
+ export { OperationTypeNode };
187
188
  export interface VariableDefinitionNode {
188
189
  readonly kind: Kind.VARIABLE_DEFINITION;
189
190
  readonly loc?: Location;
package/language/ast.js CHANGED
@@ -214,7 +214,7 @@ function isNode(maybeNode) {
214
214
  }
215
215
  /** Name */
216
216
 
217
- let OperationTypeNode;
217
+ var OperationTypeNode;
218
218
  exports.OperationTypeNode = OperationTypeNode;
219
219
 
220
220
  (function (OperationTypeNode) {
package/language/ast.mjs CHANGED
@@ -197,10 +197,12 @@ export function isNode(maybeNode) {
197
197
  }
198
198
  /** Name */
199
199
 
200
- export let OperationTypeNode;
200
+ var OperationTypeNode;
201
201
 
202
202
  (function (OperationTypeNode) {
203
203
  OperationTypeNode['QUERY'] = 'query';
204
204
  OperationTypeNode['MUTATION'] = 'mutation';
205
205
  OperationTypeNode['SUBSCRIPTION'] = 'subscription';
206
206
  })(OperationTypeNode || (OperationTypeNode = {}));
207
+
208
+ export { OperationTypeNode };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The set of allowed directive location values.
3
3
  */
4
- export declare enum DirectiveLocation {
4
+ declare enum DirectiveLocation {
5
5
  /** Request Definitions */
6
6
  QUERY = 'QUERY',
7
7
  MUTATION = 'MUTATION',
@@ -24,6 +24,7 @@ export declare enum DirectiveLocation {
24
24
  INPUT_OBJECT = 'INPUT_OBJECT',
25
25
  INPUT_FIELD_DEFINITION = 'INPUT_FIELD_DEFINITION',
26
26
  }
27
+ export { DirectiveLocation };
27
28
  /**
28
29
  * The enum type representing the directive location values.
29
30
  *
@@ -8,13 +8,7 @@ exports.DirectiveLocation = void 0;
8
8
  /**
9
9
  * The set of allowed directive location values.
10
10
  */
11
- let DirectiveLocation;
12
- /**
13
- * The enum type representing the directive location values.
14
- *
15
- * @deprecated Please use `DirectiveLocation`. Will be remove in v17.
16
- */
17
-
11
+ var DirectiveLocation;
18
12
  exports.DirectiveLocation = DirectiveLocation;
19
13
 
20
14
  (function (DirectiveLocation) {
@@ -38,3 +32,8 @@ exports.DirectiveLocation = DirectiveLocation;
38
32
  DirectiveLocation['INPUT_OBJECT'] = 'INPUT_OBJECT';
39
33
  DirectiveLocation['INPUT_FIELD_DEFINITION'] = 'INPUT_FIELD_DEFINITION';
40
34
  })(DirectiveLocation || (exports.DirectiveLocation = DirectiveLocation = {}));
35
+ /**
36
+ * The enum type representing the directive location values.
37
+ *
38
+ * @deprecated Please use `DirectiveLocation`. Will be remove in v17.
39
+ */
@@ -1,12 +1,7 @@
1
1
  /**
2
2
  * The set of allowed directive location values.
3
3
  */
4
- export let DirectiveLocation;
5
- /**
6
- * The enum type representing the directive location values.
7
- *
8
- * @deprecated Please use `DirectiveLocation`. Will be remove in v17.
9
- */
4
+ var DirectiveLocation;
10
5
 
11
6
  (function (DirectiveLocation) {
12
7
  DirectiveLocation['QUERY'] = 'QUERY';
@@ -29,3 +24,10 @@ export let DirectiveLocation;
29
24
  DirectiveLocation['INPUT_OBJECT'] = 'INPUT_OBJECT';
30
25
  DirectiveLocation['INPUT_FIELD_DEFINITION'] = 'INPUT_FIELD_DEFINITION';
31
26
  })(DirectiveLocation || (DirectiveLocation = {}));
27
+
28
+ export { DirectiveLocation };
29
+ /**
30
+ * The enum type representing the directive location values.
31
+ *
32
+ * @deprecated Please use `DirectiveLocation`. Will be remove in v17.
33
+ */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The set of allowed kind values for AST nodes.
3
3
  */
4
- export declare enum Kind {
4
+ declare enum Kind {
5
5
  /** Name */
6
6
  NAME = 'Name',
7
7
  /** Document */
@@ -57,6 +57,7 @@ export declare enum Kind {
57
57
  ENUM_TYPE_EXTENSION = 'EnumTypeExtension',
58
58
  INPUT_OBJECT_TYPE_EXTENSION = 'InputObjectTypeExtension',
59
59
  }
60
+ export { Kind };
60
61
  /**
61
62
  * The enum type representing the possible kind values of AST nodes.
62
63
  *
package/language/kinds.js CHANGED
@@ -8,13 +8,7 @@ exports.Kind = void 0;
8
8
  /**
9
9
  * The set of allowed kind values for AST nodes.
10
10
  */
11
- let Kind;
12
- /**
13
- * The enum type representing the possible kind values of AST nodes.
14
- *
15
- * @deprecated Please use `Kind`. Will be remove in v17.
16
- */
17
-
11
+ var Kind;
18
12
  exports.Kind = Kind;
19
13
 
20
14
  (function (Kind) {
@@ -62,3 +56,8 @@ exports.Kind = Kind;
62
56
  Kind['ENUM_TYPE_EXTENSION'] = 'EnumTypeExtension';
63
57
  Kind['INPUT_OBJECT_TYPE_EXTENSION'] = 'InputObjectTypeExtension';
64
58
  })(Kind || (exports.Kind = Kind = {}));
59
+ /**
60
+ * The enum type representing the possible kind values of AST nodes.
61
+ *
62
+ * @deprecated Please use `Kind`. Will be remove in v17.
63
+ */
@@ -1,12 +1,7 @@
1
1
  /**
2
2
  * The set of allowed kind values for AST nodes.
3
3
  */
4
- export let Kind;
5
- /**
6
- * The enum type representing the possible kind values of AST nodes.
7
- *
8
- * @deprecated Please use `Kind`. Will be remove in v17.
9
- */
4
+ var Kind;
10
5
 
11
6
  (function (Kind) {
12
7
  Kind['NAME'] = 'Name';
@@ -53,3 +48,10 @@ export let Kind;
53
48
  Kind['ENUM_TYPE_EXTENSION'] = 'EnumTypeExtension';
54
49
  Kind['INPUT_OBJECT_TYPE_EXTENSION'] = 'InputObjectTypeExtension';
55
50
  })(Kind || (Kind = {}));
51
+
52
+ export { Kind };
53
+ /**
54
+ * The enum type representing the possible kind values of AST nodes.
55
+ *
56
+ * @deprecated Please use `Kind`. Will be remove in v17.
57
+ */
@@ -64,6 +64,14 @@ export interface ParseOptions {
64
64
  * disables that behavior for performance or testing.
65
65
  */
66
66
  noLocation?: boolean;
67
+ /**
68
+ * Parser CPU and memory usage is linear to the number of tokens in a document
69
+ * however in extreme cases it becomes quadratic due to memory exhaustion.
70
+ * Parsing happens before validation so even invalid queries can burn lots of
71
+ * CPU time and memory.
72
+ * To prevent this you can set a maximum number of tokens allowed within a document.
73
+ */
74
+ maxTokens?: number | undefined;
67
75
  /**
68
76
  * @deprecated will be removed in the v17.0.0
69
77
  *
@@ -87,7 +95,7 @@ export interface ParseOptions {
87
95
  */
88
96
  export declare function parse(
89
97
  source: string | Source,
90
- options?: ParseOptions,
98
+ options?: ParseOptions | undefined,
91
99
  ): DocumentNode;
92
100
  /**
93
101
  * Given a string containing a GraphQL value (ex. `[42]`), parse the AST for
@@ -101,7 +109,7 @@ export declare function parse(
101
109
  */
102
110
  export declare function parseValue(
103
111
  source: string | Source,
104
- options?: ParseOptions,
112
+ options?: ParseOptions | undefined,
105
113
  ): ValueNode;
106
114
  /**
107
115
  * Similar to parseValue(), but raises a parse error if it encounters a
@@ -109,7 +117,7 @@ export declare function parseValue(
109
117
  */
110
118
  export declare function parseConstValue(
111
119
  source: string | Source,
112
- options?: ParseOptions,
120
+ options?: ParseOptions | undefined,
113
121
  ): ConstValueNode;
114
122
  /**
115
123
  * Given a string containing a GraphQL Type (ex. `[Int!]`), parse the AST for
@@ -123,7 +131,7 @@ export declare function parseConstValue(
123
131
  */
124
132
  export declare function parseType(
125
133
  source: string | Source,
126
- options?: ParseOptions,
134
+ options?: ParseOptions | undefined,
127
135
  ): TypeNode;
128
136
  /**
129
137
  * This class is exported only to assist people in implementing their own parsers
@@ -137,8 +145,9 @@ export declare function parseType(
137
145
  * @internal
138
146
  */
139
147
  export declare class Parser {
140
- protected _options: Maybe<ParseOptions>;
148
+ protected _options: ParseOptions;
141
149
  protected _lexer: Lexer;
150
+ protected _tokenCounter: number;
142
151
  constructor(source: string | Source, options?: ParseOptions);
143
152
  /**
144
153
  * Converts a name lex token into a name parse node.
@@ -551,4 +560,5 @@ export declare class Parser {
551
560
  * Advances the parser to the next lex token after last item in the list.
552
561
  */
553
562
  delimitedMany<T>(delimiterKind: TokenKind, parseFn: () => T): Array<T>;
563
+ advanceLexer(): void;
554
564
  }
@@ -92,12 +92,13 @@ function parseType(source, options) {
92
92
  */
93
93
 
94
94
  class Parser {
95
- constructor(source, options) {
95
+ constructor(source, options = {}) {
96
96
  const sourceObj = (0, _source.isSource)(source)
97
97
  ? source
98
98
  : new _source.Source(source);
99
99
  this._lexer = new _lexer.Lexer(sourceObj);
100
100
  this._options = options;
101
+ this._tokenCounter = 0;
101
102
  }
102
103
  /**
103
104
  * Converts a name lex token into a name parse node.
@@ -432,18 +433,12 @@ class Parser {
432
433
  */
433
434
 
434
435
  parseFragmentDefinition() {
435
- var _this$_options;
436
-
437
436
  const start = this._lexer.token;
438
437
  this.expectKeyword('fragment'); // Legacy support for defining variables within fragments changes
439
438
  // the grammar of FragmentDefinition:
440
439
  // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
441
440
 
442
- if (
443
- ((_this$_options = this._options) === null || _this$_options === void 0
444
- ? void 0
445
- : _this$_options.allowLegacyFragmentVariables) === true
446
- ) {
441
+ if (this._options.allowLegacyFragmentVariables === true) {
447
442
  return this.node(start, {
448
443
  kind: _kinds.Kind.FRAGMENT_DEFINITION,
449
444
  name: this.parseFragmentName(),
@@ -504,16 +499,14 @@ class Parser {
504
499
  return this.parseObject(isConst);
505
500
 
506
501
  case _tokenKind.TokenKind.INT:
507
- this._lexer.advance();
508
-
502
+ this.advanceLexer();
509
503
  return this.node(token, {
510
504
  kind: _kinds.Kind.INT,
511
505
  value: token.value,
512
506
  });
513
507
 
514
508
  case _tokenKind.TokenKind.FLOAT:
515
- this._lexer.advance();
516
-
509
+ this.advanceLexer();
517
510
  return this.node(token, {
518
511
  kind: _kinds.Kind.FLOAT,
519
512
  value: token.value,
@@ -524,7 +517,7 @@ class Parser {
524
517
  return this.parseStringLiteral();
525
518
 
526
519
  case _tokenKind.TokenKind.NAME:
527
- this._lexer.advance();
520
+ this.advanceLexer();
528
521
 
529
522
  switch (token.value) {
530
523
  case 'true':
@@ -580,9 +573,7 @@ class Parser {
580
573
 
581
574
  parseStringLiteral() {
582
575
  const token = this._lexer.token;
583
-
584
- this._lexer.advance();
585
-
576
+ this.advanceLexer();
586
577
  return this.node(token, {
587
578
  kind: _kinds.Kind.STRING,
588
579
  value: token.value,
@@ -1373,13 +1364,7 @@ class Parser {
1373
1364
  */
1374
1365
 
1375
1366
  node(startToken, node) {
1376
- var _this$_options2;
1377
-
1378
- if (
1379
- ((_this$_options2 = this._options) === null || _this$_options2 === void 0
1380
- ? void 0
1381
- : _this$_options2.noLocation) !== true
1382
- ) {
1367
+ if (this._options.noLocation !== true) {
1383
1368
  node.loc = new _ast.Location(
1384
1369
  startToken,
1385
1370
  this._lexer.lastToken,
@@ -1405,8 +1390,7 @@ class Parser {
1405
1390
  const token = this._lexer.token;
1406
1391
 
1407
1392
  if (token.kind === kind) {
1408
- this._lexer.advance();
1409
-
1393
+ this.advanceLexer();
1410
1394
  return token;
1411
1395
  }
1412
1396
 
@@ -1425,8 +1409,7 @@ class Parser {
1425
1409
  const token = this._lexer.token;
1426
1410
 
1427
1411
  if (token.kind === kind) {
1428
- this._lexer.advance();
1429
-
1412
+ this.advanceLexer();
1430
1413
  return true;
1431
1414
  }
1432
1415
 
@@ -1441,7 +1424,7 @@ class Parser {
1441
1424
  const token = this._lexer.token;
1442
1425
 
1443
1426
  if (token.kind === _tokenKind.TokenKind.NAME && token.value === value) {
1444
- this._lexer.advance();
1427
+ this.advanceLexer();
1445
1428
  } else {
1446
1429
  throw (0, _syntaxError.syntaxError)(
1447
1430
  this._lexer.source,
@@ -1459,8 +1442,7 @@ class Parser {
1459
1442
  const token = this._lexer.token;
1460
1443
 
1461
1444
  if (token.kind === _tokenKind.TokenKind.NAME && token.value === value) {
1462
- this._lexer.advance();
1463
-
1445
+ this.advanceLexer();
1464
1446
  return true;
1465
1447
  }
1466
1448
 
@@ -1547,6 +1529,24 @@ class Parser {
1547
1529
 
1548
1530
  return nodes;
1549
1531
  }
1532
+
1533
+ advanceLexer() {
1534
+ const { maxTokens } = this._options;
1535
+
1536
+ const token = this._lexer.advance();
1537
+
1538
+ if (maxTokens !== undefined && token.kind !== _tokenKind.TokenKind.EOF) {
1539
+ ++this._tokenCounter;
1540
+
1541
+ if (this._tokenCounter > maxTokens) {
1542
+ throw (0, _syntaxError.syntaxError)(
1543
+ this._lexer.source,
1544
+ token.start,
1545
+ `Document contains more that ${maxTokens} tokens. Parsing aborted.`,
1546
+ );
1547
+ }
1548
+ }
1549
+ }
1550
1550
  }
1551
1551
  /**
1552
1552
  * A helper function to describe a token as a string for debugging.
@@ -78,10 +78,11 @@ export function parseType(source, options) {
78
78
  */
79
79
 
80
80
  export class Parser {
81
- constructor(source, options) {
81
+ constructor(source, options = {}) {
82
82
  const sourceObj = isSource(source) ? source : new Source(source);
83
83
  this._lexer = new Lexer(sourceObj);
84
84
  this._options = options;
85
+ this._tokenCounter = 0;
85
86
  }
86
87
  /**
87
88
  * Converts a name lex token into a name parse node.
@@ -410,18 +411,12 @@ export class Parser {
410
411
  */
411
412
 
412
413
  parseFragmentDefinition() {
413
- var _this$_options;
414
-
415
414
  const start = this._lexer.token;
416
415
  this.expectKeyword('fragment'); // Legacy support for defining variables within fragments changes
417
416
  // the grammar of FragmentDefinition:
418
417
  // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
419
418
 
420
- if (
421
- ((_this$_options = this._options) === null || _this$_options === void 0
422
- ? void 0
423
- : _this$_options.allowLegacyFragmentVariables) === true
424
- ) {
419
+ if (this._options.allowLegacyFragmentVariables === true) {
425
420
  return this.node(start, {
426
421
  kind: Kind.FRAGMENT_DEFINITION,
427
422
  name: this.parseFragmentName(),
@@ -482,16 +477,14 @@ export class Parser {
482
477
  return this.parseObject(isConst);
483
478
 
484
479
  case TokenKind.INT:
485
- this._lexer.advance();
486
-
480
+ this.advanceLexer();
487
481
  return this.node(token, {
488
482
  kind: Kind.INT,
489
483
  value: token.value,
490
484
  });
491
485
 
492
486
  case TokenKind.FLOAT:
493
- this._lexer.advance();
494
-
487
+ this.advanceLexer();
495
488
  return this.node(token, {
496
489
  kind: Kind.FLOAT,
497
490
  value: token.value,
@@ -502,7 +495,7 @@ export class Parser {
502
495
  return this.parseStringLiteral();
503
496
 
504
497
  case TokenKind.NAME:
505
- this._lexer.advance();
498
+ this.advanceLexer();
506
499
 
507
500
  switch (token.value) {
508
501
  case 'true':
@@ -558,9 +551,7 @@ export class Parser {
558
551
 
559
552
  parseStringLiteral() {
560
553
  const token = this._lexer.token;
561
-
562
- this._lexer.advance();
563
-
554
+ this.advanceLexer();
564
555
  return this.node(token, {
565
556
  kind: Kind.STRING,
566
557
  value: token.value,
@@ -1332,13 +1323,7 @@ export class Parser {
1332
1323
  */
1333
1324
 
1334
1325
  node(startToken, node) {
1335
- var _this$_options2;
1336
-
1337
- if (
1338
- ((_this$_options2 = this._options) === null || _this$_options2 === void 0
1339
- ? void 0
1340
- : _this$_options2.noLocation) !== true
1341
- ) {
1326
+ if (this._options.noLocation !== true) {
1342
1327
  node.loc = new Location(
1343
1328
  startToken,
1344
1329
  this._lexer.lastToken,
@@ -1364,8 +1349,7 @@ export class Parser {
1364
1349
  const token = this._lexer.token;
1365
1350
 
1366
1351
  if (token.kind === kind) {
1367
- this._lexer.advance();
1368
-
1352
+ this.advanceLexer();
1369
1353
  return token;
1370
1354
  }
1371
1355
 
@@ -1384,8 +1368,7 @@ export class Parser {
1384
1368
  const token = this._lexer.token;
1385
1369
 
1386
1370
  if (token.kind === kind) {
1387
- this._lexer.advance();
1388
-
1371
+ this.advanceLexer();
1389
1372
  return true;
1390
1373
  }
1391
1374
 
@@ -1400,7 +1383,7 @@ export class Parser {
1400
1383
  const token = this._lexer.token;
1401
1384
 
1402
1385
  if (token.kind === TokenKind.NAME && token.value === value) {
1403
- this._lexer.advance();
1386
+ this.advanceLexer();
1404
1387
  } else {
1405
1388
  throw syntaxError(
1406
1389
  this._lexer.source,
@@ -1418,8 +1401,7 @@ export class Parser {
1418
1401
  const token = this._lexer.token;
1419
1402
 
1420
1403
  if (token.kind === TokenKind.NAME && token.value === value) {
1421
- this._lexer.advance();
1422
-
1404
+ this.advanceLexer();
1423
1405
  return true;
1424
1406
  }
1425
1407
 
@@ -1506,6 +1488,24 @@ export class Parser {
1506
1488
 
1507
1489
  return nodes;
1508
1490
  }
1491
+
1492
+ advanceLexer() {
1493
+ const { maxTokens } = this._options;
1494
+
1495
+ const token = this._lexer.advance();
1496
+
1497
+ if (maxTokens !== undefined && token.kind !== TokenKind.EOF) {
1498
+ ++this._tokenCounter;
1499
+
1500
+ if (this._tokenCounter > maxTokens) {
1501
+ throw syntaxError(
1502
+ this._lexer.source,
1503
+ token.start,
1504
+ `Document contains more that ${maxTokens} tokens. Parsing aborted.`,
1505
+ );
1506
+ }
1507
+ }
1508
+ }
1509
1509
  }
1510
1510
  /**
1511
1511
  * A helper function to describe a token as a string for debugging.
@@ -2,7 +2,7 @@
2
2
  * An exported enum describing the different kinds of tokens that the
3
3
  * lexer emits.
4
4
  */
5
- export declare enum TokenKind {
5
+ declare enum TokenKind {
6
6
  SOF = '<SOF>',
7
7
  EOF = '<EOF>',
8
8
  BANG = '!',
@@ -26,6 +26,7 @@ export declare enum TokenKind {
26
26
  BLOCK_STRING = 'BlockString',
27
27
  COMMENT = 'Comment',
28
28
  }
29
+ export { TokenKind };
29
30
  /**
30
31
  * The enum type representing the token kinds values.
31
32
  *
@@ -9,13 +9,7 @@ exports.TokenKind = void 0;
9
9
  * An exported enum describing the different kinds of tokens that the
10
10
  * lexer emits.
11
11
  */
12
- let TokenKind;
13
- /**
14
- * The enum type representing the token kinds values.
15
- *
16
- * @deprecated Please use `TokenKind`. Will be remove in v17.
17
- */
18
-
12
+ var TokenKind;
19
13
  exports.TokenKind = TokenKind;
20
14
 
21
15
  (function (TokenKind) {
@@ -42,3 +36,8 @@ exports.TokenKind = TokenKind;
42
36
  TokenKind['BLOCK_STRING'] = 'BlockString';
43
37
  TokenKind['COMMENT'] = 'Comment';
44
38
  })(TokenKind || (exports.TokenKind = TokenKind = {}));
39
+ /**
40
+ * The enum type representing the token kinds values.
41
+ *
42
+ * @deprecated Please use `TokenKind`. Will be remove in v17.
43
+ */
@@ -2,12 +2,7 @@
2
2
  * An exported enum describing the different kinds of tokens that the
3
3
  * lexer emits.
4
4
  */
5
- export let TokenKind;
6
- /**
7
- * The enum type representing the token kinds values.
8
- *
9
- * @deprecated Please use `TokenKind`. Will be remove in v17.
10
- */
5
+ var TokenKind;
11
6
 
12
7
  (function (TokenKind) {
13
8
  TokenKind['SOF'] = '<SOF>';
@@ -33,3 +28,10 @@ export let TokenKind;
33
28
  TokenKind['BLOCK_STRING'] = 'BlockString';
34
29
  TokenKind['COMMENT'] = 'Comment';
35
30
  })(TokenKind || (TokenKind = {}));
31
+
32
+ export { TokenKind };
33
+ /**
34
+ * The enum type representing the token kinds values.
35
+ *
36
+ * @deprecated Please use `TokenKind`. Will be remove in v17.
37
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql",
3
- "version": "16.4.0",
3
+ "version": "16.6.0",
4
4
  "description": "A Query Language and Runtime which can target any service.",
5
5
  "license": "MIT",
6
6
  "main": "index",
@@ -7,7 +7,7 @@ export declare const __Type: GraphQLObjectType;
7
7
  export declare const __Field: GraphQLObjectType;
8
8
  export declare const __InputValue: GraphQLObjectType;
9
9
  export declare const __EnumValue: GraphQLObjectType;
10
- export declare enum TypeKind {
10
+ declare enum TypeKind {
11
11
  SCALAR = 'SCALAR',
12
12
  OBJECT = 'OBJECT',
13
13
  INTERFACE = 'INTERFACE',
@@ -17,6 +17,7 @@ export declare enum TypeKind {
17
17
  LIST = 'LIST',
18
18
  NON_NULL = 'NON_NULL',
19
19
  }
20
+ export { TypeKind };
20
21
  export declare const __TypeKind: GraphQLEnumType;
21
22
  /**
22
23
  * Note that these are GraphQLField and not GraphQLFieldConfig,
@@ -493,7 +493,7 @@ const __EnumValue = new _definition.GraphQLObjectType({
493
493
  });
494
494
 
495
495
  exports.__EnumValue = __EnumValue;
496
- let TypeKind;
496
+ var TypeKind;
497
497
  exports.TypeKind = TypeKind;
498
498
 
499
499
  (function (TypeKind) {
@@ -433,7 +433,7 @@ export const __EnumValue = new GraphQLObjectType({
433
433
  },
434
434
  }),
435
435
  });
436
- export let TypeKind;
436
+ var TypeKind;
437
437
 
438
438
  (function (TypeKind) {
439
439
  TypeKind['SCALAR'] = 'SCALAR';
@@ -446,6 +446,7 @@ export let TypeKind;
446
446
  TypeKind['NON_NULL'] = 'NON_NULL';
447
447
  })(TypeKind || (TypeKind = {}));
448
448
 
449
+ export { TypeKind };
449
450
  export const __TypeKind = new GraphQLEnumType({
450
451
  name: '__TypeKind',
451
452
  description: 'An enum describing what kind of type a given `__Type` is.',
@@ -1,5 +1,5 @@
1
1
  import type { GraphQLSchema } from '../type/schema';
2
- export declare enum BreakingChangeType {
2
+ declare enum BreakingChangeType {
3
3
  TYPE_REMOVED = 'TYPE_REMOVED',
4
4
  TYPE_CHANGED_KIND = 'TYPE_CHANGED_KIND',
5
5
  TYPE_REMOVED_FROM_UNION = 'TYPE_REMOVED_FROM_UNION',
@@ -17,7 +17,8 @@ export declare enum BreakingChangeType {
17
17
  DIRECTIVE_REPEATABLE_REMOVED = 'DIRECTIVE_REPEATABLE_REMOVED',
18
18
  DIRECTIVE_LOCATION_REMOVED = 'DIRECTIVE_LOCATION_REMOVED',
19
19
  }
20
- export declare enum DangerousChangeType {
20
+ export { BreakingChangeType };
21
+ declare enum DangerousChangeType {
21
22
  VALUE_ADDED_TO_ENUM = 'VALUE_ADDED_TO_ENUM',
22
23
  TYPE_ADDED_TO_UNION = 'TYPE_ADDED_TO_UNION',
23
24
  OPTIONAL_INPUT_FIELD_ADDED = 'OPTIONAL_INPUT_FIELD_ADDED',
@@ -25,6 +26,7 @@ export declare enum DangerousChangeType {
25
26
  IMPLEMENTED_INTERFACE_ADDED = 'IMPLEMENTED_INTERFACE_ADDED',
26
27
  ARG_DEFAULT_VALUE_CHANGE = 'ARG_DEFAULT_VALUE_CHANGE',
27
28
  }
29
+ export { DangerousChangeType };
28
30
  export interface BreakingChange {
29
31
  type: BreakingChangeType;
30
32
  description: string;
@@ -23,7 +23,7 @@ var _astFromValue = require('./astFromValue.js');
23
23
 
24
24
  var _sortValueNode = require('./sortValueNode.js');
25
25
 
26
- let BreakingChangeType;
26
+ var BreakingChangeType;
27
27
  exports.BreakingChangeType = BreakingChangeType;
28
28
 
29
29
  (function (BreakingChangeType) {
@@ -52,7 +52,7 @@ exports.BreakingChangeType = BreakingChangeType;
52
52
  BreakingChangeType || (exports.BreakingChangeType = BreakingChangeType = {}),
53
53
  );
54
54
 
55
- let DangerousChangeType;
55
+ var DangerousChangeType;
56
56
  exports.DangerousChangeType = DangerousChangeType;
57
57
 
58
58
  (function (DangerousChangeType) {
@@ -18,7 +18,7 @@ import {
18
18
  import { isSpecifiedScalarType } from '../type/scalars.mjs';
19
19
  import { astFromValue } from './astFromValue.mjs';
20
20
  import { sortValueNode } from './sortValueNode.mjs';
21
- export let BreakingChangeType;
21
+ var BreakingChangeType;
22
22
 
23
23
  (function (BreakingChangeType) {
24
24
  BreakingChangeType['TYPE_REMOVED'] = 'TYPE_REMOVED';
@@ -44,7 +44,8 @@ export let BreakingChangeType;
44
44
  'DIRECTIVE_LOCATION_REMOVED';
45
45
  })(BreakingChangeType || (BreakingChangeType = {}));
46
46
 
47
- export let DangerousChangeType;
47
+ export { BreakingChangeType };
48
+ var DangerousChangeType;
48
49
 
49
50
  (function (DangerousChangeType) {
50
51
  DangerousChangeType['VALUE_ADDED_TO_ENUM'] = 'VALUE_ADDED_TO_ENUM';
@@ -57,6 +58,8 @@ export let DangerousChangeType;
57
58
  DangerousChangeType['ARG_DEFAULT_VALUE_CHANGE'] = 'ARG_DEFAULT_VALUE_CHANGE';
58
59
  })(DangerousChangeType || (DangerousChangeType = {}));
59
60
 
61
+ export { DangerousChangeType };
62
+
60
63
  /**
61
64
  * Given two schemas, returns an Array containing descriptions of all the types
62
65
  * of breaking changes covered by the other functions down below.
package/version.js CHANGED
@@ -10,7 +10,7 @@ exports.versionInfo = exports.version = void 0;
10
10
  /**
11
11
  * A string containing the version of the GraphQL.js library
12
12
  */
13
- const version = '16.4.0';
13
+ const version = '16.6.0';
14
14
  /**
15
15
  * An object containing the components of the GraphQL.js version string
16
16
  */
@@ -18,7 +18,7 @@ const version = '16.4.0';
18
18
  exports.version = version;
19
19
  const versionInfo = Object.freeze({
20
20
  major: 16,
21
- minor: 4,
21
+ minor: 6,
22
22
  patch: 0,
23
23
  preReleaseTag: null,
24
24
  });
package/version.mjs CHANGED
@@ -4,14 +4,14 @@
4
4
  /**
5
5
  * A string containing the version of the GraphQL.js library
6
6
  */
7
- export const version = '16.4.0';
7
+ export const version = '16.6.0';
8
8
  /**
9
9
  * An object containing the components of the GraphQL.js version string
10
10
  */
11
11
 
12
12
  export const versionInfo = Object.freeze({
13
13
  major: 16,
14
- minor: 4,
14
+ minor: 6,
15
15
  patch: 0,
16
16
  preReleaseTag: null,
17
17
  });