graphql 16.14.2 → 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.
- package/error/GraphQLError.d.ts +5 -1
- package/error/GraphQLError.js +12 -7
- package/error/GraphQLError.mjs +13 -6
- package/error/locatedError.d.ts +6 -4
- package/error/locatedError.js +6 -4
- package/error/locatedError.mjs +6 -4
- package/execution/collectFields.d.ts +1 -0
- package/execution/collectFields.js +9 -0
- package/execution/collectFields.mjs +9 -0
- package/execution/execute.d.ts +9 -10
- package/execution/execute.js +44 -29
- package/execution/execute.mjs +44 -29
- package/execution/mapAsyncIterator.js +12 -11
- package/execution/mapAsyncIterator.mjs +12 -11
- package/execution/subscribe.d.ts +5 -2
- package/execution/subscribe.js +5 -2
- package/execution/subscribe.mjs +5 -2
- package/execution/values.d.ts +43 -21
- package/execution/values.js +52 -24
- package/execution/values.mjs +51 -23
- package/graphql.d.ts +8 -14
- package/graphql.js +16 -15
- package/graphql.mjs +11 -15
- package/jsutils/SetMap.d.ts +14 -0
- package/jsutils/SetMap.js +48 -0
- package/jsutils/SetMap.mjs +39 -0
- package/jsutils/isIterableObject.d.ts +2 -0
- package/jsutils/isIterableObject.js +2 -0
- package/jsutils/isIterableObject.mjs +2 -0
- package/jsutils/keyMap.d.ts +2 -0
- package/jsutils/keyMap.js +2 -0
- package/jsutils/keyMap.mjs +2 -0
- package/jsutils/keyValMap.d.ts +3 -3
- package/jsutils/keyValMap.js +3 -3
- package/jsutils/keyValMap.mjs +3 -3
- package/language/ast.d.ts +2 -6
- package/language/ast.js +2 -6
- package/language/ast.mjs +2 -6
- package/language/lexer.d.ts +6 -0
- package/language/lexer.js +22 -0
- package/language/lexer.mjs +22 -0
- package/language/location.d.ts +8 -3
- package/language/location.js +57 -17
- package/language/location.mjs +56 -16
- package/language/parser.d.ts +27 -13
- package/language/parser.js +31 -9
- package/language/parser.mjs +31 -9
- package/language/predicates.d.ts +10 -3
- package/language/predicates.js +10 -3
- package/language/predicates.mjs +10 -3
- package/language/printLocation.d.ts +2 -6
- package/language/printLocation.js +2 -6
- package/language/printLocation.mjs +2 -6
- package/language/printer.d.ts +22 -3
- package/language/printer.js +394 -308
- package/language/printer.mjs +394 -308
- package/language/reducer.d.ts +32 -0
- package/language/reducer.js +95 -0
- package/language/reducer.mjs +86 -0
- package/language/source.d.ts +4 -5
- package/language/source.js +4 -5
- package/language/source.mjs +4 -5
- package/language/visitor.d.ts +16 -10
- package/language/visitor.js +15 -7
- package/language/visitor.mjs +15 -7
- package/package.json +1 -4
- package/type/definition.d.ts +170 -102
- package/type/definition.js +169 -96
- package/type/definition.mjs +168 -95
- package/type/directives.d.ts +12 -6
- package/type/directives.js +12 -6
- package/type/directives.mjs +12 -6
- package/type/scalars.js +8 -11
- package/type/scalars.mjs +1 -1
- package/type/schema.d.ts +36 -11
- package/type/schema.js +35 -10
- package/type/schema.mjs +35 -10
- package/type/validate.d.ts +1 -3
- package/type/validate.js +1 -3
- package/type/validate.mjs +1 -3
- package/utilities/TypeInfo.d.ts +15 -11
- package/utilities/TypeInfo.js +15 -11
- package/utilities/TypeInfo.mjs +15 -11
- package/utilities/assertValidName.d.ts +1 -1
- package/utilities/assertValidName.js +1 -1
- package/utilities/assertValidName.mjs +1 -1
- package/utilities/astFromValue.d.ts +3 -1
- package/utilities/astFromValue.js +3 -1
- package/utilities/astFromValue.mjs +3 -1
- package/utilities/buildASTSchema.d.ts +8 -8
- package/utilities/buildASTSchema.js +9 -20
- package/utilities/buildASTSchema.mjs +9 -20
- package/utilities/buildClientSchema.d.ts +6 -2
- package/utilities/buildClientSchema.js +6 -2
- package/utilities/buildClientSchema.mjs +6 -2
- package/utilities/coerceInputValue.d.ts +9 -3
- package/utilities/coerceInputValue.js +60 -13
- package/utilities/coerceInputValue.mjs +58 -13
- package/utilities/concatAST.d.ts +4 -1
- package/utilities/concatAST.js +4 -1
- package/utilities/concatAST.mjs +4 -1
- package/utilities/extendSchema.d.ts +7 -4
- package/utilities/extendSchema.js +7 -4
- package/utilities/extendSchema.mjs +7 -4
- package/utilities/findBreakingChanges.d.ts +2 -2
- package/utilities/findBreakingChanges.js +2 -2
- package/utilities/findBreakingChanges.mjs +2 -2
- package/utilities/getIntrospectionQuery.d.ts +9 -9
- package/utilities/getIntrospectionQuery.js +8 -8
- package/utilities/getIntrospectionQuery.mjs +8 -8
- package/utilities/getOperationAST.d.ts +2 -2
- package/utilities/getOperationAST.js +2 -2
- package/utilities/getOperationAST.mjs +2 -2
- package/utilities/getOperationRootType.d.ts +3 -1
- package/utilities/getOperationRootType.js +3 -1
- package/utilities/getOperationRootType.mjs +3 -1
- package/utilities/introspectionFromSchema.d.ts +12 -4
- package/utilities/introspectionFromSchema.js +12 -4
- package/utilities/introspectionFromSchema.mjs +12 -4
- package/utilities/lexicographicSortSchema.d.ts +17 -13
- package/utilities/lexicographicSortSchema.js +17 -13
- package/utilities/lexicographicSortSchema.mjs +17 -13
- package/utilities/printSchema.d.ts +7 -4
- package/utilities/printSchema.js +7 -4
- package/utilities/printSchema.mjs +7 -4
- package/utilities/resolveSchemaCoordinate.d.ts +9 -8
- package/utilities/resolveSchemaCoordinate.js +9 -8
- package/utilities/resolveSchemaCoordinate.mjs +9 -8
- package/utilities/separateOperations.d.ts +2 -2
- package/utilities/separateOperations.js +2 -2
- package/utilities/separateOperations.mjs +2 -2
- package/utilities/stripIgnoredCharacters.d.ts +19 -5
- package/utilities/stripIgnoredCharacters.js +19 -5
- package/utilities/stripIgnoredCharacters.mjs +19 -5
- package/utilities/typeComparators.d.ts +1 -5
- package/utilities/typeComparators.js +1 -5
- package/utilities/typeComparators.mjs +1 -5
- package/utilities/valueFromAST.js +4 -4
- package/utilities/valueFromAST.mjs +4 -4
- package/utilities/valueFromASTUntyped.d.ts +1 -3
- package/utilities/valueFromASTUntyped.js +1 -3
- package/utilities/valueFromASTUntyped.mjs +1 -3
- package/validation/ValidationContext.d.ts +22 -3
- package/validation/ValidationContext.js +84 -27
- package/validation/ValidationContext.mjs +82 -27
- package/validation/rules/ExecutableDefinitionsRule.d.ts +6 -4
- package/validation/rules/ExecutableDefinitionsRule.js +6 -4
- package/validation/rules/ExecutableDefinitionsRule.mjs +6 -4
- package/validation/rules/FieldsOnCorrectTypeRule.d.ts +4 -4
- package/validation/rules/FieldsOnCorrectTypeRule.js +10 -6
- package/validation/rules/FieldsOnCorrectTypeRule.mjs +12 -6
- package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +6 -4
- package/validation/rules/FragmentsOnCompositeTypesRule.js +6 -4
- package/validation/rules/FragmentsOnCompositeTypesRule.mjs +6 -4
- package/validation/rules/KnownArgumentNamesRule.d.ts +4 -4
- package/validation/rules/KnownArgumentNamesRule.js +26 -17
- package/validation/rules/KnownArgumentNamesRule.mjs +21 -11
- package/validation/rules/KnownDirectivesRule.d.ts +1 -3
- package/validation/rules/KnownDirectivesRule.js +1 -3
- package/validation/rules/KnownDirectivesRule.mjs +1 -3
- package/validation/rules/KnownFragmentNamesRule.d.ts +4 -4
- package/validation/rules/KnownFragmentNamesRule.js +4 -4
- package/validation/rules/KnownFragmentNamesRule.mjs +4 -4
- package/validation/rules/KnownTypeNamesRule.d.ts +1 -3
- package/validation/rules/KnownTypeNamesRule.js +7 -7
- package/validation/rules/KnownTypeNamesRule.mjs +7 -7
- package/validation/rules/LoneAnonymousOperationRule.d.ts +6 -4
- package/validation/rules/LoneAnonymousOperationRule.js +6 -4
- package/validation/rules/LoneAnonymousOperationRule.mjs +6 -4
- package/validation/rules/MaxIntrospectionDepthRule.d.ts +6 -4
- package/validation/rules/MaxIntrospectionDepthRule.js +44 -19
- package/validation/rules/MaxIntrospectionDepthRule.mjs +44 -19
- package/validation/rules/NoFragmentCyclesRule.d.ts +1 -3
- package/validation/rules/NoFragmentCyclesRule.js +1 -3
- package/validation/rules/NoFragmentCyclesRule.mjs +1 -3
- package/validation/rules/NoUndefinedVariablesRule.d.ts +4 -4
- package/validation/rules/NoUndefinedVariablesRule.js +4 -4
- package/validation/rules/NoUndefinedVariablesRule.mjs +4 -4
- package/validation/rules/NoUnusedFragmentsRule.d.ts +4 -4
- package/validation/rules/NoUnusedFragmentsRule.js +10 -14
- package/validation/rules/NoUnusedFragmentsRule.mjs +10 -14
- package/validation/rules/NoUnusedVariablesRule.d.ts +4 -4
- package/validation/rules/NoUnusedVariablesRule.js +4 -4
- package/validation/rules/NoUnusedVariablesRule.mjs +4 -4
- package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +8 -6
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +552 -354
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +545 -352
- package/validation/rules/PossibleFragmentSpreadsRule.d.ts +6 -4
- package/validation/rules/PossibleFragmentSpreadsRule.js +6 -4
- package/validation/rules/PossibleFragmentSpreadsRule.mjs +6 -4
- package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +6 -4
- package/validation/rules/ProvidedRequiredArgumentsRule.js +6 -4
- package/validation/rules/ProvidedRequiredArgumentsRule.mjs +6 -4
- package/validation/rules/ScalarLeafsRule.d.ts +1 -3
- package/validation/rules/ScalarLeafsRule.js +1 -3
- package/validation/rules/ScalarLeafsRule.mjs +1 -3
- package/validation/rules/SingleFieldSubscriptionsRule.d.ts +6 -4
- package/validation/rules/SingleFieldSubscriptionsRule.js +50 -9
- package/validation/rules/SingleFieldSubscriptionsRule.mjs +50 -9
- package/validation/rules/UniqueArgumentNamesRule.d.ts +4 -4
- package/validation/rules/UniqueArgumentNamesRule.js +4 -4
- package/validation/rules/UniqueArgumentNamesRule.mjs +4 -4
- package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +6 -4
- package/validation/rules/UniqueDirectivesPerLocationRule.js +6 -4
- package/validation/rules/UniqueDirectivesPerLocationRule.mjs +6 -4
- package/validation/rules/UniqueFragmentNamesRule.d.ts +4 -4
- package/validation/rules/UniqueFragmentNamesRule.js +4 -4
- package/validation/rules/UniqueFragmentNamesRule.mjs +4 -4
- package/validation/rules/UniqueInputFieldNamesRule.d.ts +6 -4
- package/validation/rules/UniqueInputFieldNamesRule.js +6 -4
- package/validation/rules/UniqueInputFieldNamesRule.mjs +6 -4
- package/validation/rules/UniqueOperationNamesRule.d.ts +4 -4
- package/validation/rules/UniqueOperationNamesRule.js +4 -4
- package/validation/rules/UniqueOperationNamesRule.mjs +4 -4
- package/validation/rules/UniqueVariableNamesRule.d.ts +4 -4
- package/validation/rules/UniqueVariableNamesRule.js +4 -4
- package/validation/rules/UniqueVariableNamesRule.mjs +4 -4
- package/validation/rules/ValuesOfCorrectTypeRule.d.ts +4 -4
- package/validation/rules/ValuesOfCorrectTypeRule.js +29 -23
- package/validation/rules/ValuesOfCorrectTypeRule.mjs +24 -14
- package/validation/rules/VariablesAreInputTypesRule.d.ts +6 -4
- package/validation/rules/VariablesAreInputTypesRule.js +6 -4
- package/validation/rules/VariablesAreInputTypesRule.mjs +6 -4
- package/validation/rules/VariablesInAllowedPositionRule.d.ts +6 -4
- package/validation/rules/VariablesInAllowedPositionRule.js +6 -4
- package/validation/rules/VariablesInAllowedPositionRule.mjs +6 -4
- package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +4 -4
- package/validation/rules/custom/NoDeprecatedCustomRule.js +4 -4
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs +4 -4
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +7 -5
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +7 -5
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +7 -5
- package/validation/validate.d.ts +2 -0
- package/validation/validate.js +14 -2
- package/validation/validate.mjs +13 -2
- package/validation/validationAbortedError.d.ts +3 -0
- package/validation/validationAbortedError.js +14 -0
- package/validation/validationAbortedError.mjs +4 -0
- package/version.js +3 -3
- package/version.mjs +3 -3
|
@@ -32,6 +32,7 @@ var _definition = require('../type/definition.js');
|
|
|
32
32
|
* @param inputValue - JavaScript value to coerce.
|
|
33
33
|
* @param type - GraphQL input type to coerce the value against.
|
|
34
34
|
* @param onError - Callback invoked for each coercion error.
|
|
35
|
+
* @param hideSuggestions - Omit suggestions from error messages.
|
|
35
36
|
* @returns Coerced value, or undefined if coercion failed and errors were reported.
|
|
36
37
|
* @example
|
|
37
38
|
* ```ts
|
|
@@ -53,7 +54,7 @@ var _definition = require('../type/definition.js');
|
|
|
53
54
|
* },
|
|
54
55
|
* });
|
|
55
56
|
*
|
|
56
|
-
* coerceInputValue({ stars:
|
|
57
|
+
* coerceInputValue({ stars: 5, tags: ['featured'] }, ReviewInput); // => { stars: 5, tags: ['featured'] }
|
|
57
58
|
* coerceInputValue({ stars: 'bad' }, ReviewInput); // throws an error
|
|
58
59
|
* ```
|
|
59
60
|
* @example
|
|
@@ -62,7 +63,11 @@ var _definition = require('../type/definition.js');
|
|
|
62
63
|
* import { GraphQLInt, GraphQLNonNull } from 'graphql/type';
|
|
63
64
|
* import { coerceInputValue } from 'graphql/utilities';
|
|
64
65
|
*
|
|
65
|
-
* const errors
|
|
66
|
+
* const errors: Array<{
|
|
67
|
+
* path: ReadonlyArray<string | number>;
|
|
68
|
+
* invalidValue: unknown;
|
|
69
|
+
* message: string;
|
|
70
|
+
* }> = [];
|
|
66
71
|
* const value = coerceInputValue(
|
|
67
72
|
* null,
|
|
68
73
|
* new GraphQLNonNull(GraphQLInt),
|
|
@@ -75,8 +80,19 @@ var _definition = require('../type/definition.js');
|
|
|
75
80
|
* errors; // => [ { path: [], invalidValue: null, message: 'Expected non-nullable type "Int!" not to be null.' } ]
|
|
76
81
|
* ```
|
|
77
82
|
*/
|
|
78
|
-
function coerceInputValue(
|
|
79
|
-
|
|
83
|
+
function coerceInputValue(
|
|
84
|
+
inputValue,
|
|
85
|
+
type,
|
|
86
|
+
onError = defaultOnError,
|
|
87
|
+
hideSuggestions,
|
|
88
|
+
) {
|
|
89
|
+
return coerceInputValueImpl(
|
|
90
|
+
inputValue,
|
|
91
|
+
type,
|
|
92
|
+
onError,
|
|
93
|
+
undefined,
|
|
94
|
+
hideSuggestions,
|
|
95
|
+
);
|
|
80
96
|
}
|
|
81
97
|
|
|
82
98
|
function defaultOnError(path, invalidValue, error) {
|
|
@@ -90,10 +106,22 @@ function defaultOnError(path, invalidValue, error) {
|
|
|
90
106
|
throw error;
|
|
91
107
|
}
|
|
92
108
|
|
|
93
|
-
function coerceInputValueImpl(
|
|
109
|
+
function coerceInputValueImpl(
|
|
110
|
+
inputValue,
|
|
111
|
+
type,
|
|
112
|
+
onError,
|
|
113
|
+
path,
|
|
114
|
+
hideSuggestions,
|
|
115
|
+
) {
|
|
94
116
|
if ((0, _definition.isNonNullType)(type)) {
|
|
95
117
|
if (inputValue != null) {
|
|
96
|
-
return coerceInputValueImpl(
|
|
118
|
+
return coerceInputValueImpl(
|
|
119
|
+
inputValue,
|
|
120
|
+
type.ofType,
|
|
121
|
+
onError,
|
|
122
|
+
path,
|
|
123
|
+
hideSuggestions,
|
|
124
|
+
);
|
|
97
125
|
}
|
|
98
126
|
|
|
99
127
|
onError(
|
|
@@ -119,11 +147,25 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
|
|
|
119
147
|
if ((0, _isIterableObject.isIterableObject)(inputValue)) {
|
|
120
148
|
return Array.from(inputValue, (itemValue, index) => {
|
|
121
149
|
const itemPath = (0, _Path.addPath)(path, index, undefined);
|
|
122
|
-
return coerceInputValueImpl(
|
|
150
|
+
return coerceInputValueImpl(
|
|
151
|
+
itemValue,
|
|
152
|
+
itemType,
|
|
153
|
+
onError,
|
|
154
|
+
itemPath,
|
|
155
|
+
hideSuggestions,
|
|
156
|
+
);
|
|
123
157
|
});
|
|
124
158
|
} // Lists accept a non-list value as a list of one.
|
|
125
159
|
|
|
126
|
-
return [
|
|
160
|
+
return [
|
|
161
|
+
coerceInputValueImpl(
|
|
162
|
+
inputValue,
|
|
163
|
+
itemType,
|
|
164
|
+
onError,
|
|
165
|
+
path,
|
|
166
|
+
hideSuggestions,
|
|
167
|
+
),
|
|
168
|
+
];
|
|
127
169
|
}
|
|
128
170
|
|
|
129
171
|
if ((0, _definition.isInputObjectType)(type)) {
|
|
@@ -169,15 +211,18 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
|
|
|
169
211
|
field.type,
|
|
170
212
|
onError,
|
|
171
213
|
(0, _Path.addPath)(path, field.name, type.name),
|
|
214
|
+
hideSuggestions,
|
|
172
215
|
);
|
|
173
216
|
} // Ensure every provided field is defined.
|
|
174
217
|
|
|
175
218
|
for (const fieldName of Object.keys(inputValue)) {
|
|
176
219
|
if (!fieldDefs[fieldName]) {
|
|
177
|
-
const suggestions =
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
220
|
+
const suggestions = hideSuggestions
|
|
221
|
+
? []
|
|
222
|
+
: (0, _suggestionList.suggestionList)(
|
|
223
|
+
fieldName,
|
|
224
|
+
Object.keys(type.getFields()),
|
|
225
|
+
);
|
|
181
226
|
onError(
|
|
182
227
|
(0, _Path.pathToArray)(path),
|
|
183
228
|
inputValue,
|
|
@@ -223,7 +268,9 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
|
|
|
223
268
|
// to the original error.
|
|
224
269
|
|
|
225
270
|
try {
|
|
226
|
-
parseResult =
|
|
271
|
+
parseResult = (0, _definition.isEnumType)(type)
|
|
272
|
+
? type.parseValue(inputValue, hideSuggestions)
|
|
273
|
+
: type.parseValue(inputValue);
|
|
227
274
|
} catch (error) {
|
|
228
275
|
if (error instanceof _GraphQLError.GraphQLError) {
|
|
229
276
|
onError((0, _Path.pathToArray)(path), inputValue, error);
|
|
@@ -9,6 +9,7 @@ import { printPathArray } from '../jsutils/printPathArray.mjs';
|
|
|
9
9
|
import { suggestionList } from '../jsutils/suggestionList.mjs';
|
|
10
10
|
import { GraphQLError } from '../error/GraphQLError.mjs';
|
|
11
11
|
import {
|
|
12
|
+
isEnumType,
|
|
12
13
|
isInputObjectType,
|
|
13
14
|
isLeafType,
|
|
14
15
|
isListType,
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
* @param inputValue - JavaScript value to coerce.
|
|
21
22
|
* @param type - GraphQL input type to coerce the value against.
|
|
22
23
|
* @param onError - Callback invoked for each coercion error.
|
|
24
|
+
* @param hideSuggestions - Omit suggestions from error messages.
|
|
23
25
|
* @returns Coerced value, or undefined if coercion failed and errors were reported.
|
|
24
26
|
* @example
|
|
25
27
|
* ```ts
|
|
@@ -41,7 +43,7 @@ import {
|
|
|
41
43
|
* },
|
|
42
44
|
* });
|
|
43
45
|
*
|
|
44
|
-
* coerceInputValue({ stars:
|
|
46
|
+
* coerceInputValue({ stars: 5, tags: ['featured'] }, ReviewInput); // => { stars: 5, tags: ['featured'] }
|
|
45
47
|
* coerceInputValue({ stars: 'bad' }, ReviewInput); // throws an error
|
|
46
48
|
* ```
|
|
47
49
|
* @example
|
|
@@ -50,7 +52,11 @@ import {
|
|
|
50
52
|
* import { GraphQLInt, GraphQLNonNull } from 'graphql/type';
|
|
51
53
|
* import { coerceInputValue } from 'graphql/utilities';
|
|
52
54
|
*
|
|
53
|
-
* const errors
|
|
55
|
+
* const errors: Array<{
|
|
56
|
+
* path: ReadonlyArray<string | number>;
|
|
57
|
+
* invalidValue: unknown;
|
|
58
|
+
* message: string;
|
|
59
|
+
* }> = [];
|
|
54
60
|
* const value = coerceInputValue(
|
|
55
61
|
* null,
|
|
56
62
|
* new GraphQLNonNull(GraphQLInt),
|
|
@@ -63,8 +69,19 @@ import {
|
|
|
63
69
|
* errors; // => [ { path: [], invalidValue: null, message: 'Expected non-nullable type "Int!" not to be null.' } ]
|
|
64
70
|
* ```
|
|
65
71
|
*/
|
|
66
|
-
export function coerceInputValue(
|
|
67
|
-
|
|
72
|
+
export function coerceInputValue(
|
|
73
|
+
inputValue,
|
|
74
|
+
type,
|
|
75
|
+
onError = defaultOnError,
|
|
76
|
+
hideSuggestions,
|
|
77
|
+
) {
|
|
78
|
+
return coerceInputValueImpl(
|
|
79
|
+
inputValue,
|
|
80
|
+
type,
|
|
81
|
+
onError,
|
|
82
|
+
undefined,
|
|
83
|
+
hideSuggestions,
|
|
84
|
+
);
|
|
68
85
|
}
|
|
69
86
|
|
|
70
87
|
function defaultOnError(path, invalidValue, error) {
|
|
@@ -78,10 +95,22 @@ function defaultOnError(path, invalidValue, error) {
|
|
|
78
95
|
throw error;
|
|
79
96
|
}
|
|
80
97
|
|
|
81
|
-
function coerceInputValueImpl(
|
|
98
|
+
function coerceInputValueImpl(
|
|
99
|
+
inputValue,
|
|
100
|
+
type,
|
|
101
|
+
onError,
|
|
102
|
+
path,
|
|
103
|
+
hideSuggestions,
|
|
104
|
+
) {
|
|
82
105
|
if (isNonNullType(type)) {
|
|
83
106
|
if (inputValue != null) {
|
|
84
|
-
return coerceInputValueImpl(
|
|
107
|
+
return coerceInputValueImpl(
|
|
108
|
+
inputValue,
|
|
109
|
+
type.ofType,
|
|
110
|
+
onError,
|
|
111
|
+
path,
|
|
112
|
+
hideSuggestions,
|
|
113
|
+
);
|
|
85
114
|
}
|
|
86
115
|
|
|
87
116
|
onError(
|
|
@@ -105,11 +134,25 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
|
|
|
105
134
|
if (isIterableObject(inputValue)) {
|
|
106
135
|
return Array.from(inputValue, (itemValue, index) => {
|
|
107
136
|
const itemPath = addPath(path, index, undefined);
|
|
108
|
-
return coerceInputValueImpl(
|
|
137
|
+
return coerceInputValueImpl(
|
|
138
|
+
itemValue,
|
|
139
|
+
itemType,
|
|
140
|
+
onError,
|
|
141
|
+
itemPath,
|
|
142
|
+
hideSuggestions,
|
|
143
|
+
);
|
|
109
144
|
});
|
|
110
145
|
} // Lists accept a non-list value as a list of one.
|
|
111
146
|
|
|
112
|
-
return [
|
|
147
|
+
return [
|
|
148
|
+
coerceInputValueImpl(
|
|
149
|
+
inputValue,
|
|
150
|
+
itemType,
|
|
151
|
+
onError,
|
|
152
|
+
path,
|
|
153
|
+
hideSuggestions,
|
|
154
|
+
),
|
|
155
|
+
];
|
|
113
156
|
}
|
|
114
157
|
|
|
115
158
|
if (isInputObjectType(type)) {
|
|
@@ -150,15 +193,15 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
|
|
|
150
193
|
field.type,
|
|
151
194
|
onError,
|
|
152
195
|
addPath(path, field.name, type.name),
|
|
196
|
+
hideSuggestions,
|
|
153
197
|
);
|
|
154
198
|
} // Ensure every provided field is defined.
|
|
155
199
|
|
|
156
200
|
for (const fieldName of Object.keys(inputValue)) {
|
|
157
201
|
if (!fieldDefs[fieldName]) {
|
|
158
|
-
const suggestions =
|
|
159
|
-
|
|
160
|
-
Object.keys(type.getFields())
|
|
161
|
-
);
|
|
202
|
+
const suggestions = hideSuggestions
|
|
203
|
+
? []
|
|
204
|
+
: suggestionList(fieldName, Object.keys(type.getFields()));
|
|
162
205
|
onError(
|
|
163
206
|
pathToArray(path),
|
|
164
207
|
inputValue,
|
|
@@ -204,7 +247,9 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
|
|
|
204
247
|
// to the original error.
|
|
205
248
|
|
|
206
249
|
try {
|
|
207
|
-
parseResult = type
|
|
250
|
+
parseResult = isEnumType(type)
|
|
251
|
+
? type.parseValue(inputValue, hideSuggestions)
|
|
252
|
+
: type.parseValue(inputValue);
|
|
208
253
|
} catch (error) {
|
|
209
254
|
if (error instanceof GraphQLError) {
|
|
210
255
|
onError(pathToArray(path), inputValue, error);
|
package/utilities/concatAST.d.ts
CHANGED
|
@@ -11,7 +11,10 @@ import type { DocumentNode } from '../language/ast';
|
|
|
11
11
|
* import { parse } from 'graphql/language';
|
|
12
12
|
* import { concatAST } from 'graphql/utilities';
|
|
13
13
|
*
|
|
14
|
-
* const document = concatAST([
|
|
14
|
+
* const document = concatAST([
|
|
15
|
+
* parse('type Query { a: String }'),
|
|
16
|
+
* parse('type User { id: ID }'),
|
|
17
|
+
* ]);
|
|
15
18
|
*
|
|
16
19
|
* document.definitions.length; // => 2
|
|
17
20
|
* ```
|
package/utilities/concatAST.js
CHANGED
|
@@ -20,7 +20,10 @@ var _kinds = require('../language/kinds.js');
|
|
|
20
20
|
* import { parse } from 'graphql/language';
|
|
21
21
|
* import { concatAST } from 'graphql/utilities';
|
|
22
22
|
*
|
|
23
|
-
* const document = concatAST([
|
|
23
|
+
* const document = concatAST([
|
|
24
|
+
* parse('type Query { a: String }'),
|
|
25
|
+
* parse('type User { id: ID }'),
|
|
26
|
+
* ]);
|
|
24
27
|
*
|
|
25
28
|
* document.definitions.length; // => 2
|
|
26
29
|
* ```
|
package/utilities/concatAST.mjs
CHANGED
|
@@ -11,7 +11,10 @@ import { Kind } from '../language/kinds.mjs';
|
|
|
11
11
|
* import { parse } from 'graphql/language';
|
|
12
12
|
* import { concatAST } from 'graphql/utilities';
|
|
13
13
|
*
|
|
14
|
-
* const document = concatAST([
|
|
14
|
+
* const document = concatAST([
|
|
15
|
+
* parse('type Query { a: String }'),
|
|
16
|
+
* parse('type User { id: ID }'),
|
|
17
|
+
* ]);
|
|
15
18
|
*
|
|
16
19
|
* document.definitions.length; // => 2
|
|
17
20
|
* ```
|
|
@@ -31,6 +31,7 @@ interface Options extends GraphQLSchemaValidationOptions {
|
|
|
31
31
|
* @example
|
|
32
32
|
* ```ts
|
|
33
33
|
* // Extend a schema with new fields and types.
|
|
34
|
+
* import assert from 'node:assert/strict';
|
|
34
35
|
* import { parse } from 'graphql/language';
|
|
35
36
|
* import { buildSchema, extendSchema } from 'graphql/utilities';
|
|
36
37
|
*
|
|
@@ -53,7 +54,9 @@ interface Options extends GraphQLSchemaValidationOptions {
|
|
|
53
54
|
*
|
|
54
55
|
* schema.getType('Review'); // => undefined
|
|
55
56
|
* extendedSchema.getType('Review')?.name; // => 'Review'
|
|
56
|
-
*
|
|
57
|
+
* const queryType = extendedSchema.getQueryType();
|
|
58
|
+
* assert(queryType);
|
|
59
|
+
* Object.keys(queryType.getFields()); // => ['greeting', 'farewell']
|
|
57
60
|
* ```
|
|
58
61
|
* @example
|
|
59
62
|
* ```ts
|
|
@@ -74,9 +77,9 @@ interface Options extends GraphQLSchemaValidationOptions {
|
|
|
74
77
|
*
|
|
75
78
|
* extendSchema(schema, invalidExtension); // throws an error
|
|
76
79
|
* extendSchema(schema, invalidExtension, {
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
+
* assumeValid: true,
|
|
81
|
+
* assumeValidSDL: true,
|
|
82
|
+
* }); // does not throw
|
|
80
83
|
* ```
|
|
81
84
|
*/
|
|
82
85
|
export declare function extendSchema(
|
|
@@ -56,6 +56,7 @@ var _valueFromAST = require('./valueFromAST.js');
|
|
|
56
56
|
* @example
|
|
57
57
|
* ```ts
|
|
58
58
|
* // Extend a schema with new fields and types.
|
|
59
|
+
* import assert from 'node:assert/strict';
|
|
59
60
|
* import { parse } from 'graphql/language';
|
|
60
61
|
* import { buildSchema, extendSchema } from 'graphql/utilities';
|
|
61
62
|
*
|
|
@@ -78,7 +79,9 @@ var _valueFromAST = require('./valueFromAST.js');
|
|
|
78
79
|
*
|
|
79
80
|
* schema.getType('Review'); // => undefined
|
|
80
81
|
* extendedSchema.getType('Review')?.name; // => 'Review'
|
|
81
|
-
*
|
|
82
|
+
* const queryType = extendedSchema.getQueryType();
|
|
83
|
+
* assert(queryType);
|
|
84
|
+
* Object.keys(queryType.getFields()); // => ['greeting', 'farewell']
|
|
82
85
|
* ```
|
|
83
86
|
* @example
|
|
84
87
|
* ```ts
|
|
@@ -99,9 +102,9 @@ var _valueFromAST = require('./valueFromAST.js');
|
|
|
99
102
|
*
|
|
100
103
|
* extendSchema(schema, invalidExtension); // throws an error
|
|
101
104
|
* extendSchema(schema, invalidExtension, {
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
+
* assumeValid: true,
|
|
106
|
+
* assumeValidSDL: true,
|
|
107
|
+
* }); // does not throw
|
|
105
108
|
* ```
|
|
106
109
|
*/
|
|
107
110
|
function extendSchema(schema, documentAST, options) {
|
|
@@ -64,6 +64,7 @@ import { valueFromAST } from './valueFromAST.mjs';
|
|
|
64
64
|
* @example
|
|
65
65
|
* ```ts
|
|
66
66
|
* // Extend a schema with new fields and types.
|
|
67
|
+
* import assert from 'node:assert/strict';
|
|
67
68
|
* import { parse } from 'graphql/language';
|
|
68
69
|
* import { buildSchema, extendSchema } from 'graphql/utilities';
|
|
69
70
|
*
|
|
@@ -86,7 +87,9 @@ import { valueFromAST } from './valueFromAST.mjs';
|
|
|
86
87
|
*
|
|
87
88
|
* schema.getType('Review'); // => undefined
|
|
88
89
|
* extendedSchema.getType('Review')?.name; // => 'Review'
|
|
89
|
-
*
|
|
90
|
+
* const queryType = extendedSchema.getQueryType();
|
|
91
|
+
* assert(queryType);
|
|
92
|
+
* Object.keys(queryType.getFields()); // => ['greeting', 'farewell']
|
|
90
93
|
* ```
|
|
91
94
|
* @example
|
|
92
95
|
* ```ts
|
|
@@ -107,9 +110,9 @@ import { valueFromAST } from './valueFromAST.mjs';
|
|
|
107
110
|
*
|
|
108
111
|
* extendSchema(schema, invalidExtension); // throws an error
|
|
109
112
|
* extendSchema(schema, invalidExtension, {
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
+
* assumeValid: true,
|
|
114
|
+
* assumeValidSDL: true,
|
|
115
|
+
* }); // does not throw
|
|
113
116
|
* ```
|
|
114
117
|
*/
|
|
115
118
|
export function extendSchema(schema, documentAST, options) {
|
|
@@ -99,7 +99,7 @@ export interface DangerousChange {
|
|
|
99
99
|
* const changes = findBreakingChanges(oldSchema, newSchema);
|
|
100
100
|
*
|
|
101
101
|
* changes[0].type; // => 'FIELD_REMOVED'
|
|
102
|
-
* changes[0].description
|
|
102
|
+
* changes[0].description.includes('User.name was removed'); // => true
|
|
103
103
|
* ```
|
|
104
104
|
*/
|
|
105
105
|
export declare function findBreakingChanges(
|
|
@@ -139,7 +139,7 @@ export declare function findBreakingChanges(
|
|
|
139
139
|
* const changes = findDangerousChanges(oldSchema, newSchema);
|
|
140
140
|
*
|
|
141
141
|
* changes[0].type; // => 'VALUE_ADDED_TO_ENUM'
|
|
142
|
-
* changes[0].description; //
|
|
142
|
+
* changes[0].description.includes('EMPIRE was added'); // => true
|
|
143
143
|
* ```
|
|
144
144
|
*/
|
|
145
145
|
export declare function findDangerousChanges(
|
|
@@ -106,7 +106,7 @@ exports.DangerousChangeType = DangerousChangeType;
|
|
|
106
106
|
* const changes = findBreakingChanges(oldSchema, newSchema);
|
|
107
107
|
*
|
|
108
108
|
* changes[0].type; // => 'FIELD_REMOVED'
|
|
109
|
-
* changes[0].description
|
|
109
|
+
* changes[0].description.includes('User.name was removed'); // => true
|
|
110
110
|
* ```
|
|
111
111
|
*/
|
|
112
112
|
function findBreakingChanges(oldSchema, newSchema) {
|
|
@@ -148,7 +148,7 @@ function findBreakingChanges(oldSchema, newSchema) {
|
|
|
148
148
|
* const changes = findDangerousChanges(oldSchema, newSchema);
|
|
149
149
|
*
|
|
150
150
|
* changes[0].type; // => 'VALUE_ADDED_TO_ENUM'
|
|
151
|
-
* changes[0].description; //
|
|
151
|
+
* changes[0].description.includes('EMPIRE was added'); // => true
|
|
152
152
|
* ```
|
|
153
153
|
*/
|
|
154
154
|
|
|
@@ -99,7 +99,7 @@ export { DangerousChangeType };
|
|
|
99
99
|
* const changes = findBreakingChanges(oldSchema, newSchema);
|
|
100
100
|
*
|
|
101
101
|
* changes[0].type; // => 'FIELD_REMOVED'
|
|
102
|
-
* changes[0].description
|
|
102
|
+
* changes[0].description.includes('User.name was removed'); // => true
|
|
103
103
|
* ```
|
|
104
104
|
*/
|
|
105
105
|
export function findBreakingChanges(oldSchema, newSchema) {
|
|
@@ -141,7 +141,7 @@ export function findBreakingChanges(oldSchema, newSchema) {
|
|
|
141
141
|
* const changes = findDangerousChanges(oldSchema, newSchema);
|
|
142
142
|
*
|
|
143
143
|
* changes[0].type; // => 'VALUE_ADDED_TO_ENUM'
|
|
144
|
-
* changes[0].description; //
|
|
144
|
+
* changes[0].description.includes('EMPIRE was added'); // => true
|
|
145
145
|
* ```
|
|
146
146
|
*/
|
|
147
147
|
|
|
@@ -60,9 +60,9 @@ export interface IntrospectionOptions {
|
|
|
60
60
|
*
|
|
61
61
|
* const query = getIntrospectionQuery();
|
|
62
62
|
*
|
|
63
|
-
* query; //
|
|
64
|
-
* query; //
|
|
65
|
-
* query; //
|
|
63
|
+
* query.includes('__schema'); // => true
|
|
64
|
+
* query.includes('description'); // => true
|
|
65
|
+
* query.includes('specifiedByURL'); // => false
|
|
66
66
|
* ```
|
|
67
67
|
* @example
|
|
68
68
|
* ```ts
|
|
@@ -80,11 +80,11 @@ export interface IntrospectionOptions {
|
|
|
80
80
|
* typeDepth: 3,
|
|
81
81
|
* });
|
|
82
82
|
*
|
|
83
|
-
* query; //
|
|
84
|
-
* query; //
|
|
85
|
-
* query; //
|
|
86
|
-
* query; //
|
|
87
|
-
* query; //
|
|
83
|
+
* query.includes('description'); // => false
|
|
84
|
+
* query.includes('specifiedByURL'); // => true
|
|
85
|
+
* query.includes('isRepeatable'); // => true
|
|
86
|
+
* query.includes('includeDeprecated: true'); // => true
|
|
87
|
+
* query.includes('isOneOf'); // => true
|
|
88
88
|
* (query.match(/ofType/g)?.length ?? 0) > 0; // => true
|
|
89
89
|
* ```
|
|
90
90
|
*/
|
|
@@ -110,7 +110,7 @@ export interface IntrospectionSchema {
|
|
|
110
110
|
readonly subscriptionType: Maybe<
|
|
111
111
|
IntrospectionNamedTypeRef<IntrospectionObjectType>
|
|
112
112
|
>;
|
|
113
|
-
/**
|
|
113
|
+
/** All named types that belong to this schema. */
|
|
114
114
|
readonly types: ReadonlyArray<IntrospectionType>;
|
|
115
115
|
/** Directives available in this schema or applied to this AST node. */
|
|
116
116
|
readonly directives: ReadonlyArray<IntrospectionDirective>;
|
|
@@ -21,9 +21,9 @@ exports.getIntrospectionQuery = getIntrospectionQuery;
|
|
|
21
21
|
*
|
|
22
22
|
* const query = getIntrospectionQuery();
|
|
23
23
|
*
|
|
24
|
-
* query; //
|
|
25
|
-
* query; //
|
|
26
|
-
* query; //
|
|
24
|
+
* query.includes('__schema'); // => true
|
|
25
|
+
* query.includes('description'); // => true
|
|
26
|
+
* query.includes('specifiedByURL'); // => false
|
|
27
27
|
* ```
|
|
28
28
|
* @example
|
|
29
29
|
* ```ts
|
|
@@ -41,11 +41,11 @@ exports.getIntrospectionQuery = getIntrospectionQuery;
|
|
|
41
41
|
* typeDepth: 3,
|
|
42
42
|
* });
|
|
43
43
|
*
|
|
44
|
-
* query; //
|
|
45
|
-
* query; //
|
|
46
|
-
* query; //
|
|
47
|
-
* query; //
|
|
48
|
-
* query; //
|
|
44
|
+
* query.includes('description'); // => false
|
|
45
|
+
* query.includes('specifiedByURL'); // => true
|
|
46
|
+
* query.includes('isRepeatable'); // => true
|
|
47
|
+
* query.includes('includeDeprecated: true'); // => true
|
|
48
|
+
* query.includes('isOneOf'); // => true
|
|
49
49
|
* (query.match(/ofType/g)?.length ?? 0) > 0; // => true
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
*
|
|
15
15
|
* const query = getIntrospectionQuery();
|
|
16
16
|
*
|
|
17
|
-
* query; //
|
|
18
|
-
* query; //
|
|
19
|
-
* query; //
|
|
17
|
+
* query.includes('__schema'); // => true
|
|
18
|
+
* query.includes('description'); // => true
|
|
19
|
+
* query.includes('specifiedByURL'); // => false
|
|
20
20
|
* ```
|
|
21
21
|
* @example
|
|
22
22
|
* ```ts
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
* typeDepth: 3,
|
|
35
35
|
* });
|
|
36
36
|
*
|
|
37
|
-
* query; //
|
|
38
|
-
* query; //
|
|
39
|
-
* query; //
|
|
40
|
-
* query; //
|
|
41
|
-
* query; //
|
|
37
|
+
* query.includes('description'); // => false
|
|
38
|
+
* query.includes('specifiedByURL'); // => true
|
|
39
|
+
* query.includes('isRepeatable'); // => true
|
|
40
|
+
* query.includes('includeDeprecated: true'); // => true
|
|
41
|
+
* query.includes('isOneOf'); // => true
|
|
42
42
|
* (query.match(/ofType/g)?.length ?? 0) > 0; // => true
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
@@ -16,8 +16,8 @@ import type { DocumentNode, OperationDefinitionNode } from '../language/ast';
|
|
|
16
16
|
* const document = parse('query GetName { name }');
|
|
17
17
|
* const operation = getOperationAST(document, 'GetName');
|
|
18
18
|
*
|
|
19
|
-
* operation
|
|
20
|
-
* getOperationAST(document, 'Missing'); // =>
|
|
19
|
+
* operation?.name?.value; // => 'GetName'
|
|
20
|
+
* getOperationAST(document, 'Missing'); // => null
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
export declare function getOperationAST(
|
|
@@ -24,8 +24,8 @@ var _kinds = require('../language/kinds.js');
|
|
|
24
24
|
* const document = parse('query GetName { name }');
|
|
25
25
|
* const operation = getOperationAST(document, 'GetName');
|
|
26
26
|
*
|
|
27
|
-
* operation
|
|
28
|
-
* getOperationAST(document, 'Missing'); // =>
|
|
27
|
+
* operation?.name?.value; // => 'GetName'
|
|
28
|
+
* getOperationAST(document, 'Missing'); // => null
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
function getOperationAST(documentAST, operationName) {
|
|
@@ -15,8 +15,8 @@ import { Kind } from '../language/kinds.mjs';
|
|
|
15
15
|
* const document = parse('query GetName { name }');
|
|
16
16
|
* const operation = getOperationAST(document, 'GetName');
|
|
17
17
|
*
|
|
18
|
-
* operation
|
|
19
|
-
* getOperationAST(document, 'Missing'); // =>
|
|
18
|
+
* operation?.name?.value; // => 'GetName'
|
|
19
|
+
* getOperationAST(document, 'Missing'); // => null
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
|
|
@@ -15,11 +15,13 @@ import type { GraphQLSchema } from '../type/schema';
|
|
|
15
15
|
* @returns The resolved operation root type.
|
|
16
16
|
* @example
|
|
17
17
|
* ```ts
|
|
18
|
+
* import assert from 'node:assert/strict';
|
|
18
19
|
* import { buildSchema, getOperationRootType } from 'graphql/utilities';
|
|
19
|
-
* import { parse } from 'graphql/language';
|
|
20
|
+
* import { parse, Kind } from 'graphql/language';
|
|
20
21
|
*
|
|
21
22
|
* const schema = buildSchema('type Query { name: String }');
|
|
22
23
|
* const operation = parse('{ name }').definitions[0];
|
|
24
|
+
* assert(operation.kind === Kind.OPERATION_DEFINITION);
|
|
23
25
|
* const rootType = getOperationRootType(schema, operation);
|
|
24
26
|
*
|
|
25
27
|
* rootType.name; // => 'Query'
|
|
@@ -19,11 +19,13 @@ var _GraphQLError = require('../error/GraphQLError.js');
|
|
|
19
19
|
* @returns The resolved operation root type.
|
|
20
20
|
* @example
|
|
21
21
|
* ```ts
|
|
22
|
+
* import assert from 'node:assert/strict';
|
|
22
23
|
* import { buildSchema, getOperationRootType } from 'graphql/utilities';
|
|
23
|
-
* import { parse } from 'graphql/language';
|
|
24
|
+
* import { parse, Kind } from 'graphql/language';
|
|
24
25
|
*
|
|
25
26
|
* const schema = buildSchema('type Query { name: String }');
|
|
26
27
|
* const operation = parse('{ name }').definitions[0];
|
|
28
|
+
* assert(operation.kind === Kind.OPERATION_DEFINITION);
|
|
27
29
|
* const rootType = getOperationRootType(schema, operation);
|
|
28
30
|
*
|
|
29
31
|
* rootType.name; // => 'Query'
|
|
@@ -11,11 +11,13 @@ import { GraphQLError } from '../error/GraphQLError.mjs';
|
|
|
11
11
|
* @returns The resolved operation root type.
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
14
|
+
* import assert from 'node:assert/strict';
|
|
14
15
|
* import { buildSchema, getOperationRootType } from 'graphql/utilities';
|
|
15
|
-
* import { parse } from 'graphql/language';
|
|
16
|
+
* import { parse, Kind } from 'graphql/language';
|
|
16
17
|
*
|
|
17
18
|
* const schema = buildSchema('type Query { name: String }');
|
|
18
19
|
* const operation = parse('{ name }').definitions[0];
|
|
20
|
+
* assert(operation.kind === Kind.OPERATION_DEFINITION);
|
|
19
21
|
* const rootType = getOperationRootType(schema, operation);
|
|
20
22
|
*
|
|
21
23
|
* rootType.name; // => 'Query'
|