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.
- 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 +190 -122
- package/type/definition.js +175 -102
- package/type/definition.mjs +174 -101
- package/type/directives.d.ts +14 -8
- package/type/directives.js +13 -7
- package/type/directives.mjs +13 -7
- package/type/scalars.js +8 -11
- package/type/scalars.mjs +1 -1
- package/type/schema.d.ts +38 -13
- package/type/schema.js +36 -11
- package/type/schema.mjs +36 -11
- 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
|
@@ -40,7 +40,15 @@ import { TokenKind } from '../language/tokenKind.mjs';
|
|
|
40
40
|
* Becomes:
|
|
41
41
|
*
|
|
42
42
|
* ```graphql
|
|
43
|
-
* query SomeQuery($foo:String
|
|
43
|
+
* query SomeQuery($foo: String!, $bar: String) {
|
|
44
|
+
* someField(foo: $foo, bar: $bar) {
|
|
45
|
+
* a
|
|
46
|
+
* b {
|
|
47
|
+
* c
|
|
48
|
+
* d
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
44
52
|
* ```
|
|
45
53
|
* @example SDL source
|
|
46
54
|
* ```graphql
|
|
@@ -58,15 +66,21 @@ import { TokenKind } from '../language/tokenKind.mjs';
|
|
|
58
66
|
* Becomes:
|
|
59
67
|
*
|
|
60
68
|
* ```graphql
|
|
61
|
-
* """
|
|
69
|
+
* """
|
|
70
|
+
* Type description
|
|
71
|
+
* """
|
|
72
|
+
* type Foo {
|
|
73
|
+
* """
|
|
74
|
+
* Field description
|
|
75
|
+
* """
|
|
76
|
+
* bar: String
|
|
77
|
+
* }
|
|
62
78
|
* ```
|
|
63
79
|
* @example
|
|
64
80
|
* ```ts
|
|
65
81
|
* import { stripIgnoredCharacters } from 'graphql/utilities';
|
|
66
82
|
*
|
|
67
|
-
* const source = stripIgnoredCharacters('query Example { name }');
|
|
68
|
-
*
|
|
69
|
-
* source; // => 'query Example{name}'
|
|
83
|
+
* const source = stripIgnoredCharacters('query Example { name }'); // => 'query Example{name}'
|
|
70
84
|
* ```
|
|
71
85
|
*/
|
|
72
86
|
|
|
@@ -8,11 +8,7 @@ import type { GraphQLSchema } from '../type/schema';
|
|
|
8
8
|
* @returns True when both types are equal.
|
|
9
9
|
* @example
|
|
10
10
|
* ```ts
|
|
11
|
-
* import {
|
|
12
|
-
* GraphQLList,
|
|
13
|
-
* GraphQLNonNull,
|
|
14
|
-
* GraphQLString,
|
|
15
|
-
* } from 'graphql/type';
|
|
11
|
+
* import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type';
|
|
16
12
|
* import { isEqualType } from 'graphql/utilities';
|
|
17
13
|
*
|
|
18
14
|
* isEqualType(GraphQLString, GraphQLString); // => true
|
|
@@ -18,11 +18,7 @@ var _definition = require('../type/definition.js');
|
|
|
18
18
|
* @returns True when both types are equal.
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
21
|
-
* import {
|
|
22
|
-
* GraphQLList,
|
|
23
|
-
* GraphQLNonNull,
|
|
24
|
-
* GraphQLString,
|
|
25
|
-
* } from 'graphql/type';
|
|
21
|
+
* import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type';
|
|
26
22
|
* import { isEqualType } from 'graphql/utilities';
|
|
27
23
|
*
|
|
28
24
|
* isEqualType(GraphQLString, GraphQLString); // => true
|
|
@@ -14,11 +14,7 @@ import {
|
|
|
14
14
|
* @returns True when both types are equal.
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
|
-
* import {
|
|
18
|
-
* GraphQLList,
|
|
19
|
-
* GraphQLNonNull,
|
|
20
|
-
* GraphQLString,
|
|
21
|
-
* } from 'graphql/type';
|
|
17
|
+
* import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type';
|
|
22
18
|
* import { isEqualType } from 'graphql/utilities';
|
|
23
19
|
*
|
|
24
20
|
* isEqualType(GraphQLString, GraphQLString); // => true
|
|
@@ -86,8 +86,8 @@ function valueFromAST(valueNode, type, variables) {
|
|
|
86
86
|
|
|
87
87
|
if (
|
|
88
88
|
variables == null ||
|
|
89
|
-
variables
|
|
90
|
-
|
|
89
|
+
!hasOwnProperty(variables, variableName) ||
|
|
90
|
+
variables[variableName] === undefined
|
|
91
91
|
) {
|
|
92
92
|
// No valid return value.
|
|
93
93
|
return;
|
|
@@ -236,8 +236,8 @@ function isMissingVariable(valueNode, variables) {
|
|
|
236
236
|
return (
|
|
237
237
|
valueNode.kind === _kinds.Kind.VARIABLE &&
|
|
238
238
|
(variables == null ||
|
|
239
|
-
variables
|
|
240
|
-
|
|
239
|
+
!hasOwnProperty(variables, valueNode.name.value) ||
|
|
240
|
+
variables[valueNode.name.value] === undefined)
|
|
241
241
|
);
|
|
242
242
|
}
|
|
243
243
|
|
|
@@ -79,8 +79,8 @@ export function valueFromAST(valueNode, type, variables) {
|
|
|
79
79
|
|
|
80
80
|
if (
|
|
81
81
|
variables == null ||
|
|
82
|
-
variables
|
|
83
|
-
|
|
82
|
+
!hasOwnProperty(variables, variableName) ||
|
|
83
|
+
variables[variableName] === undefined
|
|
84
84
|
) {
|
|
85
85
|
// No valid return value.
|
|
86
86
|
return;
|
|
@@ -222,8 +222,8 @@ function isMissingVariable(valueNode, variables) {
|
|
|
222
222
|
return (
|
|
223
223
|
valueNode.kind === Kind.VARIABLE &&
|
|
224
224
|
(variables == null ||
|
|
225
|
-
variables
|
|
226
|
-
|
|
225
|
+
!hasOwnProperty(variables, valueNode.name.value) ||
|
|
226
|
+
variables[valueNode.name.value] === undefined)
|
|
227
227
|
);
|
|
228
228
|
}
|
|
229
229
|
|
|
@@ -24,9 +24,7 @@ import type { ValueNode } from '../language/ast';
|
|
|
24
24
|
* import { parseValue } from 'graphql/language';
|
|
25
25
|
* import { valueFromASTUntyped } from 'graphql/utilities';
|
|
26
26
|
*
|
|
27
|
-
* const value = valueFromASTUntyped(parseValue('[1, 2, 3]'));
|
|
28
|
-
*
|
|
29
|
-
* value; // => [1, 2, 3]
|
|
27
|
+
* const value = valueFromASTUntyped(parseValue('[1, 2, 3]')); // => [1, 2, 3]
|
|
30
28
|
* valueFromASTUntyped(parseValue('$name'), { name: 'Ada' }); // => 'Ada'
|
|
31
29
|
* ```
|
|
32
30
|
*/
|
|
@@ -33,9 +33,7 @@ var _kinds = require('../language/kinds.js');
|
|
|
33
33
|
* import { parseValue } from 'graphql/language';
|
|
34
34
|
* import { valueFromASTUntyped } from 'graphql/utilities';
|
|
35
35
|
*
|
|
36
|
-
* const value = valueFromASTUntyped(parseValue('[1, 2, 3]'));
|
|
37
|
-
*
|
|
38
|
-
* value; // => [1, 2, 3]
|
|
36
|
+
* const value = valueFromASTUntyped(parseValue('[1, 2, 3]')); // => [1, 2, 3]
|
|
39
37
|
* valueFromASTUntyped(parseValue('$name'), { name: 'Ada' }); // => 'Ada'
|
|
40
38
|
* ```
|
|
41
39
|
*/
|
|
@@ -23,9 +23,7 @@ import { Kind } from '../language/kinds.mjs';
|
|
|
23
23
|
* import { parseValue } from 'graphql/language';
|
|
24
24
|
* import { valueFromASTUntyped } from 'graphql/utilities';
|
|
25
25
|
*
|
|
26
|
-
* const value = valueFromASTUntyped(parseValue('[1, 2, 3]'));
|
|
27
|
-
*
|
|
28
|
-
* value; // => [1, 2, 3]
|
|
26
|
+
* const value = valueFromASTUntyped(parseValue('[1, 2, 3]')); // => [1, 2, 3]
|
|
29
27
|
* valueFromASTUntyped(parseValue('$name'), { name: 'Ada' }); // => 'Ada'
|
|
30
28
|
* ```
|
|
31
29
|
*/
|
|
@@ -38,6 +38,7 @@ interface VariableUsage {
|
|
|
38
38
|
* @internal
|
|
39
39
|
*/
|
|
40
40
|
export declare class ASTValidationContext {
|
|
41
|
+
private _remainingFragmentWork;
|
|
41
42
|
private _ast;
|
|
42
43
|
private _onError;
|
|
43
44
|
private _fragments;
|
|
@@ -52,6 +53,11 @@ export declare class ASTValidationContext {
|
|
|
52
53
|
getRecursivelyReferencedFragments(
|
|
53
54
|
operation: OperationDefinitionNode,
|
|
54
55
|
): ReadonlyArray<FragmentDefinitionNode>;
|
|
56
|
+
getRecursivelyReferencedFragmentsForOperations(
|
|
57
|
+
operations: ReadonlyArray<OperationDefinitionNode>,
|
|
58
|
+
): ReadonlyArray<FragmentDefinitionNode>;
|
|
59
|
+
/** @internal */
|
|
60
|
+
spendFragmentWork(cost: number): void;
|
|
55
61
|
}
|
|
56
62
|
/** @internal */
|
|
57
63
|
export declare type ASTValidationRule = (
|
|
@@ -65,6 +71,7 @@ export declare class SDLValidationContext extends ASTValidationContext {
|
|
|
65
71
|
schema: Maybe<GraphQLSchema>,
|
|
66
72
|
onError: (error: GraphQLError) => void,
|
|
67
73
|
);
|
|
74
|
+
get hideSuggestions(): boolean;
|
|
68
75
|
get [Symbol.toStringTag](): string;
|
|
69
76
|
getSchema(): Maybe<GraphQLSchema>;
|
|
70
77
|
}
|
|
@@ -74,6 +81,7 @@ export declare type SDLValidationRule = (
|
|
|
74
81
|
) => ASTVisitor;
|
|
75
82
|
/** Validation context passed to query validation rules. */
|
|
76
83
|
export declare class ValidationContext extends ASTValidationContext {
|
|
84
|
+
private _hideSuggestions;
|
|
77
85
|
private _schema;
|
|
78
86
|
private _typeInfo;
|
|
79
87
|
private _variableUsages;
|
|
@@ -84,6 +92,7 @@ export declare class ValidationContext extends ASTValidationContext {
|
|
|
84
92
|
* @param ast - Document AST being validated.
|
|
85
93
|
* @param typeInfo - TypeInfo instance used to track traversal state.
|
|
86
94
|
* @param onError - Callback invoked for each validation error.
|
|
95
|
+
* @param hideSuggestions - Omit suggestions from error messages.
|
|
87
96
|
* @example
|
|
88
97
|
* ```ts
|
|
89
98
|
* import { parse } from 'graphql/language';
|
|
@@ -97,7 +106,7 @@ export declare class ValidationContext extends ASTValidationContext {
|
|
|
97
106
|
* }
|
|
98
107
|
* `);
|
|
99
108
|
* const document = parse('{ greeting }');
|
|
100
|
-
* const errors = [];
|
|
109
|
+
* const errors: Array<GraphQLError> = [];
|
|
101
110
|
* const context = new ValidationContext(
|
|
102
111
|
* schema,
|
|
103
112
|
* document,
|
|
@@ -116,7 +125,13 @@ export declare class ValidationContext extends ASTValidationContext {
|
|
|
116
125
|
ast: DocumentNode,
|
|
117
126
|
typeInfo: TypeInfo,
|
|
118
127
|
onError: (error: GraphQLError) => void,
|
|
128
|
+
hideSuggestions?: Maybe<boolean>,
|
|
119
129
|
);
|
|
130
|
+
/**
|
|
131
|
+
* Whether suggestions should be omitted from validation errors.
|
|
132
|
+
* @returns True when validation error suggestions are disabled.
|
|
133
|
+
*/
|
|
134
|
+
get hideSuggestions(): boolean;
|
|
120
135
|
/**
|
|
121
136
|
* Returns the value used by `Object.prototype.toString`.
|
|
122
137
|
* @returns The built-in string tag for this object.
|
|
@@ -153,7 +168,8 @@ export declare class ValidationContext extends ASTValidationContext {
|
|
|
153
168
|
* @returns Variable usages found directly within this node.
|
|
154
169
|
* @example
|
|
155
170
|
* ```ts
|
|
156
|
-
* import
|
|
171
|
+
* import assert from 'node:assert/strict';
|
|
172
|
+
* import { parse, Kind } from 'graphql/language';
|
|
157
173
|
* import { buildSchema, TypeInfo } from 'graphql/utilities';
|
|
158
174
|
* import { ValidationContext } from 'graphql/validation';
|
|
159
175
|
*
|
|
@@ -164,6 +180,7 @@ export declare class ValidationContext extends ASTValidationContext {
|
|
|
164
180
|
* `);
|
|
165
181
|
* const document = parse('query ($name: String) { greeting(name: $name) }');
|
|
166
182
|
* const operation = document.definitions[0];
|
|
183
|
+
* assert(operation.kind === Kind.OPERATION_DEFINITION);
|
|
167
184
|
* const context = new ValidationContext(
|
|
168
185
|
* schema,
|
|
169
186
|
* document,
|
|
@@ -184,7 +201,8 @@ export declare class ValidationContext extends ASTValidationContext {
|
|
|
184
201
|
* @returns Variable usages reachable from the operation.
|
|
185
202
|
* @example
|
|
186
203
|
* ```ts
|
|
187
|
-
* import
|
|
204
|
+
* import assert from 'node:assert/strict';
|
|
205
|
+
* import { parse, Kind } from 'graphql/language';
|
|
188
206
|
* import { buildSchema, TypeInfo } from 'graphql/utilities';
|
|
189
207
|
* import { ValidationContext } from 'graphql/validation';
|
|
190
208
|
*
|
|
@@ -209,6 +227,7 @@ export declare class ValidationContext extends ASTValidationContext {
|
|
|
209
227
|
* }
|
|
210
228
|
* `);
|
|
211
229
|
* const operation = document.definitions[0];
|
|
230
|
+
* assert(operation.kind === Kind.OPERATION_DEFINITION);
|
|
212
231
|
* const context = new ValidationContext(
|
|
213
232
|
* schema,
|
|
214
233
|
* document,
|
|
@@ -8,12 +8,16 @@ exports.ValidationContext =
|
|
|
8
8
|
exports.ASTValidationContext =
|
|
9
9
|
void 0;
|
|
10
10
|
|
|
11
|
+
var _SetMap = require('../jsutils/SetMap.js');
|
|
12
|
+
|
|
11
13
|
var _kinds = require('../language/kinds.js');
|
|
12
14
|
|
|
13
15
|
var _visitor = require('../language/visitor.js');
|
|
14
16
|
|
|
15
17
|
var _TypeInfo = require('../utilities/TypeInfo.js');
|
|
16
18
|
|
|
19
|
+
var _validationAbortedError = require('./validationAbortedError.js');
|
|
20
|
+
|
|
17
21
|
/** @category Validation Context */
|
|
18
22
|
|
|
19
23
|
/**
|
|
@@ -24,11 +28,13 @@ var _TypeInfo = require('../utilities/TypeInfo.js');
|
|
|
24
28
|
* @internal
|
|
25
29
|
*/
|
|
26
30
|
class ASTValidationContext {
|
|
31
|
+
_remainingFragmentWork = 50000;
|
|
32
|
+
|
|
27
33
|
constructor(ast, onError) {
|
|
28
34
|
this._ast = ast;
|
|
29
35
|
this._fragments = undefined;
|
|
30
36
|
this._fragmentSpreads = new Map();
|
|
31
|
-
this._recursivelyReferencedFragments = new
|
|
37
|
+
this._recursivelyReferencedFragments = new _SetMap.SetMap();
|
|
32
38
|
this._onError = onError;
|
|
33
39
|
}
|
|
34
40
|
|
|
@@ -86,38 +92,56 @@ class ASTValidationContext {
|
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
return spreads;
|
|
89
|
-
}
|
|
95
|
+
} // TODO: In the next major version, accept multiple operations here and
|
|
96
|
+
// remove getRecursivelyReferencedFragmentsForOperations.
|
|
90
97
|
|
|
91
98
|
getRecursivelyReferencedFragments(operation) {
|
|
92
|
-
|
|
99
|
+
return this.getRecursivelyReferencedFragmentsForOperations([operation]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
getRecursivelyReferencedFragmentsForOperations(operations) {
|
|
103
|
+
const fragmentNames = new Set(
|
|
104
|
+
operations.flatMap(({ selectionSet }) =>
|
|
105
|
+
this.getFragmentSpreads(selectionSet).map(({ name }) => name.value),
|
|
106
|
+
),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
let fragments = this._recursivelyReferencedFragments.get(fragmentNames);
|
|
93
110
|
|
|
94
111
|
if (!fragments) {
|
|
95
112
|
fragments = [];
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
fragments.push(fragment);
|
|
110
|
-
nodesToVisit.push(fragment.selectionSet);
|
|
111
|
-
}
|
|
113
|
+
this.spendFragmentWork(fragmentNames.size);
|
|
114
|
+
const collectedNames = new Set(fragmentNames);
|
|
115
|
+
|
|
116
|
+
for (const fragName of collectedNames) {
|
|
117
|
+
const fragment = this.getFragment(fragName);
|
|
118
|
+
|
|
119
|
+
if (fragment) {
|
|
120
|
+
fragments.push(fragment);
|
|
121
|
+
const spreads = this.getFragmentSpreads(fragment.selectionSet);
|
|
122
|
+
this.spendFragmentWork(spreads.length);
|
|
123
|
+
|
|
124
|
+
for (const spread of spreads) {
|
|
125
|
+
collectedNames.add(spread.name.value);
|
|
112
126
|
}
|
|
113
127
|
}
|
|
114
128
|
}
|
|
115
129
|
|
|
116
|
-
this._recursivelyReferencedFragments.set(
|
|
130
|
+
this._recursivelyReferencedFragments.set(fragmentNames, fragments);
|
|
117
131
|
}
|
|
118
132
|
|
|
119
133
|
return fragments;
|
|
120
134
|
}
|
|
135
|
+
/** @internal */
|
|
136
|
+
|
|
137
|
+
spendFragmentWork(cost) {
|
|
138
|
+
this._remainingFragmentWork -= cost;
|
|
139
|
+
/* c8 ignore next 3 */
|
|
140
|
+
|
|
141
|
+
if (this._remainingFragmentWork < 0) {
|
|
142
|
+
throw _validationAbortedError.validationAbortedError;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
121
145
|
}
|
|
122
146
|
/** @internal */
|
|
123
147
|
|
|
@@ -130,6 +154,10 @@ class SDLValidationContext extends ASTValidationContext {
|
|
|
130
154
|
this._schema = schema;
|
|
131
155
|
}
|
|
132
156
|
|
|
157
|
+
get hideSuggestions() {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
|
|
133
161
|
get [Symbol.toStringTag]() {
|
|
134
162
|
return 'SDLValidationContext';
|
|
135
163
|
}
|
|
@@ -150,6 +178,7 @@ class ValidationContext extends ASTValidationContext {
|
|
|
150
178
|
* @param ast - Document AST being validated.
|
|
151
179
|
* @param typeInfo - TypeInfo instance used to track traversal state.
|
|
152
180
|
* @param onError - Callback invoked for each validation error.
|
|
181
|
+
* @param hideSuggestions - Omit suggestions from error messages.
|
|
153
182
|
* @example
|
|
154
183
|
* ```ts
|
|
155
184
|
* import { parse } from 'graphql/language';
|
|
@@ -163,7 +192,7 @@ class ValidationContext extends ASTValidationContext {
|
|
|
163
192
|
* }
|
|
164
193
|
* `);
|
|
165
194
|
* const document = parse('{ greeting }');
|
|
166
|
-
* const errors = [];
|
|
195
|
+
* const errors: Array<GraphQLError> = [];
|
|
167
196
|
* const context = new ValidationContext(
|
|
168
197
|
* schema,
|
|
169
198
|
* document,
|
|
@@ -177,13 +206,25 @@ class ValidationContext extends ASTValidationContext {
|
|
|
177
206
|
* errors[0].message; // => 'Example validation error.'
|
|
178
207
|
* ```
|
|
179
208
|
*/
|
|
180
|
-
constructor(schema, ast, typeInfo, onError) {
|
|
209
|
+
constructor(schema, ast, typeInfo, onError, hideSuggestions) {
|
|
181
210
|
super(ast, onError);
|
|
211
|
+
this._hideSuggestions =
|
|
212
|
+
hideSuggestions !== null && hideSuggestions !== void 0
|
|
213
|
+
? hideSuggestions
|
|
214
|
+
: false;
|
|
182
215
|
this._schema = schema;
|
|
183
216
|
this._typeInfo = typeInfo;
|
|
184
217
|
this._variableUsages = new Map();
|
|
185
218
|
this._recursiveVariableUsages = new Map();
|
|
186
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Whether suggestions should be omitted from validation errors.
|
|
222
|
+
* @returns True when validation error suggestions are disabled.
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
get hideSuggestions() {
|
|
226
|
+
return this._hideSuggestions;
|
|
227
|
+
}
|
|
187
228
|
/**
|
|
188
229
|
* Returns the value used by `Object.prototype.toString`.
|
|
189
230
|
* @returns The built-in string tag for this object.
|
|
@@ -226,7 +267,8 @@ class ValidationContext extends ASTValidationContext {
|
|
|
226
267
|
* @returns Variable usages found directly within this node.
|
|
227
268
|
* @example
|
|
228
269
|
* ```ts
|
|
229
|
-
* import
|
|
270
|
+
* import assert from 'node:assert/strict';
|
|
271
|
+
* import { parse, Kind } from 'graphql/language';
|
|
230
272
|
* import { buildSchema, TypeInfo } from 'graphql/utilities';
|
|
231
273
|
* import { ValidationContext } from 'graphql/validation';
|
|
232
274
|
*
|
|
@@ -237,6 +279,7 @@ class ValidationContext extends ASTValidationContext {
|
|
|
237
279
|
* `);
|
|
238
280
|
* const document = parse('query ($name: String) { greeting(name: $name) }');
|
|
239
281
|
* const operation = document.definitions[0];
|
|
282
|
+
* assert(operation.kind === Kind.OPERATION_DEFINITION);
|
|
240
283
|
* const context = new ValidationContext(
|
|
241
284
|
* schema,
|
|
242
285
|
* document,
|
|
@@ -285,7 +328,8 @@ class ValidationContext extends ASTValidationContext {
|
|
|
285
328
|
* @returns Variable usages reachable from the operation.
|
|
286
329
|
* @example
|
|
287
330
|
* ```ts
|
|
288
|
-
* import
|
|
331
|
+
* import assert from 'node:assert/strict';
|
|
332
|
+
* import { parse, Kind } from 'graphql/language';
|
|
289
333
|
* import { buildSchema, TypeInfo } from 'graphql/utilities';
|
|
290
334
|
* import { ValidationContext } from 'graphql/validation';
|
|
291
335
|
*
|
|
@@ -310,6 +354,7 @@ class ValidationContext extends ASTValidationContext {
|
|
|
310
354
|
* }
|
|
311
355
|
* `);
|
|
312
356
|
* const operation = document.definitions[0];
|
|
357
|
+
* assert(operation.kind === Kind.OPERATION_DEFINITION);
|
|
313
358
|
* const context = new ValidationContext(
|
|
314
359
|
* schema,
|
|
315
360
|
* document,
|
|
@@ -327,12 +372,24 @@ class ValidationContext extends ASTValidationContext {
|
|
|
327
372
|
let usages = this._recursiveVariableUsages.get(operation);
|
|
328
373
|
|
|
329
374
|
if (!usages) {
|
|
330
|
-
|
|
375
|
+
const fragments = this.getRecursivelyReferencedFragments(operation);
|
|
331
376
|
|
|
332
|
-
|
|
333
|
-
|
|
377
|
+
let fragmentUsages = this._recursiveVariableUsages.get(fragments);
|
|
378
|
+
|
|
379
|
+
if (!fragmentUsages) {
|
|
380
|
+
this.spendFragmentWork(fragments.length);
|
|
381
|
+
fragmentUsages = fragments.flatMap((frag) => {
|
|
382
|
+
const localUsages = this.getVariableUsages(frag);
|
|
383
|
+
this.spendFragmentWork(localUsages.length);
|
|
384
|
+
return localUsages;
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
this._recursiveVariableUsages.set(fragments, fragmentUsages);
|
|
334
388
|
}
|
|
335
389
|
|
|
390
|
+
this.spendFragmentWork(fragmentUsages.length);
|
|
391
|
+
usages = this.getVariableUsages(operation).concat(fragmentUsages);
|
|
392
|
+
|
|
336
393
|
this._recursiveVariableUsages.set(operation, usages);
|
|
337
394
|
}
|
|
338
395
|
|