graphql 16.0.1 → 16.3.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.
Files changed (177) hide show
  1. package/README.md +4 -4
  2. package/error/GraphQLError.d.ts +17 -1
  3. package/error/GraphQLError.js +28 -10
  4. package/error/GraphQLError.mjs +28 -19
  5. package/error/locatedError.js +2 -8
  6. package/error/locatedError.mjs +2 -6
  7. package/execution/collectFields.d.ts +8 -8
  8. package/execution/collectFields.js +8 -8
  9. package/execution/collectFields.mjs +7 -7
  10. package/execution/execute.d.ts +5 -5
  11. package/execution/execute.js +28 -17
  12. package/execution/execute.mjs +30 -19
  13. package/execution/index.d.ts +1 -1
  14. package/execution/index.js +6 -0
  15. package/execution/index.mjs +1 -1
  16. package/execution/mapAsyncIterator.js +3 -1
  17. package/execution/mapAsyncIterator.mjs +3 -1
  18. package/execution/subscribe.d.ts +1 -1
  19. package/execution/subscribe.js +10 -2
  20. package/execution/subscribe.mjs +8 -1
  21. package/execution/values.d.ts +3 -5
  22. package/execution/values.js +7 -8
  23. package/execution/values.mjs +5 -6
  24. package/graphql.js +12 -4
  25. package/graphql.mjs +8 -1
  26. package/index.d.ts +7 -61
  27. package/index.js +30 -0
  28. package/index.mjs +62 -111
  29. package/jsutils/devAssert.js +1 -1
  30. package/jsutils/devAssert.mjs +1 -1
  31. package/jsutils/instanceOf.js +3 -1
  32. package/jsutils/instanceOf.mjs +3 -1
  33. package/jsutils/invariant.js +1 -1
  34. package/jsutils/invariant.mjs +1 -1
  35. package/jsutils/mapValue.js +2 -2
  36. package/jsutils/mapValue.mjs +2 -2
  37. package/jsutils/promiseReduce.mjs +1 -1
  38. package/jsutils/toError.d.ts +4 -0
  39. package/jsutils/toError.js +25 -0
  40. package/jsutils/toError.mjs +18 -0
  41. package/language/blockString.d.ts +7 -3
  42. package/language/blockString.js +121 -64
  43. package/language/blockString.mjs +111 -62
  44. package/language/characterClasses.d.ts +9 -0
  45. package/language/characterClasses.js +13 -0
  46. package/language/characterClasses.mjs +12 -0
  47. package/language/index.d.ts +0 -1
  48. package/language/lexer.d.ts +1 -1
  49. package/language/lexer.js +23 -15
  50. package/language/lexer.mjs +23 -15
  51. package/language/parser.d.ts +40 -40
  52. package/language/parser.js +9 -8
  53. package/language/parser.mjs +7 -6
  54. package/language/predicates.d.ts +4 -4
  55. package/language/printLocation.d.ts +1 -1
  56. package/language/printLocation.mjs +1 -1
  57. package/language/printer.js +5 -3
  58. package/language/printer.mjs +4 -2
  59. package/language/source.js +2 -2
  60. package/language/source.mjs +1 -1
  61. package/language/visitor.js +12 -13
  62. package/language/visitor.mjs +11 -12
  63. package/package.json +4 -1
  64. package/type/assertName.mjs +1 -1
  65. package/type/definition.d.ts +18 -14
  66. package/type/definition.js +13 -11
  67. package/type/definition.mjs +10 -16
  68. package/type/directives.d.ts +1 -1
  69. package/type/directives.js +9 -9
  70. package/type/directives.mjs +7 -7
  71. package/type/index.d.ts +5 -27
  72. package/type/index.js +24 -0
  73. package/type/index.mjs +26 -40
  74. package/type/introspection.d.ts +2 -2
  75. package/type/introspection.js +12 -8
  76. package/type/introspection.mjs +16 -12
  77. package/type/scalars.d.ts +10 -0
  78. package/type/scalars.js +20 -12
  79. package/type/scalars.mjs +17 -12
  80. package/type/schema.d.ts +4 -4
  81. package/type/schema.js +11 -9
  82. package/type/schema.mjs +11 -10
  83. package/type/validate.js +39 -30
  84. package/type/validate.mjs +42 -33
  85. package/utilities/TypeInfo.d.ts +9 -9
  86. package/utilities/TypeInfo.js +6 -2
  87. package/utilities/TypeInfo.mjs +11 -7
  88. package/utilities/assertValidName.js +3 -2
  89. package/utilities/assertValidName.mjs +3 -2
  90. package/utilities/astFromValue.js +8 -6
  91. package/utilities/astFromValue.mjs +7 -5
  92. package/utilities/buildASTSchema.d.ts +1 -1
  93. package/utilities/buildASTSchema.js +2 -2
  94. package/utilities/buildASTSchema.mjs +2 -2
  95. package/utilities/buildClientSchema.js +9 -7
  96. package/utilities/buildClientSchema.mjs +17 -15
  97. package/utilities/coerceInputValue.js +9 -7
  98. package/utilities/coerceInputValue.mjs +9 -7
  99. package/utilities/extendSchema.d.ts +1 -1
  100. package/utilities/extendSchema.js +50 -42
  101. package/utilities/extendSchema.mjs +71 -60
  102. package/utilities/findBreakingChanges.js +9 -22
  103. package/utilities/findBreakingChanges.mjs +13 -22
  104. package/utilities/getIntrospectionQuery.d.ts +4 -0
  105. package/utilities/getIntrospectionQuery.js +4 -0
  106. package/utilities/getIntrospectionQuery.mjs +4 -0
  107. package/utilities/getOperationRootType.d.ts +1 -1
  108. package/utilities/index.d.ts +0 -25
  109. package/utilities/index.mjs +21 -44
  110. package/utilities/introspectionFromSchema.d.ts +1 -1
  111. package/utilities/lexicographicSortSchema.js +8 -7
  112. package/utilities/lexicographicSortSchema.mjs +16 -15
  113. package/utilities/printSchema.d.ts +1 -1
  114. package/utilities/printSchema.js +14 -12
  115. package/utilities/printSchema.mjs +20 -15
  116. package/utilities/separateOperations.js +2 -0
  117. package/utilities/separateOperations.mjs +2 -0
  118. package/utilities/sortValueNode.d.ts +9 -0
  119. package/utilities/sortValueNode.js +47 -0
  120. package/utilities/sortValueNode.mjs +39 -0
  121. package/utilities/stripIgnoredCharacters.js +7 -23
  122. package/utilities/stripIgnoredCharacters.mjs +6 -25
  123. package/utilities/typeComparators.d.ts +1 -1
  124. package/utilities/typeComparators.mjs +3 -3
  125. package/utilities/typeFromAST.d.ts +4 -4
  126. package/utilities/typeFromAST.js +13 -24
  127. package/utilities/typeFromAST.mjs +12 -25
  128. package/utilities/valueFromAST.d.ts +1 -1
  129. package/utilities/valueFromAST.js +6 -4
  130. package/utilities/valueFromAST.mjs +7 -5
  131. package/utilities/valueFromASTUntyped.d.ts +1 -1
  132. package/utilities/valueFromASTUntyped.js +1 -11
  133. package/utilities/valueFromASTUntyped.mjs +2 -6
  134. package/validation/ValidationContext.d.ts +10 -10
  135. package/validation/index.d.ts +0 -29
  136. package/validation/index.mjs +29 -58
  137. package/validation/rules/FieldsOnCorrectTypeRule.js +2 -2
  138. package/validation/rules/FieldsOnCorrectTypeRule.mjs +3 -3
  139. package/validation/rules/KnownArgumentNamesRule.d.ts +1 -1
  140. package/validation/rules/KnownArgumentNamesRule.js +3 -1
  141. package/validation/rules/KnownArgumentNamesRule.mjs +3 -1
  142. package/validation/rules/KnownDirectivesRule.d.ts +1 -1
  143. package/validation/rules/KnownDirectivesRule.js +13 -9
  144. package/validation/rules/KnownDirectivesRule.mjs +8 -4
  145. package/validation/rules/KnownTypeNamesRule.d.ts +1 -1
  146. package/validation/rules/KnownTypeNamesRule.js +2 -2
  147. package/validation/rules/KnownTypeNamesRule.mjs +1 -1
  148. package/validation/rules/OverlappingFieldsCanBeMergedRule.js +41 -36
  149. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +41 -39
  150. package/validation/rules/PossibleFragmentSpreadsRule.js +2 -2
  151. package/validation/rules/PossibleFragmentSpreadsRule.mjs +1 -1
  152. package/validation/rules/PossibleTypeExtensionsRule.js +16 -10
  153. package/validation/rules/PossibleTypeExtensionsRule.mjs +15 -9
  154. package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +1 -1
  155. package/validation/rules/ProvidedRequiredArgumentsRule.js +10 -5
  156. package/validation/rules/ProvidedRequiredArgumentsRule.mjs +9 -4
  157. package/validation/rules/UniqueArgumentDefinitionNamesRule.js +9 -3
  158. package/validation/rules/UniqueArgumentDefinitionNamesRule.mjs +9 -3
  159. package/validation/rules/UniqueArgumentNamesRule.js +3 -1
  160. package/validation/rules/UniqueArgumentNamesRule.mjs +3 -1
  161. package/validation/rules/UniqueEnumValueNamesRule.js +3 -1
  162. package/validation/rules/UniqueEnumValueNamesRule.mjs +3 -1
  163. package/validation/rules/UniqueFieldDefinitionNamesRule.js +3 -1
  164. package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +5 -3
  165. package/validation/rules/UniqueOperationTypesRule.js +3 -1
  166. package/validation/rules/UniqueOperationTypesRule.mjs +3 -1
  167. package/validation/rules/UniqueVariableNamesRule.js +3 -1
  168. package/validation/rules/UniqueVariableNamesRule.mjs +3 -1
  169. package/validation/rules/ValuesOfCorrectTypeRule.js +2 -2
  170. package/validation/rules/ValuesOfCorrectTypeRule.mjs +5 -5
  171. package/validation/rules/VariablesInAllowedPositionRule.js +2 -2
  172. package/validation/rules/VariablesInAllowedPositionRule.mjs +1 -1
  173. package/validation/specifiedRules.d.ts +1 -1
  174. package/validation/specifiedRules.js +47 -47
  175. package/validation/specifiedRules.mjs +41 -41
  176. package/version.js +3 -3
  177. package/version.mjs +3 -3
package/README.md CHANGED
@@ -71,9 +71,9 @@ or an array of promises. A more complex example is included in the top-level [te
71
71
  Then, serve the result of a query against that type schema.
72
72
 
73
73
  ```js
74
- var query = '{ hello }';
74
+ var source = '{ hello }';
75
75
 
76
- graphql(schema, query).then((result) => {
76
+ graphql({ schema, source }).then((result) => {
77
77
  // Prints
78
78
  // {
79
79
  // data: { hello: "world" }
@@ -87,9 +87,9 @@ first ensure the query is syntactically and semantically valid before executing
87
87
  it, reporting errors otherwise.
88
88
 
89
89
  ```js
90
- var query = '{ BoyHowdy }';
90
+ var source = '{ BoyHowdy }';
91
91
 
92
- graphql(schema, query).then((result) => {
92
+ graphql({ schema, source }).then((result) => {
93
93
  // Prints
94
94
  // {
95
95
  // errors: [
@@ -1,7 +1,7 @@
1
1
  import type { Maybe } from '../jsutils/Maybe';
2
2
  import type { ASTNode } from '../language/ast';
3
- import type { Source } from '../language/source';
4
3
  import type { SourceLocation } from '../language/location';
4
+ import type { Source } from '../language/source';
5
5
  /**
6
6
  * Custom extensions
7
7
  *
@@ -14,6 +14,18 @@ import type { SourceLocation } from '../language/location';
14
14
  export interface GraphQLErrorExtensions {
15
15
  [attributeName: string]: unknown;
16
16
  }
17
+ export interface GraphQLErrorArgs {
18
+ nodes?: ReadonlyArray<ASTNode> | ASTNode | null;
19
+ source?: Maybe<Source>;
20
+ positions?: Maybe<ReadonlyArray<number>>;
21
+ path?: Maybe<ReadonlyArray<string | number>>;
22
+ originalError?: Maybe<
23
+ Error & {
24
+ readonly extensions?: unknown;
25
+ }
26
+ >;
27
+ extensions?: Maybe<GraphQLErrorExtensions>;
28
+ }
17
29
  /**
18
30
  * A GraphQLError describes an Error found during the parse, validate, or
19
31
  * execute phases of performing a GraphQL operation. In addition to a message
@@ -63,6 +75,9 @@ export declare class GraphQLError extends Error {
63
75
  * Extension fields to add to the formatted error.
64
76
  */
65
77
  readonly extensions: GraphQLErrorExtensions;
78
+ /**
79
+ * @deprecated Please use the `GraphQLErrorArgs` constructor overload instead.
80
+ */
66
81
  constructor(
67
82
  message: string,
68
83
  nodes?: ReadonlyArray<ASTNode> | ASTNode | null,
@@ -76,6 +91,7 @@ export declare class GraphQLError extends Error {
76
91
  >,
77
92
  extensions?: Maybe<GraphQLErrorExtensions>,
78
93
  );
94
+ constructor(message: string, args?: GraphQLErrorArgs);
79
95
  get [Symbol.toStringTag](): string;
80
96
  toString(): string;
81
97
  toJSON(): GraphQLFormattedError;
@@ -13,12 +13,29 @@ var _location = require('../language/location.js');
13
13
 
14
14
  var _printLocation = require('../language/printLocation.js');
15
15
 
16
+ function toNormalizedArgs(args) {
17
+ const firstArg = args[0];
18
+
19
+ if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
20
+ return {
21
+ nodes: firstArg,
22
+ source: args[1],
23
+ positions: args[2],
24
+ path: args[3],
25
+ originalError: args[4],
26
+ extensions: args[5],
27
+ };
28
+ }
29
+
30
+ return firstArg;
31
+ }
16
32
  /**
17
33
  * A GraphQLError describes an Error found during the parse, validate, or
18
34
  * execute phases of performing a GraphQL operation. In addition to a message
19
35
  * and stack trace, it also includes information about the locations in a
20
36
  * GraphQL document and/or execution result that correspond to the Error.
21
37
  */
38
+
22
39
  class GraphQLError extends Error {
23
40
  /**
24
41
  * An array of `{ line, column }` locations within the source GraphQL document
@@ -61,17 +78,15 @@ class GraphQLError extends Error {
61
78
  /**
62
79
  * Extension fields to add to the formatted error.
63
80
  */
64
- constructor(
65
- message,
66
- nodes,
67
- source,
68
- positions,
69
- path,
70
- originalError,
71
- extensions,
72
- ) {
81
+
82
+ /**
83
+ * @deprecated Please use the `GraphQLErrorArgs` constructor overload instead.
84
+ */
85
+ constructor(message, ...rawArgs) {
73
86
  var _this$nodes, _nodeLocations$, _ref;
74
87
 
88
+ const { nodes, source, positions, path, originalError, extensions } =
89
+ toNormalizedArgs(rawArgs);
75
90
  super(message);
76
91
  this.name = 'GraphQLError';
77
92
  this.path = path !== null && path !== void 0 ? path : undefined;
@@ -151,7 +166,9 @@ class GraphQLError extends Error {
151
166
  enumerable: false,
152
167
  },
153
168
  }); // Include (non-enumerable) stack trace.
154
- // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
169
+
170
+ /* c8 ignore start */
171
+ // FIXME: https://github.com/graphql/graphql-js/issues/2317
155
172
 
156
173
  if (
157
174
  originalError !== null &&
@@ -172,6 +189,7 @@ class GraphQLError extends Error {
172
189
  configurable: true,
173
190
  });
174
191
  }
192
+ /* c8 ignore stop */
175
193
  }
176
194
 
177
195
  get [Symbol.toStringTag]() {
@@ -4,22 +4,30 @@ import {
4
4
  printLocation,
5
5
  printSourceLocation,
6
6
  } from '../language/printLocation.mjs';
7
- /**
8
- * Custom extensions
9
- *
10
- * @remarks
11
- * Use a unique identifier name for your extension, for example the name of
12
- * your library or project. Do not use a shortened identifier as this increases
13
- * the risk of conflicts. We recommend you add at most one extension field,
14
- * an object which can contain all the values you need.
15
- */
16
7
 
8
+ function toNormalizedArgs(args) {
9
+ const firstArg = args[0];
10
+
11
+ if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
12
+ return {
13
+ nodes: firstArg,
14
+ source: args[1],
15
+ positions: args[2],
16
+ path: args[3],
17
+ originalError: args[4],
18
+ extensions: args[5],
19
+ };
20
+ }
21
+
22
+ return firstArg;
23
+ }
17
24
  /**
18
25
  * A GraphQLError describes an Error found during the parse, validate, or
19
26
  * execute phases of performing a GraphQL operation. In addition to a message
20
27
  * and stack trace, it also includes information about the locations in a
21
28
  * GraphQL document and/or execution result that correspond to the Error.
22
29
  */
30
+
23
31
  export class GraphQLError extends Error {
24
32
  /**
25
33
  * An array of `{ line, column }` locations within the source GraphQL document
@@ -62,17 +70,15 @@ export class GraphQLError extends Error {
62
70
  /**
63
71
  * Extension fields to add to the formatted error.
64
72
  */
65
- constructor(
66
- message,
67
- nodes,
68
- source,
69
- positions,
70
- path,
71
- originalError,
72
- extensions,
73
- ) {
73
+
74
+ /**
75
+ * @deprecated Please use the `GraphQLErrorArgs` constructor overload instead.
76
+ */
77
+ constructor(message, ...rawArgs) {
74
78
  var _this$nodes, _nodeLocations$, _ref;
75
79
 
80
+ const { nodes, source, positions, path, originalError, extensions } =
81
+ toNormalizedArgs(rawArgs);
76
82
  super(message);
77
83
  this.name = 'GraphQLError';
78
84
  this.path = path !== null && path !== void 0 ? path : undefined;
@@ -150,7 +156,9 @@ export class GraphQLError extends Error {
150
156
  enumerable: false,
151
157
  },
152
158
  }); // Include (non-enumerable) stack trace.
153
- // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
159
+
160
+ /* c8 ignore start */
161
+ // FIXME: https://github.com/graphql/graphql-js/issues/2317
154
162
 
155
163
  if (
156
164
  originalError !== null &&
@@ -171,6 +179,7 @@ export class GraphQLError extends Error {
171
179
  configurable: true,
172
180
  });
173
181
  }
182
+ /* c8 ignore stop */
174
183
  }
175
184
 
176
185
  get [Symbol.toStringTag]() {
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', {
5
5
  });
6
6
  exports.locatedError = locatedError;
7
7
 
8
- var _inspect = require('../jsutils/inspect.js');
8
+ var _toError = require('../jsutils/toError.js');
9
9
 
10
10
  var _GraphQLError = require('./GraphQLError.js');
11
11
 
@@ -17,13 +17,7 @@ var _GraphQLError = require('./GraphQLError.js');
17
17
  function locatedError(rawOriginalError, nodes, path) {
18
18
  var _nodes;
19
19
 
20
- // Sometimes a non-error is thrown, wrap it as an Error instance to ensure a consistent Error interface.
21
- const originalError =
22
- rawOriginalError instanceof Error
23
- ? rawOriginalError
24
- : new Error(
25
- 'Unexpected error value: ' + (0, _inspect.inspect)(rawOriginalError),
26
- ); // Note: this uses a brand-check to support GraphQL errors originating from other contexts.
20
+ const originalError = (0, _toError.toError)(rawOriginalError); // Note: this uses a brand-check to support GraphQL errors originating from other contexts.
27
21
 
28
22
  if (isLocatedGraphQLError(originalError)) {
29
23
  return originalError;
@@ -1,4 +1,4 @@
1
- import { inspect } from '../jsutils/inspect.mjs';
1
+ import { toError } from '../jsutils/toError.mjs';
2
2
  import { GraphQLError } from './GraphQLError.mjs';
3
3
  /**
4
4
  * Given an arbitrary value, presumably thrown while attempting to execute a
@@ -9,11 +9,7 @@ import { GraphQLError } from './GraphQLError.mjs';
9
9
  export function locatedError(rawOriginalError, nodes, path) {
10
10
  var _nodes;
11
11
 
12
- // Sometimes a non-error is thrown, wrap it as an Error instance to ensure a consistent Error interface.
13
- const originalError =
14
- rawOriginalError instanceof Error
15
- ? rawOriginalError
16
- : new Error('Unexpected error value: ' + inspect(rawOriginalError)); // Note: this uses a brand-check to support GraphQL errors originating from other contexts.
12
+ const originalError = toError(rawOriginalError); // Note: this uses a brand-check to support GraphQL errors originating from other contexts.
17
13
 
18
14
  if (isLocatedGraphQLError(originalError)) {
19
15
  return originalError;
@@ -1,17 +1,17 @@
1
1
  import type { ObjMap } from '../jsutils/ObjMap';
2
2
  import type {
3
- SelectionSetNode,
4
3
  FieldNode,
5
4
  FragmentDefinitionNode,
5
+ SelectionSetNode,
6
6
  } from '../language/ast';
7
- import type { GraphQLSchema } from '../type/schema';
8
7
  import type { GraphQLObjectType } from '../type/definition';
8
+ import type { GraphQLSchema } from '../type/schema';
9
9
  /**
10
- * Given a selectionSet, collect all of the fields and returns it at the end.
10
+ * Given a selectionSet, collects all of the fields and returns them.
11
11
  *
12
- * CollectFields requires the "runtime type" of an object. For a field which
12
+ * CollectFields requires the "runtime type" of an object. For a field that
13
13
  * returns an Interface or Union type, the "runtime type" will be the actual
14
- * Object type returned by that field.
14
+ * object type returned by that field.
15
15
  *
16
16
  * @internal
17
17
  */
@@ -26,11 +26,11 @@ export declare function collectFields(
26
26
  ): Map<string, ReadonlyArray<FieldNode>>;
27
27
  /**
28
28
  * Given an array of field nodes, collects all of the subfields of the passed
29
- * in fields, and returns it at the end.
29
+ * in fields, and returns them at the end.
30
30
  *
31
- * CollectFields requires the "return type" of an object. For a field which
31
+ * CollectSubFields requires the "return type" of an object. For a field that
32
32
  * returns an Interface or Union type, the "return type" will be the actual
33
- * Object type returned by that field.
33
+ * object type returned by that field.
34
34
  *
35
35
  * @internal
36
36
  */
@@ -8,20 +8,20 @@ exports.collectSubfields = collectSubfields;
8
8
 
9
9
  var _kinds = require('../language/kinds.js');
10
10
 
11
- var _directives = require('../type/directives.js');
12
-
13
11
  var _definition = require('../type/definition.js');
14
12
 
13
+ var _directives = require('../type/directives.js');
14
+
15
15
  var _typeFromAST = require('../utilities/typeFromAST.js');
16
16
 
17
17
  var _values = require('./values.js');
18
18
 
19
19
  /**
20
- * Given a selectionSet, collect all of the fields and returns it at the end.
20
+ * Given a selectionSet, collects all of the fields and returns them.
21
21
  *
22
- * CollectFields requires the "runtime type" of an object. For a field which
22
+ * CollectFields requires the "runtime type" of an object. For a field that
23
23
  * returns an Interface or Union type, the "runtime type" will be the actual
24
- * Object type returned by that field.
24
+ * object type returned by that field.
25
25
  *
26
26
  * @internal
27
27
  */
@@ -46,11 +46,11 @@ function collectFields(
46
46
  }
47
47
  /**
48
48
  * Given an array of field nodes, collects all of the subfields of the passed
49
- * in fields, and returns it at the end.
49
+ * in fields, and returns them at the end.
50
50
  *
51
- * CollectFields requires the "return type" of an object. For a field which
51
+ * CollectSubFields requires the "return type" of an object. For a field that
52
52
  * returns an Interface or Union type, the "return type" will be the actual
53
- * Object type returned by that field.
53
+ * object type returned by that field.
54
54
  *
55
55
  * @internal
56
56
  */
@@ -1,17 +1,17 @@
1
1
  import { Kind } from '../language/kinds.mjs';
2
+ import { isAbstractType } from '../type/definition.mjs';
2
3
  import {
3
4
  GraphQLIncludeDirective,
4
5
  GraphQLSkipDirective,
5
6
  } from '../type/directives.mjs';
6
- import { isAbstractType } from '../type/definition.mjs';
7
7
  import { typeFromAST } from '../utilities/typeFromAST.mjs';
8
8
  import { getDirectiveValues } from './values.mjs';
9
9
  /**
10
- * Given a selectionSet, collect all of the fields and returns it at the end.
10
+ * Given a selectionSet, collects all of the fields and returns them.
11
11
  *
12
- * CollectFields requires the "runtime type" of an object. For a field which
12
+ * CollectFields requires the "runtime type" of an object. For a field that
13
13
  * returns an Interface or Union type, the "runtime type" will be the actual
14
- * Object type returned by that field.
14
+ * object type returned by that field.
15
15
  *
16
16
  * @internal
17
17
  */
@@ -37,11 +37,11 @@ export function collectFields(
37
37
  }
38
38
  /**
39
39
  * Given an array of field nodes, collects all of the subfields of the passed
40
- * in fields, and returns it at the end.
40
+ * in fields, and returns them at the end.
41
41
  *
42
- * CollectFields requires the "return type" of an object. For a field which
42
+ * CollectSubFields requires the "return type" of an object. For a field that
43
43
  * returns an Interface or Union type, the "return type" will be the actual
44
- * Object type returned by that field.
44
+ * object type returned by that field.
45
45
  *
46
46
  * @internal
47
47
  */
@@ -1,23 +1,23 @@
1
- import type { Path } from '../jsutils/Path';
1
+ import type { Maybe } from '../jsutils/Maybe';
2
2
  import type { ObjMap } from '../jsutils/ObjMap';
3
+ import type { Path } from '../jsutils/Path';
3
4
  import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
4
- import type { Maybe } from '../jsutils/Maybe';
5
5
  import type { GraphQLFormattedError } from '../error/GraphQLError';
6
6
  import { GraphQLError } from '../error/GraphQLError';
7
7
  import type {
8
8
  DocumentNode,
9
- OperationDefinitionNode,
10
9
  FieldNode,
11
10
  FragmentDefinitionNode,
11
+ OperationDefinitionNode,
12
12
  } from '../language/ast';
13
- import type { GraphQLSchema } from '../type/schema';
14
13
  import type {
15
- GraphQLObjectType,
16
14
  GraphQLField,
17
15
  GraphQLFieldResolver,
16
+ GraphQLObjectType,
18
17
  GraphQLResolveInfo,
19
18
  GraphQLTypeResolver,
20
19
  } from '../type/definition';
20
+ import type { GraphQLSchema } from '../type/schema';
21
21
  /**
22
22
  * Terminology
23
23
  *
@@ -11,25 +11,25 @@ exports.execute = execute;
11
11
  exports.executeSync = executeSync;
12
12
  exports.getFieldDef = getFieldDef;
13
13
 
14
- var _inspect = require('../jsutils/inspect.js');
14
+ var _devAssert = require('../jsutils/devAssert.js');
15
15
 
16
- var _memoize = require('../jsutils/memoize3.js');
16
+ var _inspect = require('../jsutils/inspect.js');
17
17
 
18
18
  var _invariant = require('../jsutils/invariant.js');
19
19
 
20
- var _devAssert = require('../jsutils/devAssert.js');
21
-
22
- var _isPromise = require('../jsutils/isPromise.js');
20
+ var _isIterableObject = require('../jsutils/isIterableObject.js');
23
21
 
24
22
  var _isObjectLike = require('../jsutils/isObjectLike.js');
25
23
 
26
- var _promiseReduce = require('../jsutils/promiseReduce.js');
24
+ var _isPromise = require('../jsutils/isPromise.js');
27
25
 
28
- var _promiseForObject = require('../jsutils/promiseForObject.js');
26
+ var _memoize = require('../jsutils/memoize3.js');
29
27
 
30
28
  var _Path = require('../jsutils/Path.js');
31
29
 
32
- var _isIterableObject = require('../jsutils/isIterableObject.js');
30
+ var _promiseForObject = require('../jsutils/promiseForObject.js');
31
+
32
+ var _promiseReduce = require('../jsutils/promiseReduce.js');
33
33
 
34
34
  var _GraphQLError = require('../error/GraphQLError.js');
35
35
 
@@ -39,16 +39,16 @@ var _ast = require('../language/ast.js');
39
39
 
40
40
  var _kinds = require('../language/kinds.js');
41
41
 
42
- var _validate = require('../type/validate.js');
42
+ var _definition = require('../type/definition.js');
43
43
 
44
44
  var _introspection = require('../type/introspection.js');
45
45
 
46
- var _definition = require('../type/definition.js');
47
-
48
- var _values = require('./values.js');
46
+ var _validate = require('../type/validate.js');
49
47
 
50
48
  var _collectFields = require('./collectFields.js');
51
49
 
50
+ var _values = require('./values.js');
51
+
52
52
  /**
53
53
  * A memoized collection of relevant subfields with regard to the return
54
54
  * type. Memoizing ensures the subfields are not repeatedly calculated, which
@@ -102,6 +102,12 @@ const collectSubfields = (0, _memoize.memoize3)(
102
102
  * a GraphQLError will be thrown immediately explaining the invalid input.
103
103
  */
104
104
  function execute(args) {
105
+ // Temporary for v15 to v16 migration. Remove in v17
106
+ arguments.length < 2 ||
107
+ (0, _devAssert.devAssert)(
108
+ false,
109
+ 'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.',
110
+ );
105
111
  const { schema, document, variableValues, rootValue } = args; // If arguments are missing or incorrect, throw an error.
106
112
 
107
113
  assertValidExecutionArguments(schema, document, variableValues); // If a valid execution context cannot be created due to incorrect arguments,
@@ -247,6 +253,8 @@ function buildExecutionContext(args) {
247
253
  case _kinds.Kind.FRAGMENT_DEFINITION:
248
254
  fragments[definition.name.value] = definition;
249
255
  break;
256
+
257
+ default: // ignore non-executable definitions
250
258
  }
251
259
  }
252
260
 
@@ -260,7 +268,9 @@ function buildExecutionContext(args) {
260
268
  }
261
269
 
262
270
  return [new _GraphQLError.GraphQLError('Must provide an operation.')];
263
- } // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
271
+ } // FIXME: https://github.com/graphql/graphql-js/issues/2203
272
+
273
+ /* c8 ignore next */
264
274
 
265
275
  const variableDefinitions =
266
276
  (_operation$variableDe = operation.variableDefinitions) !== null &&
@@ -424,7 +434,7 @@ function executeFields(exeContext, parentType, sourceValue, path, fields) {
424
434
  return (0, _promiseForObject.promiseForObject)(results);
425
435
  }
426
436
  /**
427
- * Implements the "Executing field" section of the spec
437
+ * Implements the "Executing fields" section of the spec
428
438
  * In particular, this function figures out the value that the field returns by
429
439
  * calling its resolve function, then calls completeValue to complete promises,
430
440
  * serialize scalars, or execute the sub-selection-set for objects.
@@ -541,7 +551,7 @@ function handleFieldError(error, returnType, exeContext) {
541
551
  }
542
552
  /**
543
553
  * Implements the instructions for completeValue as defined in the
544
- * "Field entries" section of the spec.
554
+ * "Value Completion" section of the spec.
545
555
  *
546
556
  * If the field type is Non-Null, then this recursively completes the value
547
557
  * for the inner type. It throws a field error if that completion returns null,
@@ -618,7 +628,6 @@ function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
618
628
  result,
619
629
  );
620
630
  } // If field type is Object, execute and complete all sub-selections.
621
- // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2618')
622
631
 
623
632
  if ((0, _definition.isObjectType)(returnType)) {
624
633
  return completeObjectValue(
@@ -629,7 +638,9 @@ function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
629
638
  path,
630
639
  result,
631
640
  );
632
- } // istanbul ignore next (Not reachable. All possible output types have been considered)
641
+ }
642
+ /* c8 ignore next 6 */
643
+ // Not reachable, all possible output types have been considered.
633
644
 
634
645
  false ||
635
646
  (0, _invariant.invariant)(
@@ -1,35 +1,35 @@
1
+ import { devAssert } from '../jsutils/devAssert.mjs';
1
2
  import { inspect } from '../jsutils/inspect.mjs';
2
- import { memoize3 } from '../jsutils/memoize3.mjs';
3
3
  import { invariant } from '../jsutils/invariant.mjs';
4
- import { devAssert } from '../jsutils/devAssert.mjs';
5
- import { isPromise } from '../jsutils/isPromise.mjs';
4
+ import { isIterableObject } from '../jsutils/isIterableObject.mjs';
6
5
  import { isObjectLike } from '../jsutils/isObjectLike.mjs';
7
- import { promiseReduce } from '../jsutils/promiseReduce.mjs';
8
- import { promiseForObject } from '../jsutils/promiseForObject.mjs';
6
+ import { isPromise } from '../jsutils/isPromise.mjs';
7
+ import { memoize3 } from '../jsutils/memoize3.mjs';
9
8
  import { addPath, pathToArray } from '../jsutils/Path.mjs';
10
- import { isIterableObject } from '../jsutils/isIterableObject.mjs';
9
+ import { promiseForObject } from '../jsutils/promiseForObject.mjs';
10
+ import { promiseReduce } from '../jsutils/promiseReduce.mjs';
11
11
  import { GraphQLError } from '../error/GraphQLError.mjs';
12
12
  import { locatedError } from '../error/locatedError.mjs';
13
13
  import { OperationTypeNode } from '../language/ast.mjs';
14
14
  import { Kind } from '../language/kinds.mjs';
15
- import { assertValidSchema } from '../type/validate.mjs';
16
- import {
17
- SchemaMetaFieldDef,
18
- TypeMetaFieldDef,
19
- TypeNameMetaFieldDef,
20
- } from '../type/introspection.mjs';
21
15
  import {
22
- isObjectType,
23
16
  isAbstractType,
24
17
  isLeafType,
25
18
  isListType,
26
19
  isNonNullType,
20
+ isObjectType,
27
21
  } from '../type/definition.mjs';
28
- import { getVariableValues, getArgumentValues } from './values.mjs';
22
+ import {
23
+ SchemaMetaFieldDef,
24
+ TypeMetaFieldDef,
25
+ TypeNameMetaFieldDef,
26
+ } from '../type/introspection.mjs';
27
+ import { assertValidSchema } from '../type/validate.mjs';
29
28
  import {
30
29
  collectFields,
31
30
  collectSubfields as _collectSubfields,
32
31
  } from './collectFields.mjs';
32
+ import { getArgumentValues, getVariableValues } from './values.mjs';
33
33
  /**
34
34
  * A memoized collection of relevant subfields with regard to the return
35
35
  * type. Memoizing ensures the subfields are not repeatedly calculated, which
@@ -83,6 +83,12 @@ const collectSubfields = memoize3((exeContext, returnType, fieldNodes) =>
83
83
  * a GraphQLError will be thrown immediately explaining the invalid input.
84
84
  */
85
85
  export function execute(args) {
86
+ // Temporary for v15 to v16 migration. Remove in v17
87
+ arguments.length < 2 ||
88
+ devAssert(
89
+ false,
90
+ 'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.',
91
+ );
86
92
  const { schema, document, variableValues, rootValue } = args; // If arguments are missing or incorrect, throw an error.
87
93
 
88
94
  assertValidExecutionArguments(schema, document, variableValues); // If a valid execution context cannot be created due to incorrect arguments,
@@ -232,6 +238,8 @@ export function buildExecutionContext(args) {
232
238
  case Kind.FRAGMENT_DEFINITION:
233
239
  fragments[definition.name.value] = definition;
234
240
  break;
241
+
242
+ default: // ignore non-executable definitions
235
243
  }
236
244
  }
237
245
 
@@ -241,7 +249,9 @@ export function buildExecutionContext(args) {
241
249
  }
242
250
 
243
251
  return [new GraphQLError('Must provide an operation.')];
244
- } // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
252
+ } // FIXME: https://github.com/graphql/graphql-js/issues/2203
253
+
254
+ /* c8 ignore next */
245
255
 
246
256
  const variableDefinitions =
247
257
  (_operation$variableDe = operation.variableDefinitions) !== null &&
@@ -405,7 +415,7 @@ function executeFields(exeContext, parentType, sourceValue, path, fields) {
405
415
  return promiseForObject(results);
406
416
  }
407
417
  /**
408
- * Implements the "Executing field" section of the spec
418
+ * Implements the "Executing fields" section of the spec
409
419
  * In particular, this function figures out the value that the field returns by
410
420
  * calling its resolve function, then calls completeValue to complete promises,
411
421
  * serialize scalars, or execute the sub-selection-set for objects.
@@ -520,7 +530,7 @@ function handleFieldError(error, returnType, exeContext) {
520
530
  }
521
531
  /**
522
532
  * Implements the instructions for completeValue as defined in the
523
- * "Field entries" section of the spec.
533
+ * "Value Completion" section of the spec.
524
534
  *
525
535
  * If the field type is Non-Null, then this recursively completes the value
526
536
  * for the inner type. It throws a field error if that completion returns null,
@@ -597,7 +607,6 @@ function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
597
607
  result,
598
608
  );
599
609
  } // If field type is Object, execute and complete all sub-selections.
600
- // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2618')
601
610
 
602
611
  if (isObjectType(returnType)) {
603
612
  return completeObjectValue(
@@ -608,7 +617,9 @@ function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
608
617
  path,
609
618
  result,
610
619
  );
611
- } // istanbul ignore next (Not reachable. All possible output types have been considered)
620
+ }
621
+ /* c8 ignore next 6 */
622
+ // Not reachable, all possible output types have been considered.
612
623
 
613
624
  false ||
614
625
  invariant(
@@ -11,4 +11,4 @@ export type {
11
11
  FormattedExecutionResult,
12
12
  } from './execute';
13
13
  export { subscribe, createSourceEventStream } from './subscribe';
14
- export { getDirectiveValues } from './values';
14
+ export { getVariableValues, getDirectiveValues } from './values';