graphql 16.14.1 → 16.15.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 (240) hide show
  1. package/error/GraphQLError.d.ts +5 -1
  2. package/error/GraphQLError.js +12 -7
  3. package/error/GraphQLError.mjs +13 -6
  4. package/error/locatedError.d.ts +6 -4
  5. package/error/locatedError.js +6 -4
  6. package/error/locatedError.mjs +6 -4
  7. package/execution/collectFields.d.ts +1 -0
  8. package/execution/collectFields.js +9 -0
  9. package/execution/collectFields.mjs +9 -0
  10. package/execution/execute.d.ts +9 -10
  11. package/execution/execute.js +44 -29
  12. package/execution/execute.mjs +44 -29
  13. package/execution/mapAsyncIterator.js +12 -11
  14. package/execution/mapAsyncIterator.mjs +12 -11
  15. package/execution/subscribe.d.ts +5 -2
  16. package/execution/subscribe.js +5 -2
  17. package/execution/subscribe.mjs +5 -2
  18. package/execution/values.d.ts +43 -21
  19. package/execution/values.js +52 -24
  20. package/execution/values.mjs +51 -23
  21. package/graphql.d.ts +8 -14
  22. package/graphql.js +16 -15
  23. package/graphql.mjs +11 -15
  24. package/jsutils/SetMap.d.ts +14 -0
  25. package/jsutils/SetMap.js +48 -0
  26. package/jsutils/SetMap.mjs +39 -0
  27. package/jsutils/isIterableObject.d.ts +2 -0
  28. package/jsutils/isIterableObject.js +2 -0
  29. package/jsutils/isIterableObject.mjs +2 -0
  30. package/jsutils/keyMap.d.ts +2 -0
  31. package/jsutils/keyMap.js +2 -0
  32. package/jsutils/keyMap.mjs +2 -0
  33. package/jsutils/keyValMap.d.ts +3 -3
  34. package/jsutils/keyValMap.js +3 -3
  35. package/jsutils/keyValMap.mjs +3 -3
  36. package/language/ast.d.ts +2 -6
  37. package/language/ast.js +2 -6
  38. package/language/ast.mjs +2 -6
  39. package/language/lexer.d.ts +6 -0
  40. package/language/lexer.js +22 -0
  41. package/language/lexer.mjs +22 -0
  42. package/language/location.d.ts +8 -3
  43. package/language/location.js +57 -17
  44. package/language/location.mjs +56 -16
  45. package/language/parser.d.ts +27 -13
  46. package/language/parser.js +31 -9
  47. package/language/parser.mjs +31 -9
  48. package/language/predicates.d.ts +10 -3
  49. package/language/predicates.js +10 -3
  50. package/language/predicates.mjs +10 -3
  51. package/language/printLocation.d.ts +2 -6
  52. package/language/printLocation.js +2 -6
  53. package/language/printLocation.mjs +2 -6
  54. package/language/printer.d.ts +22 -3
  55. package/language/printer.js +394 -308
  56. package/language/printer.mjs +394 -308
  57. package/language/reducer.d.ts +32 -0
  58. package/language/reducer.js +95 -0
  59. package/language/reducer.mjs +86 -0
  60. package/language/source.d.ts +4 -5
  61. package/language/source.js +4 -5
  62. package/language/source.mjs +4 -5
  63. package/language/visitor.d.ts +16 -10
  64. package/language/visitor.js +15 -7
  65. package/language/visitor.mjs +15 -7
  66. package/package.json +1 -4
  67. package/type/definition.d.ts +190 -122
  68. package/type/definition.js +175 -102
  69. package/type/definition.mjs +174 -101
  70. package/type/directives.d.ts +14 -8
  71. package/type/directives.js +13 -7
  72. package/type/directives.mjs +13 -7
  73. package/type/scalars.js +8 -11
  74. package/type/scalars.mjs +1 -1
  75. package/type/schema.d.ts +38 -13
  76. package/type/schema.js +36 -11
  77. package/type/schema.mjs +36 -11
  78. package/type/validate.d.ts +1 -3
  79. package/type/validate.js +1 -3
  80. package/type/validate.mjs +1 -3
  81. package/utilities/TypeInfo.d.ts +15 -11
  82. package/utilities/TypeInfo.js +15 -11
  83. package/utilities/TypeInfo.mjs +15 -11
  84. package/utilities/assertValidName.d.ts +1 -1
  85. package/utilities/assertValidName.js +1 -1
  86. package/utilities/assertValidName.mjs +1 -1
  87. package/utilities/astFromValue.d.ts +3 -1
  88. package/utilities/astFromValue.js +3 -1
  89. package/utilities/astFromValue.mjs +3 -1
  90. package/utilities/buildASTSchema.d.ts +8 -8
  91. package/utilities/buildASTSchema.js +9 -20
  92. package/utilities/buildASTSchema.mjs +9 -20
  93. package/utilities/buildClientSchema.d.ts +6 -2
  94. package/utilities/buildClientSchema.js +6 -2
  95. package/utilities/buildClientSchema.mjs +6 -2
  96. package/utilities/coerceInputValue.d.ts +9 -3
  97. package/utilities/coerceInputValue.js +60 -13
  98. package/utilities/coerceInputValue.mjs +58 -13
  99. package/utilities/concatAST.d.ts +4 -1
  100. package/utilities/concatAST.js +4 -1
  101. package/utilities/concatAST.mjs +4 -1
  102. package/utilities/extendSchema.d.ts +7 -4
  103. package/utilities/extendSchema.js +7 -4
  104. package/utilities/extendSchema.mjs +7 -4
  105. package/utilities/findBreakingChanges.d.ts +2 -2
  106. package/utilities/findBreakingChanges.js +2 -2
  107. package/utilities/findBreakingChanges.mjs +2 -2
  108. package/utilities/getIntrospectionQuery.d.ts +9 -9
  109. package/utilities/getIntrospectionQuery.js +8 -8
  110. package/utilities/getIntrospectionQuery.mjs +8 -8
  111. package/utilities/getOperationAST.d.ts +2 -2
  112. package/utilities/getOperationAST.js +2 -2
  113. package/utilities/getOperationAST.mjs +2 -2
  114. package/utilities/getOperationRootType.d.ts +3 -1
  115. package/utilities/getOperationRootType.js +3 -1
  116. package/utilities/getOperationRootType.mjs +3 -1
  117. package/utilities/introspectionFromSchema.d.ts +12 -4
  118. package/utilities/introspectionFromSchema.js +12 -4
  119. package/utilities/introspectionFromSchema.mjs +12 -4
  120. package/utilities/lexicographicSortSchema.d.ts +17 -13
  121. package/utilities/lexicographicSortSchema.js +17 -13
  122. package/utilities/lexicographicSortSchema.mjs +17 -13
  123. package/utilities/printSchema.d.ts +7 -4
  124. package/utilities/printSchema.js +7 -4
  125. package/utilities/printSchema.mjs +7 -4
  126. package/utilities/resolveSchemaCoordinate.d.ts +9 -8
  127. package/utilities/resolveSchemaCoordinate.js +9 -8
  128. package/utilities/resolveSchemaCoordinate.mjs +9 -8
  129. package/utilities/separateOperations.d.ts +2 -2
  130. package/utilities/separateOperations.js +2 -2
  131. package/utilities/separateOperations.mjs +2 -2
  132. package/utilities/stripIgnoredCharacters.d.ts +19 -5
  133. package/utilities/stripIgnoredCharacters.js +19 -5
  134. package/utilities/stripIgnoredCharacters.mjs +19 -5
  135. package/utilities/typeComparators.d.ts +1 -5
  136. package/utilities/typeComparators.js +1 -5
  137. package/utilities/typeComparators.mjs +1 -5
  138. package/utilities/valueFromAST.js +4 -4
  139. package/utilities/valueFromAST.mjs +4 -4
  140. package/utilities/valueFromASTUntyped.d.ts +1 -3
  141. package/utilities/valueFromASTUntyped.js +1 -3
  142. package/utilities/valueFromASTUntyped.mjs +1 -3
  143. package/validation/ValidationContext.d.ts +22 -3
  144. package/validation/ValidationContext.js +84 -27
  145. package/validation/ValidationContext.mjs +82 -27
  146. package/validation/rules/ExecutableDefinitionsRule.d.ts +6 -4
  147. package/validation/rules/ExecutableDefinitionsRule.js +6 -4
  148. package/validation/rules/ExecutableDefinitionsRule.mjs +6 -4
  149. package/validation/rules/FieldsOnCorrectTypeRule.d.ts +4 -4
  150. package/validation/rules/FieldsOnCorrectTypeRule.js +10 -6
  151. package/validation/rules/FieldsOnCorrectTypeRule.mjs +12 -6
  152. package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +6 -4
  153. package/validation/rules/FragmentsOnCompositeTypesRule.js +6 -4
  154. package/validation/rules/FragmentsOnCompositeTypesRule.mjs +6 -4
  155. package/validation/rules/KnownArgumentNamesRule.d.ts +4 -4
  156. package/validation/rules/KnownArgumentNamesRule.js +26 -17
  157. package/validation/rules/KnownArgumentNamesRule.mjs +21 -11
  158. package/validation/rules/KnownDirectivesRule.d.ts +1 -3
  159. package/validation/rules/KnownDirectivesRule.js +1 -3
  160. package/validation/rules/KnownDirectivesRule.mjs +1 -3
  161. package/validation/rules/KnownFragmentNamesRule.d.ts +4 -4
  162. package/validation/rules/KnownFragmentNamesRule.js +4 -4
  163. package/validation/rules/KnownFragmentNamesRule.mjs +4 -4
  164. package/validation/rules/KnownTypeNamesRule.d.ts +1 -3
  165. package/validation/rules/KnownTypeNamesRule.js +7 -7
  166. package/validation/rules/KnownTypeNamesRule.mjs +7 -7
  167. package/validation/rules/LoneAnonymousOperationRule.d.ts +6 -4
  168. package/validation/rules/LoneAnonymousOperationRule.js +6 -4
  169. package/validation/rules/LoneAnonymousOperationRule.mjs +6 -4
  170. package/validation/rules/MaxIntrospectionDepthRule.d.ts +6 -4
  171. package/validation/rules/MaxIntrospectionDepthRule.js +44 -19
  172. package/validation/rules/MaxIntrospectionDepthRule.mjs +44 -19
  173. package/validation/rules/NoFragmentCyclesRule.d.ts +1 -3
  174. package/validation/rules/NoFragmentCyclesRule.js +1 -3
  175. package/validation/rules/NoFragmentCyclesRule.mjs +1 -3
  176. package/validation/rules/NoUndefinedVariablesRule.d.ts +4 -4
  177. package/validation/rules/NoUndefinedVariablesRule.js +4 -4
  178. package/validation/rules/NoUndefinedVariablesRule.mjs +4 -4
  179. package/validation/rules/NoUnusedFragmentsRule.d.ts +4 -4
  180. package/validation/rules/NoUnusedFragmentsRule.js +10 -14
  181. package/validation/rules/NoUnusedFragmentsRule.mjs +10 -14
  182. package/validation/rules/NoUnusedVariablesRule.d.ts +4 -4
  183. package/validation/rules/NoUnusedVariablesRule.js +4 -4
  184. package/validation/rules/NoUnusedVariablesRule.mjs +4 -4
  185. package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +8 -6
  186. package/validation/rules/OverlappingFieldsCanBeMergedRule.js +552 -354
  187. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +545 -352
  188. package/validation/rules/PossibleFragmentSpreadsRule.d.ts +6 -4
  189. package/validation/rules/PossibleFragmentSpreadsRule.js +6 -4
  190. package/validation/rules/PossibleFragmentSpreadsRule.mjs +6 -4
  191. package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +6 -4
  192. package/validation/rules/ProvidedRequiredArgumentsRule.js +6 -4
  193. package/validation/rules/ProvidedRequiredArgumentsRule.mjs +6 -4
  194. package/validation/rules/ScalarLeafsRule.d.ts +1 -3
  195. package/validation/rules/ScalarLeafsRule.js +1 -3
  196. package/validation/rules/ScalarLeafsRule.mjs +1 -3
  197. package/validation/rules/SingleFieldSubscriptionsRule.d.ts +6 -4
  198. package/validation/rules/SingleFieldSubscriptionsRule.js +50 -9
  199. package/validation/rules/SingleFieldSubscriptionsRule.mjs +50 -9
  200. package/validation/rules/UniqueArgumentNamesRule.d.ts +4 -4
  201. package/validation/rules/UniqueArgumentNamesRule.js +4 -4
  202. package/validation/rules/UniqueArgumentNamesRule.mjs +4 -4
  203. package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +6 -4
  204. package/validation/rules/UniqueDirectivesPerLocationRule.js +6 -4
  205. package/validation/rules/UniqueDirectivesPerLocationRule.mjs +6 -4
  206. package/validation/rules/UniqueFragmentNamesRule.d.ts +4 -4
  207. package/validation/rules/UniqueFragmentNamesRule.js +4 -4
  208. package/validation/rules/UniqueFragmentNamesRule.mjs +4 -4
  209. package/validation/rules/UniqueInputFieldNamesRule.d.ts +6 -4
  210. package/validation/rules/UniqueInputFieldNamesRule.js +6 -4
  211. package/validation/rules/UniqueInputFieldNamesRule.mjs +6 -4
  212. package/validation/rules/UniqueOperationNamesRule.d.ts +4 -4
  213. package/validation/rules/UniqueOperationNamesRule.js +4 -4
  214. package/validation/rules/UniqueOperationNamesRule.mjs +4 -4
  215. package/validation/rules/UniqueVariableNamesRule.d.ts +4 -4
  216. package/validation/rules/UniqueVariableNamesRule.js +4 -4
  217. package/validation/rules/UniqueVariableNamesRule.mjs +4 -4
  218. package/validation/rules/ValuesOfCorrectTypeRule.d.ts +4 -4
  219. package/validation/rules/ValuesOfCorrectTypeRule.js +29 -23
  220. package/validation/rules/ValuesOfCorrectTypeRule.mjs +24 -14
  221. package/validation/rules/VariablesAreInputTypesRule.d.ts +6 -4
  222. package/validation/rules/VariablesAreInputTypesRule.js +6 -4
  223. package/validation/rules/VariablesAreInputTypesRule.mjs +6 -4
  224. package/validation/rules/VariablesInAllowedPositionRule.d.ts +6 -4
  225. package/validation/rules/VariablesInAllowedPositionRule.js +6 -4
  226. package/validation/rules/VariablesInAllowedPositionRule.mjs +6 -4
  227. package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +4 -4
  228. package/validation/rules/custom/NoDeprecatedCustomRule.js +4 -4
  229. package/validation/rules/custom/NoDeprecatedCustomRule.mjs +4 -4
  230. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +7 -5
  231. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +7 -5
  232. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +7 -5
  233. package/validation/validate.d.ts +2 -0
  234. package/validation/validate.js +14 -2
  235. package/validation/validate.mjs +13 -2
  236. package/validation/validationAbortedError.d.ts +3 -0
  237. package/validation/validationAbortedError.js +14 -0
  238. package/validation/validationAbortedError.mjs +4 -0
  239. package/version.js +3 -3
  240. package/version.mjs +3 -3
@@ -121,7 +121,10 @@ var _values = require('./values.js');
121
121
  * 'subscription Greeting($locale: String) { greeting(locale: $locale) }',
122
122
  * ),
123
123
  * rootValue: {
124
- * greeting: (args, contextValue) => {
124
+ * greeting: (
125
+ * args: { locale?: string },
126
+ * contextValue: { defaultLocale: string },
127
+ * ) => {
125
128
  * const locale = args.locale ?? contextValue.defaultLocale;
126
129
  * return locale === 'fr' ? frenchGreetings() : defaultGreetings();
127
130
  * },
@@ -161,7 +164,7 @@ var _values = require('./values.js');
161
164
  *
162
165
  * assert('errors' in result);
163
166
  *
164
- * result.errors[0].message; // => 'Schema is not configured to execute subscription operation.'
167
+ * result.errors?.[0].message; // => 'Schema is not configured to execute subscription operation.'
165
168
  * ```
166
169
  */
167
170
  async function subscribe(args) {
@@ -109,7 +109,10 @@ import { getArgumentValues } from './values.mjs';
109
109
  * 'subscription Greeting($locale: String) { greeting(locale: $locale) }',
110
110
  * ),
111
111
  * rootValue: {
112
- * greeting: (args, contextValue) => {
112
+ * greeting: (
113
+ * args: { locale?: string },
114
+ * contextValue: { defaultLocale: string },
115
+ * ) => {
113
116
  * const locale = args.locale ?? contextValue.defaultLocale;
114
117
  * return locale === 'fr' ? frenchGreetings() : defaultGreetings();
115
118
  * },
@@ -149,7 +152,7 @@ import { getArgumentValues } from './values.mjs';
149
152
  *
150
153
  * assert('errors' in result);
151
154
  *
152
- * result.errors[0].message; // => 'Schema is not configured to execute subscription operation.'
155
+ * result.errors?.[0].message; // => 'Schema is not configured to execute subscription operation.'
153
156
  * ```
154
157
  */
155
158
 
@@ -26,6 +26,8 @@ declare type CoercedVariableValues =
26
26
  * @internal
27
27
  */
28
28
  export interface GetVariableValuesOptions {
29
+ /** Omit suggestions from input coercion errors. */
30
+ hideSuggestions?: boolean;
29
31
  /**
30
32
  * Maximum number of variable coercion errors before coercion stops.
31
33
  * @internal
@@ -47,8 +49,9 @@ export interface GetVariableValuesOptions {
47
49
  * @returns Coerced variable values, or request errors.
48
50
  * @example
49
51
  * ```ts
52
+ * import assert from 'node:assert/strict';
50
53
  * // Coerce provided variables and apply operation defaults.
51
- * import { parse } from 'graphql/language';
54
+ * import { parse, Kind } from 'graphql/language';
52
55
  * import { buildSchema } from 'graphql/utilities';
53
56
  * import { getVariableValues } from 'graphql/execution';
54
57
  *
@@ -63,19 +66,19 @@ export interface GetVariableValuesOptions {
63
66
  * }
64
67
  * `);
65
68
  * const operation = document.definitions[0];
69
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
66
70
  *
67
- * const result = getVariableValues(
68
- * schema,
69
- * operation.variableDefinitions,
70
- * { stars: '5' },
71
- * );
71
+ * const result = getVariableValues(schema, operation.variableDefinitions ?? [], {
72
+ * stars: 5,
73
+ * });
72
74
  *
73
75
  * result; // => { coerced: { stars: 5, limit: 10 } }
74
76
  * ```
75
77
  * @example
76
78
  * ```ts
79
+ * import assert from 'node:assert/strict';
77
80
  * // This variant uses maxErrors to cap reported coercion errors.
78
- * import { parse } from 'graphql/language';
81
+ * import { parse, Kind } from 'graphql/language';
79
82
  * import { buildSchema } from 'graphql/utilities';
80
83
  * import { getVariableValues } from 'graphql/execution';
81
84
  *
@@ -95,16 +98,17 @@ export interface GetVariableValuesOptions {
95
98
  * }
96
99
  * `);
97
100
  * const operation = document.definitions[0];
101
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
98
102
  *
99
103
  * const result = getVariableValues(
100
104
  * schema,
101
- * operation.variableDefinitions,
105
+ * operation.variableDefinitions ?? [],
102
106
  * { first: { stars: 'bad' }, second: { stars: 'also bad' } },
103
107
  * { maxErrors: 1 },
104
108
  * );
105
109
  *
106
- * result.errors.length; // => 2
107
- * result.errors[1].message; // matches /error limit reached/
110
+ * result.errors?.length; // => 2
111
+ * result.errors?.[1].message.includes('error limit reached'); // => true
108
112
  * ```
109
113
  */
110
114
  export declare function getVariableValues(
@@ -128,8 +132,9 @@ export declare function getVariableValues(
128
132
  * @returns Coerced argument values keyed by argument name.
129
133
  * @example
130
134
  * ```ts
135
+ * import assert from 'node:assert/strict';
131
136
  * // Read literal argument values and defaults.
132
- * import { parse } from 'graphql/language';
137
+ * import { parse, Kind } from 'graphql/language';
133
138
  * import { buildSchema } from 'graphql/utilities';
134
139
  * import { getArgumentValues } from 'graphql/execution';
135
140
  *
@@ -138,16 +143,21 @@ export declare function getVariableValues(
138
143
  * reviews(stars: Int!, limit: Int = 10): [String]
139
144
  * }
140
145
  * `);
141
- * const fieldDef = schema.getQueryType().getFields().reviews;
146
+ * const fieldDef = schema.getQueryType()?.getFields().reviews;
147
+ * assert(fieldDef);
142
148
  * const document = parse('{ reviews(stars: 5) }');
143
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
149
+ * const operation = document.definitions[0];
150
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
151
+ * const fieldNode = operation.selectionSet.selections[0];
152
+ * assert(fieldNode.kind === Kind.FIELD);
144
153
  *
145
154
  * getArgumentValues(fieldDef, fieldNode); // => { stars: 5, limit: 10 }
146
155
  * ```
147
156
  * @example
148
157
  * ```ts
158
+ * import assert from 'node:assert/strict';
149
159
  * // This variant resolves argument values from operation variables.
150
- * import { parse } from 'graphql/language';
160
+ * import { parse, Kind } from 'graphql/language';
151
161
  * import { buildSchema } from 'graphql/utilities';
152
162
  * import { getArgumentValues } from 'graphql/execution';
153
163
  *
@@ -156,9 +166,13 @@ export declare function getVariableValues(
156
166
  * reviews(stars: Int!): [String]
157
167
  * }
158
168
  * `);
159
- * const fieldDef = schema.getQueryType().getFields().reviews;
169
+ * const fieldDef = schema.getQueryType()?.getFields().reviews;
170
+ * assert(fieldDef);
160
171
  * const document = parse('query ($stars: Int!) { reviews(stars: $stars) }');
161
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
172
+ * const operation = document.definitions[0];
173
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
174
+ * const fieldNode = operation.selectionSet.selections[0];
175
+ * assert(fieldNode.kind === Kind.FIELD);
162
176
  *
163
177
  * getArgumentValues(fieldDef, fieldNode, { stars: 5 }); // => { stars: 5 }
164
178
  * getArgumentValues(fieldDef, fieldNode, {}); // throws an error
@@ -198,25 +212,33 @@ export interface DirectiveValuesNode {
198
212
  * @returns Coerced directive argument values keyed by argument name.
199
213
  * @example
200
214
  * ```ts
215
+ * import assert from 'node:assert/strict';
201
216
  * // Read literal directive arguments from a node.
202
- * import { parse } from 'graphql/language';
217
+ * import { parse, Kind } from 'graphql/language';
203
218
  * import { GraphQLSkipDirective } from 'graphql/type';
204
219
  * import { getDirectiveValues } from 'graphql/execution';
205
220
  *
206
221
  * const document = parse('{ name @skip(if: true) }');
207
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
222
+ * const operation = document.definitions[0];
223
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
224
+ * const fieldNode = operation.selectionSet.selections[0];
208
225
  *
209
226
  * getDirectiveValues(GraphQLSkipDirective, fieldNode); // => { if: true }
210
227
  * ```
211
228
  * @example
212
229
  * ```ts
230
+ * import assert from 'node:assert/strict';
213
231
  * // This variant resolves directive arguments from variables and handles absent directives.
214
- * import { parse } from 'graphql/language';
232
+ * import { parse, Kind } from 'graphql/language';
215
233
  * import { GraphQLIncludeDirective } from 'graphql/type';
216
234
  * import { getDirectiveValues } from 'graphql/execution';
217
235
  *
218
- * const document = parse('query ($includeName: Boolean!) { name @include(if: $includeName) }');
219
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
236
+ * const document = parse(
237
+ * 'query ($includeName: Boolean!) { name @include(if: $includeName) }',
238
+ * );
239
+ * const operation = document.definitions[0];
240
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
241
+ * const fieldNode = operation.selectionSet.selections[0];
220
242
  *
221
243
  * getDirectiveValues(GraphQLIncludeDirective, fieldNode, {
222
244
  * includeName: false,
@@ -44,8 +44,9 @@ var _valueFromAST = require('../utilities/valueFromAST.js');
44
44
  * @returns Coerced variable values, or request errors.
45
45
  * @example
46
46
  * ```ts
47
+ * import assert from 'node:assert/strict';
47
48
  * // Coerce provided variables and apply operation defaults.
48
- * import { parse } from 'graphql/language';
49
+ * import { parse, Kind } from 'graphql/language';
49
50
  * import { buildSchema } from 'graphql/utilities';
50
51
  * import { getVariableValues } from 'graphql/execution';
51
52
  *
@@ -60,19 +61,19 @@ var _valueFromAST = require('../utilities/valueFromAST.js');
60
61
  * }
61
62
  * `);
62
63
  * const operation = document.definitions[0];
64
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
63
65
  *
64
- * const result = getVariableValues(
65
- * schema,
66
- * operation.variableDefinitions,
67
- * { stars: '5' },
68
- * );
66
+ * const result = getVariableValues(schema, operation.variableDefinitions ?? [], {
67
+ * stars: 5,
68
+ * });
69
69
  *
70
70
  * result; // => { coerced: { stars: 5, limit: 10 } }
71
71
  * ```
72
72
  * @example
73
73
  * ```ts
74
+ * import assert from 'node:assert/strict';
74
75
  * // This variant uses maxErrors to cap reported coercion errors.
75
- * import { parse } from 'graphql/language';
76
+ * import { parse, Kind } from 'graphql/language';
76
77
  * import { buildSchema } from 'graphql/utilities';
77
78
  * import { getVariableValues } from 'graphql/execution';
78
79
  *
@@ -92,16 +93,17 @@ var _valueFromAST = require('../utilities/valueFromAST.js');
92
93
  * }
93
94
  * `);
94
95
  * const operation = document.definitions[0];
96
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
95
97
  *
96
98
  * const result = getVariableValues(
97
99
  * schema,
98
- * operation.variableDefinitions,
100
+ * operation.variableDefinitions ?? [],
99
101
  * { first: { stars: 'bad' }, second: { stars: 'also bad' } },
100
102
  * { maxErrors: 1 },
101
103
  * );
102
104
  *
103
- * result.errors.length; // => 2
104
- * result.errors[1].message; // matches /error limit reached/
105
+ * result.errors?.length; // => 2
106
+ * result.errors?.[1].message.includes('error limit reached'); // => true
105
107
  * ```
106
108
  */
107
109
  function getVariableValues(schema, varDefNodes, inputs, options) {
@@ -123,6 +125,7 @@ function getVariableValues(schema, varDefNodes, inputs, options) {
123
125
 
124
126
  errors.push(error);
125
127
  },
128
+ options === null || options === void 0 ? void 0 : options.hideSuggestions,
126
129
  );
127
130
 
128
131
  if (errors.length === 0) {
@@ -139,7 +142,13 @@ function getVariableValues(schema, varDefNodes, inputs, options) {
139
142
  };
140
143
  }
141
144
 
142
- function coerceVariableValues(schema, varDefNodes, inputs, onError) {
145
+ function coerceVariableValues(
146
+ schema,
147
+ varDefNodes,
148
+ inputs,
149
+ onError,
150
+ hideSuggestions,
151
+ ) {
143
152
  const coercedValues = Object.create(null);
144
153
 
145
154
  for (const varDefNode of varDefNodes) {
@@ -149,7 +158,7 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
149
158
  if (!(0, _definition.isInputType)(varType)) {
150
159
  // Must use input types for variables. This should be caught during
151
160
  // validation, however is checked again here for safety.
152
- const varTypeStr = (0, _printer.print)(varDefNode.type);
161
+ const varTypeStr = (0, _printer.printForError)(varDefNode.type);
153
162
  onError(
154
163
  new _GraphQLError.GraphQLError(
155
164
  `Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`,
@@ -218,6 +227,7 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
218
227
  }),
219
228
  );
220
229
  },
230
+ hideSuggestions,
221
231
  );
222
232
  }
223
233
 
@@ -236,8 +246,9 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
236
246
  * @returns Coerced argument values keyed by argument name.
237
247
  * @example
238
248
  * ```ts
249
+ * import assert from 'node:assert/strict';
239
250
  * // Read literal argument values and defaults.
240
- * import { parse } from 'graphql/language';
251
+ * import { parse, Kind } from 'graphql/language';
241
252
  * import { buildSchema } from 'graphql/utilities';
242
253
  * import { getArgumentValues } from 'graphql/execution';
243
254
  *
@@ -246,16 +257,21 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
246
257
  * reviews(stars: Int!, limit: Int = 10): [String]
247
258
  * }
248
259
  * `);
249
- * const fieldDef = schema.getQueryType().getFields().reviews;
260
+ * const fieldDef = schema.getQueryType()?.getFields().reviews;
261
+ * assert(fieldDef);
250
262
  * const document = parse('{ reviews(stars: 5) }');
251
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
263
+ * const operation = document.definitions[0];
264
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
265
+ * const fieldNode = operation.selectionSet.selections[0];
266
+ * assert(fieldNode.kind === Kind.FIELD);
252
267
  *
253
268
  * getArgumentValues(fieldDef, fieldNode); // => { stars: 5, limit: 10 }
254
269
  * ```
255
270
  * @example
256
271
  * ```ts
272
+ * import assert from 'node:assert/strict';
257
273
  * // This variant resolves argument values from operation variables.
258
- * import { parse } from 'graphql/language';
274
+ * import { parse, Kind } from 'graphql/language';
259
275
  * import { buildSchema } from 'graphql/utilities';
260
276
  * import { getArgumentValues } from 'graphql/execution';
261
277
  *
@@ -264,9 +280,13 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
264
280
  * reviews(stars: Int!): [String]
265
281
  * }
266
282
  * `);
267
- * const fieldDef = schema.getQueryType().getFields().reviews;
283
+ * const fieldDef = schema.getQueryType()?.getFields().reviews;
284
+ * assert(fieldDef);
268
285
  * const document = parse('query ($stars: Int!) { reviews(stars: $stars) }');
269
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
286
+ * const operation = document.definitions[0];
287
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
288
+ * const fieldNode = operation.selectionSet.selections[0];
289
+ * assert(fieldNode.kind === Kind.FIELD);
270
290
  *
271
291
  * getArgumentValues(fieldDef, fieldNode, { stars: 5 }); // => { stars: 5 }
272
292
  * getArgumentValues(fieldDef, fieldNode, {}); // throws an error
@@ -363,7 +383,7 @@ function getArgumentValues(def, node, variableValues) {
363
383
  // execution. This is a runtime check to ensure execution does not
364
384
  // continue with an invalid argument value.
365
385
  throw new _GraphQLError.GraphQLError(
366
- `Argument "${name}" has invalid value ${(0, _printer.print)(
386
+ `Argument "${name}" has invalid value ${(0, _printer.printForError)(
367
387
  valueNode,
368
388
  )}.`,
369
389
  {
@@ -398,25 +418,33 @@ function getArgumentValues(def, node, variableValues) {
398
418
  * @returns Coerced directive argument values keyed by argument name.
399
419
  * @example
400
420
  * ```ts
421
+ * import assert from 'node:assert/strict';
401
422
  * // Read literal directive arguments from a node.
402
- * import { parse } from 'graphql/language';
423
+ * import { parse, Kind } from 'graphql/language';
403
424
  * import { GraphQLSkipDirective } from 'graphql/type';
404
425
  * import { getDirectiveValues } from 'graphql/execution';
405
426
  *
406
427
  * const document = parse('{ name @skip(if: true) }');
407
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
428
+ * const operation = document.definitions[0];
429
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
430
+ * const fieldNode = operation.selectionSet.selections[0];
408
431
  *
409
432
  * getDirectiveValues(GraphQLSkipDirective, fieldNode); // => { if: true }
410
433
  * ```
411
434
  * @example
412
435
  * ```ts
436
+ * import assert from 'node:assert/strict';
413
437
  * // This variant resolves directive arguments from variables and handles absent directives.
414
- * import { parse } from 'graphql/language';
438
+ * import { parse, Kind } from 'graphql/language';
415
439
  * import { GraphQLIncludeDirective } from 'graphql/type';
416
440
  * import { getDirectiveValues } from 'graphql/execution';
417
441
  *
418
- * const document = parse('query ($includeName: Boolean!) { name @include(if: $includeName) }');
419
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
442
+ * const document = parse(
443
+ * 'query ($includeName: Boolean!) { name @include(if: $includeName) }',
444
+ * );
445
+ * const operation = document.definitions[0];
446
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
447
+ * const fieldNode = operation.selectionSet.selections[0];
420
448
  *
421
449
  * getDirectiveValues(GraphQLIncludeDirective, fieldNode, {
422
450
  * includeName: false,
@@ -4,7 +4,7 @@ import { keyMap } from '../jsutils/keyMap.mjs';
4
4
  import { printPathArray } from '../jsutils/printPathArray.mjs';
5
5
  import { GraphQLError } from '../error/GraphQLError.mjs';
6
6
  import { Kind } from '../language/kinds.mjs';
7
- import { print } from '../language/printer.mjs';
7
+ import { printForError as print } from '../language/printer.mjs';
8
8
  import { isInputType, isNonNullType } from '../type/definition.mjs';
9
9
  import { coerceInputValue } from '../utilities/coerceInputValue.mjs';
10
10
  import { typeFromAST } from '../utilities/typeFromAST.mjs';
@@ -25,8 +25,9 @@ import { valueFromAST } from '../utilities/valueFromAST.mjs';
25
25
  * @returns Coerced variable values, or request errors.
26
26
  * @example
27
27
  * ```ts
28
+ * import assert from 'node:assert/strict';
28
29
  * // Coerce provided variables and apply operation defaults.
29
- * import { parse } from 'graphql/language';
30
+ * import { parse, Kind } from 'graphql/language';
30
31
  * import { buildSchema } from 'graphql/utilities';
31
32
  * import { getVariableValues } from 'graphql/execution';
32
33
  *
@@ -41,19 +42,19 @@ import { valueFromAST } from '../utilities/valueFromAST.mjs';
41
42
  * }
42
43
  * `);
43
44
  * const operation = document.definitions[0];
45
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
44
46
  *
45
- * const result = getVariableValues(
46
- * schema,
47
- * operation.variableDefinitions,
48
- * { stars: '5' },
49
- * );
47
+ * const result = getVariableValues(schema, operation.variableDefinitions ?? [], {
48
+ * stars: 5,
49
+ * });
50
50
  *
51
51
  * result; // => { coerced: { stars: 5, limit: 10 } }
52
52
  * ```
53
53
  * @example
54
54
  * ```ts
55
+ * import assert from 'node:assert/strict';
55
56
  * // This variant uses maxErrors to cap reported coercion errors.
56
- * import { parse } from 'graphql/language';
57
+ * import { parse, Kind } from 'graphql/language';
57
58
  * import { buildSchema } from 'graphql/utilities';
58
59
  * import { getVariableValues } from 'graphql/execution';
59
60
  *
@@ -73,16 +74,17 @@ import { valueFromAST } from '../utilities/valueFromAST.mjs';
73
74
  * }
74
75
  * `);
75
76
  * const operation = document.definitions[0];
77
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
76
78
  *
77
79
  * const result = getVariableValues(
78
80
  * schema,
79
- * operation.variableDefinitions,
81
+ * operation.variableDefinitions ?? [],
80
82
  * { first: { stars: 'bad' }, second: { stars: 'also bad' } },
81
83
  * { maxErrors: 1 },
82
84
  * );
83
85
  *
84
- * result.errors.length; // => 2
85
- * result.errors[1].message; // matches /error limit reached/
86
+ * result.errors?.length; // => 2
87
+ * result.errors?.[1].message.includes('error limit reached'); // => true
86
88
  * ```
87
89
  */
88
90
  export function getVariableValues(schema, varDefNodes, inputs, options) {
@@ -104,6 +106,7 @@ export function getVariableValues(schema, varDefNodes, inputs, options) {
104
106
 
105
107
  errors.push(error);
106
108
  },
109
+ options === null || options === void 0 ? void 0 : options.hideSuggestions,
107
110
  );
108
111
 
109
112
  if (errors.length === 0) {
@@ -120,7 +123,13 @@ export function getVariableValues(schema, varDefNodes, inputs, options) {
120
123
  };
121
124
  }
122
125
 
123
- function coerceVariableValues(schema, varDefNodes, inputs, onError) {
126
+ function coerceVariableValues(
127
+ schema,
128
+ varDefNodes,
129
+ inputs,
130
+ onError,
131
+ hideSuggestions,
132
+ ) {
124
133
  const coercedValues = Object.create(null);
125
134
 
126
135
  for (const varDefNode of varDefNodes) {
@@ -193,6 +202,7 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
193
202
  }),
194
203
  );
195
204
  },
205
+ hideSuggestions,
196
206
  );
197
207
  }
198
208
 
@@ -211,8 +221,9 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
211
221
  * @returns Coerced argument values keyed by argument name.
212
222
  * @example
213
223
  * ```ts
224
+ * import assert from 'node:assert/strict';
214
225
  * // Read literal argument values and defaults.
215
- * import { parse } from 'graphql/language';
226
+ * import { parse, Kind } from 'graphql/language';
216
227
  * import { buildSchema } from 'graphql/utilities';
217
228
  * import { getArgumentValues } from 'graphql/execution';
218
229
  *
@@ -221,16 +232,21 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
221
232
  * reviews(stars: Int!, limit: Int = 10): [String]
222
233
  * }
223
234
  * `);
224
- * const fieldDef = schema.getQueryType().getFields().reviews;
235
+ * const fieldDef = schema.getQueryType()?.getFields().reviews;
236
+ * assert(fieldDef);
225
237
  * const document = parse('{ reviews(stars: 5) }');
226
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
238
+ * const operation = document.definitions[0];
239
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
240
+ * const fieldNode = operation.selectionSet.selections[0];
241
+ * assert(fieldNode.kind === Kind.FIELD);
227
242
  *
228
243
  * getArgumentValues(fieldDef, fieldNode); // => { stars: 5, limit: 10 }
229
244
  * ```
230
245
  * @example
231
246
  * ```ts
247
+ * import assert from 'node:assert/strict';
232
248
  * // This variant resolves argument values from operation variables.
233
- * import { parse } from 'graphql/language';
249
+ * import { parse, Kind } from 'graphql/language';
234
250
  * import { buildSchema } from 'graphql/utilities';
235
251
  * import { getArgumentValues } from 'graphql/execution';
236
252
  *
@@ -239,9 +255,13 @@ function coerceVariableValues(schema, varDefNodes, inputs, onError) {
239
255
  * reviews(stars: Int!): [String]
240
256
  * }
241
257
  * `);
242
- * const fieldDef = schema.getQueryType().getFields().reviews;
258
+ * const fieldDef = schema.getQueryType()?.getFields().reviews;
259
+ * assert(fieldDef);
243
260
  * const document = parse('query ($stars: Int!) { reviews(stars: $stars) }');
244
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
261
+ * const operation = document.definitions[0];
262
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
263
+ * const fieldNode = operation.selectionSet.selections[0];
264
+ * assert(fieldNode.kind === Kind.FIELD);
245
265
  *
246
266
  * getArgumentValues(fieldDef, fieldNode, { stars: 5 }); // => { stars: 5 }
247
267
  * getArgumentValues(fieldDef, fieldNode, {}); // throws an error
@@ -360,25 +380,33 @@ export function getArgumentValues(def, node, variableValues) {
360
380
  * @returns Coerced directive argument values keyed by argument name.
361
381
  * @example
362
382
  * ```ts
383
+ * import assert from 'node:assert/strict';
363
384
  * // Read literal directive arguments from a node.
364
- * import { parse } from 'graphql/language';
385
+ * import { parse, Kind } from 'graphql/language';
365
386
  * import { GraphQLSkipDirective } from 'graphql/type';
366
387
  * import { getDirectiveValues } from 'graphql/execution';
367
388
  *
368
389
  * const document = parse('{ name @skip(if: true) }');
369
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
390
+ * const operation = document.definitions[0];
391
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
392
+ * const fieldNode = operation.selectionSet.selections[0];
370
393
  *
371
394
  * getDirectiveValues(GraphQLSkipDirective, fieldNode); // => { if: true }
372
395
  * ```
373
396
  * @example
374
397
  * ```ts
398
+ * import assert from 'node:assert/strict';
375
399
  * // This variant resolves directive arguments from variables and handles absent directives.
376
- * import { parse } from 'graphql/language';
400
+ * import { parse, Kind } from 'graphql/language';
377
401
  * import { GraphQLIncludeDirective } from 'graphql/type';
378
402
  * import { getDirectiveValues } from 'graphql/execution';
379
403
  *
380
- * const document = parse('query ($includeName: Boolean!) { name @include(if: $includeName) }');
381
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
404
+ * const document = parse(
405
+ * 'query ($includeName: Boolean!) { name @include(if: $includeName) }',
406
+ * );
407
+ * const operation = document.definitions[0];
408
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
409
+ * const fieldNode = operation.selectionSet.selections[0];
382
410
  *
383
411
  * getDirectiveValues(GraphQLIncludeDirective, fieldNode, {
384
412
  * includeName: false,
package/graphql.d.ts CHANGED
@@ -14,6 +14,8 @@ import type { ExecutionResult } from './execution/execute';
14
14
  * @category Request Pipeline
15
15
  */
16
16
  export interface GraphQLArgs {
17
+ /** Omit suggestions from validation and input coercion errors. */
18
+ hideSuggestions?: Maybe<boolean>;
17
19
  /** The GraphQL type system to use when validating and executing a query. */
18
20
  schema: GraphQLSchema;
19
21
  /**
@@ -84,13 +86,11 @@ export interface GraphQLArgs {
84
86
  * schema,
85
87
  * source: 'query SayHello($name: String!) { greeting(name: $name) }',
86
88
  * rootValue: {
87
- * greeting: ({ name }) => `Hello, ${name}!`,
89
+ * greeting: ({ name }: { name: string }) => `Hello, ${name}!`,
88
90
  * },
89
91
  * variableValues: { name: 'Ada' },
90
92
  * operationName: 'SayHello',
91
- * });
92
- *
93
- * result; // => { data: { greeting: 'Hello, Ada!' } }
93
+ * }); // => { data: { greeting: 'Hello, Ada!' } }
94
94
  * ```
95
95
  * @example
96
96
  * ```ts
@@ -123,9 +123,7 @@ export interface GraphQLArgs {
123
123
  * typeResolver: (value) => {
124
124
  * return value.kind === 'user' ? 'User' : undefined;
125
125
  * },
126
- * });
127
- *
128
- * result; // => { data: { viewer: { __typename: 'User', name: 'Ada' } } }
126
+ * }); // => { data: { viewer: { __typename: 'User', name: 'Ada' } } }
129
127
  * ```
130
128
  * @category Request Pipeline
131
129
  */
@@ -154,13 +152,11 @@ export declare function graphql(args: GraphQLArgs): Promise<ExecutionResult>;
154
152
  * schema,
155
153
  * source: 'query SayHello($name: String!) { greeting(name: $name) }',
156
154
  * rootValue: {
157
- * greeting: ({ name }) => `Hello, ${name}!`,
155
+ * greeting: ({ name }: { name: string }) => `Hello, ${name}!`,
158
156
  * },
159
157
  * variableValues: { name: 'Ada' },
160
158
  * operationName: 'SayHello',
161
- * });
162
- *
163
- * result; // => { data: { greeting: 'Hello, Ada!' } }
159
+ * }); // => { data: { greeting: 'Hello, Ada!' } }
164
160
  * ```
165
161
  * @example
166
162
  * ```ts
@@ -180,9 +176,7 @@ export declare function graphql(args: GraphQLArgs): Promise<ExecutionResult>;
180
176
  * return contextValue.defaultGreeting;
181
177
  * },
182
178
  * contextValue: { defaultGreeting: 'Hello' },
183
- * });
184
- *
185
- * result; // => { data: { greeting: 'Hello' } }
179
+ * }); // => { data: { greeting: 'Hello' } }
186
180
  * ```
187
181
  * @category Request Pipeline
188
182
  */