graphql 16.12.0 → 16.13.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.
@@ -55,7 +55,18 @@ export interface ExecutionContext {
55
55
  fieldResolver: GraphQLFieldResolver<any, any>;
56
56
  typeResolver: GraphQLTypeResolver<any, any>;
57
57
  subscribeFieldResolver: GraphQLFieldResolver<any, any>;
58
- errors: Array<GraphQLError>;
58
+ collectedErrors: CollectedErrors;
59
+ }
60
+ /**
61
+ * @internal
62
+ */
63
+ declare class CollectedErrors {
64
+ private _errorPositions;
65
+ private _errors;
66
+ constructor();
67
+ get errors(): ReadonlyArray<GraphQLError>;
68
+ add(error: GraphQLError, path: Path | undefined): void;
69
+ private _hasNulledPosition;
59
70
  }
60
71
  /**
61
72
  * The result of GraphQL execution.
@@ -121,6 +132,7 @@ export declare function executeSync(args: ExecutionArgs): ExecutionResult;
121
132
  * Essential assertions before executing to provide developer feedback for
122
133
  * improper use of the GraphQL library.
123
134
  *
135
+ * @deprecated will be removed in v17 in favor of assertValidSchema() and TS checks
124
136
  * @internal
125
137
  */
126
138
  export declare function assertValidExecutionArguments(
@@ -188,3 +200,4 @@ export declare function getFieldDef(
188
200
  parentType: GraphQLObjectType,
189
201
  fieldNode: FieldNode,
190
202
  ): Maybe<GraphQLField<unknown, unknown>>;
203
+ export {};
@@ -91,6 +91,55 @@ const collectSubfields = (0, _memoize.memoize3)(
91
91
  * and the fragments defined in the query document
92
92
  */
93
93
 
94
+ /**
95
+ * @internal
96
+ */
97
+ class CollectedErrors {
98
+ constructor() {
99
+ this._errorPositions = new Set();
100
+ this._errors = [];
101
+ }
102
+
103
+ get errors() {
104
+ return this._errors;
105
+ }
106
+
107
+ add(error, path) {
108
+ // Do not modify errors list if the execution position for this error or
109
+ // any of its ancestors has already been nulled via error propagation.
110
+ // This check should be unnecessary for implementations able to implement
111
+ // actual cancellation.
112
+ if (this._hasNulledPosition(path)) {
113
+ return;
114
+ }
115
+
116
+ this._errorPositions.add(path);
117
+
118
+ this._errors.push(error);
119
+ }
120
+
121
+ _hasNulledPosition(startPath) {
122
+ let path = startPath;
123
+
124
+ while (path !== undefined) {
125
+ if (this._errorPositions.has(path)) {
126
+ return true;
127
+ }
128
+
129
+ path = path.prev;
130
+ }
131
+
132
+ return this._errorPositions.has(undefined);
133
+ }
134
+ }
135
+ /**
136
+ * The result of GraphQL execution.
137
+ *
138
+ * - `errors` is included when any errors occurred as a non-empty array.
139
+ * - `data` is the result of a successful execution of the query.
140
+ * - `extensions` is reserved for adding non-standard properties.
141
+ */
142
+
94
143
  /**
95
144
  * Implements the "Executing requests" section of the GraphQL specification.
96
145
  *
@@ -137,18 +186,18 @@ function execute(args) {
137
186
 
138
187
  if ((0, _isPromise.isPromise)(result)) {
139
188
  return result.then(
140
- (data) => buildResponse(data, exeContext.errors),
189
+ (data) => buildResponse(data, exeContext.collectedErrors.errors),
141
190
  (error) => {
142
- exeContext.errors.push(error);
143
- return buildResponse(null, exeContext.errors);
191
+ exeContext.collectedErrors.add(error, undefined);
192
+ return buildResponse(null, exeContext.collectedErrors.errors);
144
193
  },
145
194
  );
146
195
  }
147
196
 
148
- return buildResponse(result, exeContext.errors);
197
+ return buildResponse(result, exeContext.collectedErrors.errors);
149
198
  } catch (error) {
150
- exeContext.errors.push(error);
151
- return buildResponse(null, exeContext.errors);
199
+ exeContext.collectedErrors.add(error, undefined);
200
+ return buildResponse(null, exeContext.collectedErrors.errors);
152
201
  }
153
202
  }
154
203
  /**
@@ -185,6 +234,7 @@ function buildResponse(data, errors) {
185
234
  * Essential assertions before executing to provide developer feedback for
186
235
  * improper use of the GraphQL library.
187
236
  *
237
+ * @deprecated will be removed in v17 in favor of assertValidSchema() and TS checks
188
238
  * @internal
189
239
  */
190
240
 
@@ -319,7 +369,7 @@ function buildExecutionContext(args) {
319
369
  subscribeFieldResolver !== null && subscribeFieldResolver !== void 0
320
370
  ? subscribeFieldResolver
321
371
  : defaultFieldResolver,
322
- errors: [],
372
+ collectedErrors: new CollectedErrors(),
323
373
  };
324
374
  }
325
375
  /**
@@ -524,7 +574,7 @@ function executeField(exeContext, parentType, source, fieldNodes, path) {
524
574
  fieldNodes,
525
575
  (0, _Path.pathToArray)(path),
526
576
  );
527
- return handleFieldError(error, returnType, exeContext);
577
+ return handleFieldError(error, returnType, path, exeContext);
528
578
  });
529
579
  }
530
580
 
@@ -535,7 +585,7 @@ function executeField(exeContext, parentType, source, fieldNodes, path) {
535
585
  fieldNodes,
536
586
  (0, _Path.pathToArray)(path),
537
587
  );
538
- return handleFieldError(error, returnType, exeContext);
588
+ return handleFieldError(error, returnType, path, exeContext);
539
589
  }
540
590
  }
541
591
  /**
@@ -559,7 +609,7 @@ function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path) {
559
609
  };
560
610
  }
561
611
 
562
- function handleFieldError(error, returnType, exeContext) {
612
+ function handleFieldError(error, returnType, path, exeContext) {
563
613
  // If the field type is non-nullable, then it is resolved without any
564
614
  // protection from errors, however it still properly locates the error.
565
615
  if ((0, _definition.isNonNullType)(returnType)) {
@@ -567,7 +617,7 @@ function handleFieldError(error, returnType, exeContext) {
567
617
  } // Otherwise, error protection is applied, logging the error and resolving
568
618
  // a null value for this field if one is encountered.
569
619
 
570
- exeContext.errors.push(error);
620
+ exeContext.collectedErrors.add(error, path);
571
621
  return null;
572
622
  }
573
623
  /**
@@ -732,7 +782,7 @@ function completeListValue(
732
782
  fieldNodes,
733
783
  (0, _Path.pathToArray)(itemPath),
734
784
  );
735
- return handleFieldError(error, itemType, exeContext);
785
+ return handleFieldError(error, itemType, itemPath, exeContext);
736
786
  });
737
787
  }
738
788
 
@@ -743,7 +793,7 @@ function completeListValue(
743
793
  fieldNodes,
744
794
  (0, _Path.pathToArray)(itemPath),
745
795
  );
746
- return handleFieldError(error, itemType, exeContext);
796
+ return handleFieldError(error, itemType, itemPath, exeContext);
747
797
  }
748
798
  });
749
799
  return containsPromise ? Promise.all(completedResults) : completedResults;
@@ -72,6 +72,55 @@ const collectSubfields = memoize3((exeContext, returnType, fieldNodes) =>
72
72
  * and the fragments defined in the query document
73
73
  */
74
74
 
75
+ /**
76
+ * @internal
77
+ */
78
+ class CollectedErrors {
79
+ constructor() {
80
+ this._errorPositions = new Set();
81
+ this._errors = [];
82
+ }
83
+
84
+ get errors() {
85
+ return this._errors;
86
+ }
87
+
88
+ add(error, path) {
89
+ // Do not modify errors list if the execution position for this error or
90
+ // any of its ancestors has already been nulled via error propagation.
91
+ // This check should be unnecessary for implementations able to implement
92
+ // actual cancellation.
93
+ if (this._hasNulledPosition(path)) {
94
+ return;
95
+ }
96
+
97
+ this._errorPositions.add(path);
98
+
99
+ this._errors.push(error);
100
+ }
101
+
102
+ _hasNulledPosition(startPath) {
103
+ let path = startPath;
104
+
105
+ while (path !== undefined) {
106
+ if (this._errorPositions.has(path)) {
107
+ return true;
108
+ }
109
+
110
+ path = path.prev;
111
+ }
112
+
113
+ return this._errorPositions.has(undefined);
114
+ }
115
+ }
116
+ /**
117
+ * The result of GraphQL execution.
118
+ *
119
+ * - `errors` is included when any errors occurred as a non-empty array.
120
+ * - `data` is the result of a successful execution of the query.
121
+ * - `extensions` is reserved for adding non-standard properties.
122
+ */
123
+
75
124
  /**
76
125
  * Implements the "Executing requests" section of the GraphQL specification.
77
126
  *
@@ -118,18 +167,18 @@ export function execute(args) {
118
167
 
119
168
  if (isPromise(result)) {
120
169
  return result.then(
121
- (data) => buildResponse(data, exeContext.errors),
170
+ (data) => buildResponse(data, exeContext.collectedErrors.errors),
122
171
  (error) => {
123
- exeContext.errors.push(error);
124
- return buildResponse(null, exeContext.errors);
172
+ exeContext.collectedErrors.add(error, undefined);
173
+ return buildResponse(null, exeContext.collectedErrors.errors);
125
174
  },
126
175
  );
127
176
  }
128
177
 
129
- return buildResponse(result, exeContext.errors);
178
+ return buildResponse(result, exeContext.collectedErrors.errors);
130
179
  } catch (error) {
131
- exeContext.errors.push(error);
132
- return buildResponse(null, exeContext.errors);
180
+ exeContext.collectedErrors.add(error, undefined);
181
+ return buildResponse(null, exeContext.collectedErrors.errors);
133
182
  }
134
183
  }
135
184
  /**
@@ -166,6 +215,7 @@ function buildResponse(data, errors) {
166
215
  * Essential assertions before executing to provide developer feedback for
167
216
  * improper use of the GraphQL library.
168
217
  *
218
+ * @deprecated will be removed in v17 in favor of assertValidSchema() and TS checks
169
219
  * @internal
170
220
  */
171
221
 
@@ -300,7 +350,7 @@ export function buildExecutionContext(args) {
300
350
  subscribeFieldResolver !== null && subscribeFieldResolver !== void 0
301
351
  ? subscribeFieldResolver
302
352
  : defaultFieldResolver,
303
- errors: [],
353
+ collectedErrors: new CollectedErrors(),
304
354
  };
305
355
  }
306
356
  /**
@@ -501,14 +551,14 @@ function executeField(exeContext, parentType, source, fieldNodes, path) {
501
551
  // to take a second callback for the error case.
502
552
  return completed.then(undefined, (rawError) => {
503
553
  const error = locatedError(rawError, fieldNodes, pathToArray(path));
504
- return handleFieldError(error, returnType, exeContext);
554
+ return handleFieldError(error, returnType, path, exeContext);
505
555
  });
506
556
  }
507
557
 
508
558
  return completed;
509
559
  } catch (rawError) {
510
560
  const error = locatedError(rawError, fieldNodes, pathToArray(path));
511
- return handleFieldError(error, returnType, exeContext);
561
+ return handleFieldError(error, returnType, path, exeContext);
512
562
  }
513
563
  }
514
564
  /**
@@ -538,7 +588,7 @@ export function buildResolveInfo(
538
588
  };
539
589
  }
540
590
 
541
- function handleFieldError(error, returnType, exeContext) {
591
+ function handleFieldError(error, returnType, path, exeContext) {
542
592
  // If the field type is non-nullable, then it is resolved without any
543
593
  // protection from errors, however it still properly locates the error.
544
594
  if (isNonNullType(returnType)) {
@@ -546,7 +596,7 @@ function handleFieldError(error, returnType, exeContext) {
546
596
  } // Otherwise, error protection is applied, logging the error and resolving
547
597
  // a null value for this field if one is encountered.
548
598
 
549
- exeContext.errors.push(error);
599
+ exeContext.collectedErrors.add(error, path);
550
600
  return null;
551
601
  }
552
602
  /**
@@ -710,14 +760,14 @@ function completeListValue(
710
760
  fieldNodes,
711
761
  pathToArray(itemPath),
712
762
  );
713
- return handleFieldError(error, itemType, exeContext);
763
+ return handleFieldError(error, itemType, itemPath, exeContext);
714
764
  });
715
765
  }
716
766
 
717
767
  return completedItem;
718
768
  } catch (rawError) {
719
769
  const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
720
- return handleFieldError(error, itemType, exeContext);
770
+ return handleFieldError(error, itemType, itemPath, exeContext);
721
771
  }
722
772
  });
723
773
  return containsPromise ? Promise.all(completedResults) : completedResults;
@@ -125,6 +125,7 @@ async function createSourceEventStream(...rawArgs) {
125
125
  const args = toNormalizedArgs(rawArgs);
126
126
  const { schema, document, variableValues } = args; // If arguments are missing or incorrectly typed, this is an internal
127
127
  // developer mistake which should throw an early error.
128
+ // eslint-disable-next-line import/no-deprecated
128
129
 
129
130
  (0, _execute.assertValidExecutionArguments)(schema, document, variableValues); // If a valid execution context cannot be created due to incorrect arguments,
130
131
  // a "Response" with only errors is returned.
@@ -6,6 +6,7 @@ import { GraphQLError } from '../error/GraphQLError.mjs';
6
6
  import { locatedError } from '../error/locatedError.mjs';
7
7
  import { collectFields } from './collectFields.mjs';
8
8
  import {
9
+ // eslint-disable-next-line import/no-deprecated
9
10
  assertValidExecutionArguments,
10
11
  buildExecutionContext,
11
12
  buildResolveInfo,
@@ -111,6 +112,7 @@ export async function createSourceEventStream(...rawArgs) {
111
112
  const args = toNormalizedArgs(rawArgs);
112
113
  const { schema, document, variableValues } = args; // If arguments are missing or incorrectly typed, this is an internal
113
114
  // developer mistake which should throw an early error.
115
+ // eslint-disable-next-line import/no-deprecated
114
116
 
115
117
  assertValidExecutionArguments(schema, document, variableValues); // If a valid execution context cannot be created due to incorrect arguments,
116
118
  // a "Response" with only errors is returned.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql",
3
- "version": "16.12.0",
3
+ "version": "16.13.0",
4
4
  "description": "A Query Language and Runtime which can target any service.",
5
5
  "license": "MIT",
6
6
  "main": "index",
@@ -132,6 +132,11 @@ function ValuesOfCorrectTypeRule(context) {
132
132
  EnumValue: (node) => isValidValueNode(context, node),
133
133
  IntValue: (node) => isValidValueNode(context, node),
134
134
  FloatValue: (node) => isValidValueNode(context, node),
135
+ // Descriptions are string values that would not validate according
136
+ // to the below logic, but since (per the specification) descriptions must
137
+ // not affect validation, they are ignored entirely when visiting the AST
138
+ // and do not require special handling.
139
+ // See https://spec.graphql.org/draft/#sec-Descriptions
135
140
  StringValue: (node) => isValidValueNode(context, node),
136
141
  BooleanValue: (node) => isValidValueNode(context, node),
137
142
  };
@@ -117,6 +117,11 @@ export function ValuesOfCorrectTypeRule(context) {
117
117
  EnumValue: (node) => isValidValueNode(context, node),
118
118
  IntValue: (node) => isValidValueNode(context, node),
119
119
  FloatValue: (node) => isValidValueNode(context, node),
120
+ // Descriptions are string values that would not validate according
121
+ // to the below logic, but since (per the specification) descriptions must
122
+ // not affect validation, they are ignored entirely when visiting the AST
123
+ // and do not require special handling.
124
+ // See https://spec.graphql.org/draft/#sec-Descriptions
120
125
  StringValue: (node) => isValidValueNode(context, node),
121
126
  BooleanValue: (node) => isValidValueNode(context, node),
122
127
  };
@@ -10,8 +10,12 @@ exports.validateSDL = validateSDL;
10
10
 
11
11
  var _devAssert = require('../jsutils/devAssert.js');
12
12
 
13
+ var _mapValue = require('../jsutils/mapValue.js');
14
+
13
15
  var _GraphQLError = require('../error/GraphQLError.js');
14
16
 
17
+ var _ast = require('../language/ast.js');
18
+
15
19
  var _visitor = require('../language/visitor.js');
16
20
 
17
21
  var _validate = require('../type/validate.js');
@@ -22,6 +26,12 @@ var _specifiedRules = require('./specifiedRules.js');
22
26
 
23
27
  var _ValidationContext = require('./ValidationContext.js');
24
28
 
29
+ // Per the specification, descriptions must not affect validation.
30
+ // See https://spec.graphql.org/draft/#sec-Descriptions
31
+ const QueryDocumentKeysToValidate = (0, _mapValue.mapValue)(
32
+ _ast.QueryDocumentKeys,
33
+ (keys) => keys.filter((key) => key !== 'description'),
34
+ );
25
35
  /**
26
36
  * Implements the "Validation" section of the spec.
27
37
  *
@@ -42,6 +52,7 @@ var _ValidationContext = require('./ValidationContext.js');
42
52
  * Optionally a custom TypeInfo instance may be provided. If not provided, one
43
53
  * will be created from the provided schema.
44
54
  */
55
+
45
56
  function validate(
46
57
  schema,
47
58
  documentAST,
@@ -91,6 +102,7 @@ function validate(
91
102
  (0, _visitor.visit)(
92
103
  documentAST,
93
104
  (0, _TypeInfo.visitWithTypeInfo)(typeInfo, visitor),
105
+ QueryDocumentKeysToValidate,
94
106
  );
95
107
  } catch (e) {
96
108
  if (e !== abortObj) {
@@ -1,5 +1,7 @@
1
1
  import { devAssert } from '../jsutils/devAssert.mjs';
2
+ import { mapValue } from '../jsutils/mapValue.mjs';
2
3
  import { GraphQLError } from '../error/GraphQLError.mjs';
4
+ import { QueryDocumentKeys } from '../language/ast.mjs';
3
5
  import { visit, visitInParallel } from '../language/visitor.mjs';
4
6
  import { assertValidSchema } from '../type/validate.mjs';
5
7
  import { TypeInfo, visitWithTypeInfo } from '../utilities/TypeInfo.mjs';
@@ -7,7 +9,12 @@ import { specifiedRules, specifiedSDLRules } from './specifiedRules.mjs';
7
9
  import {
8
10
  SDLValidationContext,
9
11
  ValidationContext,
10
- } from './ValidationContext.mjs';
12
+ } from './ValidationContext.mjs'; // Per the specification, descriptions must not affect validation.
13
+ // See https://spec.graphql.org/draft/#sec-Descriptions
14
+
15
+ const QueryDocumentKeysToValidate = mapValue(QueryDocumentKeys, (keys) =>
16
+ keys.filter((key) => key !== 'description'),
17
+ );
11
18
  /**
12
19
  * Implements the "Validation" section of the spec.
13
20
  *
@@ -73,7 +80,11 @@ export function validate(
73
80
  const visitor = visitInParallel(rules.map((rule) => rule(context))); // Visit the whole document with each instance of all provided rules.
74
81
 
75
82
  try {
76
- visit(documentAST, visitWithTypeInfo(typeInfo, visitor));
83
+ visit(
84
+ documentAST,
85
+ visitWithTypeInfo(typeInfo, visitor),
86
+ QueryDocumentKeysToValidate,
87
+ );
77
88
  } catch (e) {
78
89
  if (e !== abortObj) {
79
90
  throw e;
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.12.0';
13
+ const version = '16.13.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.12.0';
18
18
  exports.version = version;
19
19
  const versionInfo = Object.freeze({
20
20
  major: 16,
21
- minor: 12,
21
+ minor: 13,
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.12.0';
7
+ export const version = '16.13.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: 12,
14
+ minor: 13,
15
15
  patch: 0,
16
16
  preReleaseTag: null,
17
17
  });