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
|
@@ -25,16 +25,18 @@ import { Kind } from '../../language/kinds.mjs';
|
|
|
25
25
|
* const invalidDocument = parse(`
|
|
26
26
|
* query { name } query Other { name }
|
|
27
27
|
* `);
|
|
28
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
28
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
29
|
+
* LoneAnonymousOperationRule,
|
|
30
|
+
* ]);
|
|
29
31
|
*
|
|
30
32
|
* invalidErrors.length; // => 1
|
|
31
33
|
*
|
|
32
34
|
* const validDocument = parse(`
|
|
33
35
|
* { name }
|
|
34
36
|
* `);
|
|
35
|
-
* const validErrors = validate(schema, validDocument, [
|
|
36
|
-
*
|
|
37
|
-
*
|
|
37
|
+
* const validErrors = validate(schema, validDocument, [
|
|
38
|
+
* LoneAnonymousOperationRule,
|
|
39
|
+
* ]); // => []
|
|
38
40
|
* ```
|
|
39
41
|
*/
|
|
40
42
|
export function LoneAnonymousOperationRule(context) {
|
|
@@ -19,16 +19,18 @@ import type { ASTValidationContext } from '../ValidationContext';
|
|
|
19
19
|
* const invalidDocument = parse(`
|
|
20
20
|
* { __schema { types { fields { type { fields { type { fields { name } } } } } } } }
|
|
21
21
|
* `);
|
|
22
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
22
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
23
|
+
* MaxIntrospectionDepthRule,
|
|
24
|
+
* ]);
|
|
23
25
|
*
|
|
24
26
|
* invalidErrors.length; // => 1
|
|
25
27
|
*
|
|
26
28
|
* const validDocument = parse(`
|
|
27
29
|
* { __schema { queryType { name } } }
|
|
28
30
|
* `);
|
|
29
|
-
* const validErrors = validate(schema, validDocument, [
|
|
30
|
-
*
|
|
31
|
-
*
|
|
31
|
+
* const validErrors = validate(schema, validDocument, [
|
|
32
|
+
* MaxIntrospectionDepthRule,
|
|
33
|
+
* ]); // => []
|
|
32
34
|
* ```
|
|
33
35
|
*/
|
|
34
36
|
export declare function MaxIntrospectionDepthRule(
|
|
@@ -29,32 +29,54 @@ const MAX_LISTS_DEPTH = 3;
|
|
|
29
29
|
* const invalidDocument = parse(`
|
|
30
30
|
* { __schema { types { fields { type { fields { type { fields { name } } } } } } } }
|
|
31
31
|
* `);
|
|
32
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
32
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
33
|
+
* MaxIntrospectionDepthRule,
|
|
34
|
+
* ]);
|
|
33
35
|
*
|
|
34
36
|
* invalidErrors.length; // => 1
|
|
35
37
|
*
|
|
36
38
|
* const validDocument = parse(`
|
|
37
39
|
* { __schema { queryType { name } } }
|
|
38
40
|
* `);
|
|
39
|
-
* const validErrors = validate(schema, validDocument, [
|
|
40
|
-
*
|
|
41
|
-
*
|
|
41
|
+
* const validErrors = validate(schema, validDocument, [
|
|
42
|
+
* MaxIntrospectionDepthRule,
|
|
43
|
+
* ]); // => []
|
|
42
44
|
* ```
|
|
43
45
|
*/
|
|
44
46
|
|
|
45
47
|
function MaxIntrospectionDepthRule(context) {
|
|
48
|
+
// For each fragment, the greatest entry depth at which its check completed
|
|
49
|
+
// without reaching the limit. Shared across root checks.
|
|
50
|
+
// Entry depth is the list depth before entering the fragment.
|
|
51
|
+
const checkedFragments = Object.create(null); // For each fragment, the smallest entry depth at which its check reached
|
|
52
|
+
// the limit. Shared across root checks.
|
|
53
|
+
|
|
54
|
+
const exceededFragments = Object.create(null);
|
|
46
55
|
/**
|
|
47
56
|
* Counts the depth of list fields in "__Type" recursively and
|
|
48
57
|
* returns `true` if the limit has been reached.
|
|
49
58
|
*
|
|
50
59
|
* @internal
|
|
51
60
|
*/
|
|
52
|
-
|
|
61
|
+
|
|
62
|
+
function checkDepth(node, visitedFragments, depth = 0) {
|
|
53
63
|
if (node.kind === _kinds.Kind.FRAGMENT_SPREAD) {
|
|
54
64
|
const fragmentName = node.name.value;
|
|
65
|
+
const exceededEntryDepth = exceededFragments[fragmentName]; // A check that reached the limit will also do so when repeated at an
|
|
66
|
+
// equal or greater entry depth.
|
|
67
|
+
|
|
68
|
+
if (exceededEntryDepth !== undefined && exceededEntryDepth <= depth) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const visitedEntryDepth = visitedFragments[fragmentName];
|
|
73
|
+
const checkedEntryDepth = checkedFragments[fragmentName]; // At equal or shallower entry depths, skip revisits to break cycles
|
|
74
|
+
// or reuse a completed successful check.
|
|
55
75
|
|
|
56
|
-
if (
|
|
57
|
-
|
|
76
|
+
if (
|
|
77
|
+
(visitedEntryDepth !== undefined && visitedEntryDepth >= depth) ||
|
|
78
|
+
(checkedEntryDepth !== undefined && checkedEntryDepth >= depth)
|
|
79
|
+
) {
|
|
58
80
|
return false;
|
|
59
81
|
}
|
|
60
82
|
|
|
@@ -63,18 +85,17 @@ function MaxIntrospectionDepthRule(context) {
|
|
|
63
85
|
if (!fragment) {
|
|
64
86
|
// Missing fragments checks are handled by `KnownFragmentNamesRule`.
|
|
65
87
|
return false;
|
|
66
|
-
} // Rather than following an immutable programming pattern which has
|
|
67
|
-
// significant memory and garbage collection overhead, we've opted to
|
|
68
|
-
// take a mutable approach for efficiency's sake. Importantly visiting a
|
|
69
|
-
// fragment twice is fine, so long as you don't do one visit inside the
|
|
70
|
-
// other.
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
visitedFragments[fragmentName] = true;
|
|
74
|
-
return checkDepth(fragment, visitedFragments, depth);
|
|
75
|
-
} finally {
|
|
76
|
-
visitedFragments[fragmentName] = undefined;
|
|
77
88
|
}
|
|
89
|
+
|
|
90
|
+
visitedFragments[fragmentName] = depth;
|
|
91
|
+
|
|
92
|
+
if (checkDepth(fragment, visitedFragments, depth)) {
|
|
93
|
+
exceededFragments[fragmentName] = depth;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
checkedFragments[fragmentName] = depth;
|
|
98
|
+
return false;
|
|
78
99
|
}
|
|
79
100
|
|
|
80
101
|
if (
|
|
@@ -106,7 +127,11 @@ function MaxIntrospectionDepthRule(context) {
|
|
|
106
127
|
return {
|
|
107
128
|
Field(node) {
|
|
108
129
|
if (node.name.value === '__schema' || node.name.value === '__type') {
|
|
109
|
-
|
|
130
|
+
// For each fragment, the greatest entry depth at which it was visited
|
|
131
|
+
// during this root check, including visits still in progress.
|
|
132
|
+
const visitedFragments = Object.create(null);
|
|
133
|
+
|
|
134
|
+
if (checkDepth(node, visitedFragments)) {
|
|
110
135
|
context.reportError(
|
|
111
136
|
new _GraphQLError.GraphQLError(
|
|
112
137
|
'Maximum introspection depth exceeded',
|
|
@@ -20,32 +20,54 @@ const MAX_LISTS_DEPTH = 3;
|
|
|
20
20
|
* const invalidDocument = parse(`
|
|
21
21
|
* { __schema { types { fields { type { fields { type { fields { name } } } } } } } }
|
|
22
22
|
* `);
|
|
23
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
23
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
24
|
+
* MaxIntrospectionDepthRule,
|
|
25
|
+
* ]);
|
|
24
26
|
*
|
|
25
27
|
* invalidErrors.length; // => 1
|
|
26
28
|
*
|
|
27
29
|
* const validDocument = parse(`
|
|
28
30
|
* { __schema { queryType { name } } }
|
|
29
31
|
* `);
|
|
30
|
-
* const validErrors = validate(schema, validDocument, [
|
|
31
|
-
*
|
|
32
|
-
*
|
|
32
|
+
* const validErrors = validate(schema, validDocument, [
|
|
33
|
+
* MaxIntrospectionDepthRule,
|
|
34
|
+
* ]); // => []
|
|
33
35
|
* ```
|
|
34
36
|
*/
|
|
35
37
|
|
|
36
38
|
export function MaxIntrospectionDepthRule(context) {
|
|
39
|
+
// For each fragment, the greatest entry depth at which its check completed
|
|
40
|
+
// without reaching the limit. Shared across root checks.
|
|
41
|
+
// Entry depth is the list depth before entering the fragment.
|
|
42
|
+
const checkedFragments = Object.create(null); // For each fragment, the smallest entry depth at which its check reached
|
|
43
|
+
// the limit. Shared across root checks.
|
|
44
|
+
|
|
45
|
+
const exceededFragments = Object.create(null);
|
|
37
46
|
/**
|
|
38
47
|
* Counts the depth of list fields in "__Type" recursively and
|
|
39
48
|
* returns `true` if the limit has been reached.
|
|
40
49
|
*
|
|
41
50
|
* @internal
|
|
42
51
|
*/
|
|
43
|
-
|
|
52
|
+
|
|
53
|
+
function checkDepth(node, visitedFragments, depth = 0) {
|
|
44
54
|
if (node.kind === Kind.FRAGMENT_SPREAD) {
|
|
45
55
|
const fragmentName = node.name.value;
|
|
56
|
+
const exceededEntryDepth = exceededFragments[fragmentName]; // A check that reached the limit will also do so when repeated at an
|
|
57
|
+
// equal or greater entry depth.
|
|
58
|
+
|
|
59
|
+
if (exceededEntryDepth !== undefined && exceededEntryDepth <= depth) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const visitedEntryDepth = visitedFragments[fragmentName];
|
|
64
|
+
const checkedEntryDepth = checkedFragments[fragmentName]; // At equal or shallower entry depths, skip revisits to break cycles
|
|
65
|
+
// or reuse a completed successful check.
|
|
46
66
|
|
|
47
|
-
if (
|
|
48
|
-
|
|
67
|
+
if (
|
|
68
|
+
(visitedEntryDepth !== undefined && visitedEntryDepth >= depth) ||
|
|
69
|
+
(checkedEntryDepth !== undefined && checkedEntryDepth >= depth)
|
|
70
|
+
) {
|
|
49
71
|
return false;
|
|
50
72
|
}
|
|
51
73
|
|
|
@@ -54,18 +76,17 @@ export function MaxIntrospectionDepthRule(context) {
|
|
|
54
76
|
if (!fragment) {
|
|
55
77
|
// Missing fragments checks are handled by `KnownFragmentNamesRule`.
|
|
56
78
|
return false;
|
|
57
|
-
} // Rather than following an immutable programming pattern which has
|
|
58
|
-
// significant memory and garbage collection overhead, we've opted to
|
|
59
|
-
// take a mutable approach for efficiency's sake. Importantly visiting a
|
|
60
|
-
// fragment twice is fine, so long as you don't do one visit inside the
|
|
61
|
-
// other.
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
visitedFragments[fragmentName] = true;
|
|
65
|
-
return checkDepth(fragment, visitedFragments, depth);
|
|
66
|
-
} finally {
|
|
67
|
-
visitedFragments[fragmentName] = undefined;
|
|
68
79
|
}
|
|
80
|
+
|
|
81
|
+
visitedFragments[fragmentName] = depth;
|
|
82
|
+
|
|
83
|
+
if (checkDepth(fragment, visitedFragments, depth)) {
|
|
84
|
+
exceededFragments[fragmentName] = depth;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
checkedFragments[fragmentName] = depth;
|
|
89
|
+
return false;
|
|
69
90
|
}
|
|
70
91
|
|
|
71
92
|
if (
|
|
@@ -97,7 +118,11 @@ export function MaxIntrospectionDepthRule(context) {
|
|
|
97
118
|
return {
|
|
98
119
|
Field(node) {
|
|
99
120
|
if (node.name.value === '__schema' || node.name.value === '__type') {
|
|
100
|
-
|
|
121
|
+
// For each fragment, the greatest entry depth at which it was visited
|
|
122
|
+
// during this root check, including visits still in progress.
|
|
123
|
+
const visitedFragments = Object.create(null);
|
|
124
|
+
|
|
125
|
+
if (checkDepth(node, visitedFragments)) {
|
|
101
126
|
context.reportError(
|
|
102
127
|
new GraphQLError('Maximum introspection depth exceeded', {
|
|
103
128
|
nodes: [node],
|
|
@@ -31,9 +31,7 @@ import type { ASTValidationContext } from '../ValidationContext';
|
|
|
31
31
|
* const validDocument = parse(`
|
|
32
32
|
* fragment A on Query { name } query { ...A }
|
|
33
33
|
* `);
|
|
34
|
-
* const validErrors = validate(schema, validDocument, [NoFragmentCyclesRule]);
|
|
35
|
-
*
|
|
36
|
-
* validErrors; // => []
|
|
34
|
+
* const validErrors = validate(schema, validDocument, [NoFragmentCyclesRule]); // => []
|
|
37
35
|
* ```
|
|
38
36
|
*/
|
|
39
37
|
export declare function NoFragmentCyclesRule(
|
|
@@ -39,9 +39,7 @@ var _GraphQLError = require('../../error/GraphQLError.js');
|
|
|
39
39
|
* const validDocument = parse(`
|
|
40
40
|
* fragment A on Query { name } query { ...A }
|
|
41
41
|
* `);
|
|
42
|
-
* const validErrors = validate(schema, validDocument, [NoFragmentCyclesRule]);
|
|
43
|
-
*
|
|
44
|
-
* validErrors; // => []
|
|
42
|
+
* const validErrors = validate(schema, validDocument, [NoFragmentCyclesRule]); // => []
|
|
45
43
|
* ```
|
|
46
44
|
*/
|
|
47
45
|
function NoFragmentCyclesRule(context) {
|
|
@@ -31,9 +31,7 @@ import { GraphQLError } from '../../error/GraphQLError.mjs';
|
|
|
31
31
|
* const validDocument = parse(`
|
|
32
32
|
* fragment A on Query { name } query { ...A }
|
|
33
33
|
* `);
|
|
34
|
-
* const validErrors = validate(schema, validDocument, [NoFragmentCyclesRule]);
|
|
35
|
-
*
|
|
36
|
-
* validErrors; // => []
|
|
34
|
+
* const validErrors = validate(schema, validDocument, [NoFragmentCyclesRule]); // => []
|
|
37
35
|
* ```
|
|
38
36
|
*/
|
|
39
37
|
export function NoFragmentCyclesRule(context) {
|
|
@@ -24,16 +24,16 @@ import type { ValidationContext } from '../ValidationContext';
|
|
|
24
24
|
* const invalidDocument = parse(`
|
|
25
25
|
* query ($id: ID) { field(arg: $missing) }
|
|
26
26
|
* `);
|
|
27
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
27
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
28
|
+
* NoUndefinedVariablesRule,
|
|
29
|
+
* ]);
|
|
28
30
|
*
|
|
29
31
|
* invalidErrors.length; // => 1
|
|
30
32
|
*
|
|
31
33
|
* const validDocument = parse(`
|
|
32
34
|
* query ($id: ID) { field(arg: $id) }
|
|
33
35
|
* `);
|
|
34
|
-
* const validErrors = validate(schema, validDocument, [NoUndefinedVariablesRule]);
|
|
35
|
-
*
|
|
36
|
-
* validErrors; // => []
|
|
36
|
+
* const validErrors = validate(schema, validDocument, [NoUndefinedVariablesRule]); // => []
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
export declare function NoUndefinedVariablesRule(
|
|
@@ -32,16 +32,16 @@ var _GraphQLError = require('../../error/GraphQLError.js');
|
|
|
32
32
|
* const invalidDocument = parse(`
|
|
33
33
|
* query ($id: ID) { field(arg: $missing) }
|
|
34
34
|
* `);
|
|
35
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
35
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
36
|
+
* NoUndefinedVariablesRule,
|
|
37
|
+
* ]);
|
|
36
38
|
*
|
|
37
39
|
* invalidErrors.length; // => 1
|
|
38
40
|
*
|
|
39
41
|
* const validDocument = parse(`
|
|
40
42
|
* query ($id: ID) { field(arg: $id) }
|
|
41
43
|
* `);
|
|
42
|
-
* const validErrors = validate(schema, validDocument, [NoUndefinedVariablesRule]);
|
|
43
|
-
*
|
|
44
|
-
* validErrors; // => []
|
|
44
|
+
* const validErrors = validate(schema, validDocument, [NoUndefinedVariablesRule]); // => []
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
47
|
function NoUndefinedVariablesRule(context) {
|
|
@@ -24,16 +24,16 @@ import { GraphQLError } from '../../error/GraphQLError.mjs';
|
|
|
24
24
|
* const invalidDocument = parse(`
|
|
25
25
|
* query ($id: ID) { field(arg: $missing) }
|
|
26
26
|
* `);
|
|
27
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
27
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
28
|
+
* NoUndefinedVariablesRule,
|
|
29
|
+
* ]);
|
|
28
30
|
*
|
|
29
31
|
* invalidErrors.length; // => 1
|
|
30
32
|
*
|
|
31
33
|
* const validDocument = parse(`
|
|
32
34
|
* query ($id: ID) { field(arg: $id) }
|
|
33
35
|
* `);
|
|
34
|
-
* const validErrors = validate(schema, validDocument, [NoUndefinedVariablesRule]);
|
|
35
|
-
*
|
|
36
|
-
* validErrors; // => []
|
|
36
|
+
* const validErrors = validate(schema, validDocument, [NoUndefinedVariablesRule]); // => []
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
export function NoUndefinedVariablesRule(context) {
|
|
@@ -24,16 +24,16 @@ import type { ASTValidationContext } from '../ValidationContext';
|
|
|
24
24
|
* const invalidDocument = parse(`
|
|
25
25
|
* fragment Unused on Query { name } query { name }
|
|
26
26
|
* `);
|
|
27
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
27
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
28
|
+
* NoUnusedFragmentsRule,
|
|
29
|
+
* ]);
|
|
28
30
|
*
|
|
29
31
|
* invalidErrors.length; // => 1
|
|
30
32
|
*
|
|
31
33
|
* const validDocument = parse(`
|
|
32
34
|
* fragment Used on Query { name } query { ...Used }
|
|
33
35
|
* `);
|
|
34
|
-
* const validErrors = validate(schema, validDocument, [NoUnusedFragmentsRule]);
|
|
35
|
-
*
|
|
36
|
-
* validErrors; // => []
|
|
36
|
+
* const validErrors = validate(schema, validDocument, [NoUnusedFragmentsRule]); // => []
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
export declare function NoUnusedFragmentsRule(
|
|
@@ -32,16 +32,16 @@ var _GraphQLError = require('../../error/GraphQLError.js');
|
|
|
32
32
|
* const invalidDocument = parse(`
|
|
33
33
|
* fragment Unused on Query { name } query { name }
|
|
34
34
|
* `);
|
|
35
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
35
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
36
|
+
* NoUnusedFragmentsRule,
|
|
37
|
+
* ]);
|
|
36
38
|
*
|
|
37
39
|
* invalidErrors.length; // => 1
|
|
38
40
|
*
|
|
39
41
|
* const validDocument = parse(`
|
|
40
42
|
* fragment Used on Query { name } query { ...Used }
|
|
41
43
|
* `);
|
|
42
|
-
* const validErrors = validate(schema, validDocument, [NoUnusedFragmentsRule]);
|
|
43
|
-
*
|
|
44
|
-
* validErrors; // => []
|
|
44
|
+
* const validErrors = validate(schema, validDocument, [NoUnusedFragmentsRule]); // => []
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
47
|
function NoUnusedFragmentsRule(context) {
|
|
@@ -60,20 +60,16 @@ function NoUnusedFragmentsRule(context) {
|
|
|
60
60
|
|
|
61
61
|
Document: {
|
|
62
62
|
leave() {
|
|
63
|
-
const fragmentNameUsed =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
)) {
|
|
69
|
-
fragmentNameUsed[fragment.name.value] = true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
63
|
+
const fragmentNameUsed = new Set(
|
|
64
|
+
context
|
|
65
|
+
.getRecursivelyReferencedFragmentsForOperations(operationDefs)
|
|
66
|
+
.map((fragment) => fragment.name.value),
|
|
67
|
+
);
|
|
72
68
|
|
|
73
69
|
for (const fragmentDef of fragmentDefs) {
|
|
74
70
|
const fragName = fragmentDef.name.value;
|
|
75
71
|
|
|
76
|
-
if (fragmentNameUsed
|
|
72
|
+
if (!fragmentNameUsed.has(fragName)) {
|
|
77
73
|
context.reportError(
|
|
78
74
|
new _GraphQLError.GraphQLError(
|
|
79
75
|
`Fragment "${fragName}" is never used.`,
|
|
@@ -24,16 +24,16 @@ import { GraphQLError } from '../../error/GraphQLError.mjs';
|
|
|
24
24
|
* const invalidDocument = parse(`
|
|
25
25
|
* fragment Unused on Query { name } query { name }
|
|
26
26
|
* `);
|
|
27
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
27
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
28
|
+
* NoUnusedFragmentsRule,
|
|
29
|
+
* ]);
|
|
28
30
|
*
|
|
29
31
|
* invalidErrors.length; // => 1
|
|
30
32
|
*
|
|
31
33
|
* const validDocument = parse(`
|
|
32
34
|
* fragment Used on Query { name } query { ...Used }
|
|
33
35
|
* `);
|
|
34
|
-
* const validErrors = validate(schema, validDocument, [NoUnusedFragmentsRule]);
|
|
35
|
-
*
|
|
36
|
-
* validErrors; // => []
|
|
36
|
+
* const validErrors = validate(schema, validDocument, [NoUnusedFragmentsRule]); // => []
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
export function NoUnusedFragmentsRule(context) {
|
|
@@ -52,20 +52,16 @@ export function NoUnusedFragmentsRule(context) {
|
|
|
52
52
|
|
|
53
53
|
Document: {
|
|
54
54
|
leave() {
|
|
55
|
-
const fragmentNameUsed =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)) {
|
|
61
|
-
fragmentNameUsed[fragment.name.value] = true;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
55
|
+
const fragmentNameUsed = new Set(
|
|
56
|
+
context
|
|
57
|
+
.getRecursivelyReferencedFragmentsForOperations(operationDefs)
|
|
58
|
+
.map((fragment) => fragment.name.value),
|
|
59
|
+
);
|
|
64
60
|
|
|
65
61
|
for (const fragmentDef of fragmentDefs) {
|
|
66
62
|
const fragName = fragmentDef.name.value;
|
|
67
63
|
|
|
68
|
-
if (fragmentNameUsed
|
|
64
|
+
if (!fragmentNameUsed.has(fragName)) {
|
|
69
65
|
context.reportError(
|
|
70
66
|
new GraphQLError(`Fragment "${fragName}" is never used.`, {
|
|
71
67
|
nodes: fragmentDef,
|
|
@@ -25,16 +25,16 @@ import type { ValidationContext } from '../ValidationContext';
|
|
|
25
25
|
* const invalidDocument = parse(`
|
|
26
26
|
* query ($id: ID) { name }
|
|
27
27
|
* `);
|
|
28
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
28
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
29
|
+
* NoUnusedVariablesRule,
|
|
30
|
+
* ]);
|
|
29
31
|
*
|
|
30
32
|
* invalidErrors.length; // => 1
|
|
31
33
|
*
|
|
32
34
|
* const validDocument = parse(`
|
|
33
35
|
* query ($id: ID) { field(arg: $id) }
|
|
34
36
|
* `);
|
|
35
|
-
* const validErrors = validate(schema, validDocument, [NoUnusedVariablesRule]);
|
|
36
|
-
*
|
|
37
|
-
* validErrors; // => []
|
|
37
|
+
* const validErrors = validate(schema, validDocument, [NoUnusedVariablesRule]); // => []
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
40
|
export declare function NoUnusedVariablesRule(
|
|
@@ -33,16 +33,16 @@ var _GraphQLError = require('../../error/GraphQLError.js');
|
|
|
33
33
|
* const invalidDocument = parse(`
|
|
34
34
|
* query ($id: ID) { name }
|
|
35
35
|
* `);
|
|
36
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
36
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
37
|
+
* NoUnusedVariablesRule,
|
|
38
|
+
* ]);
|
|
37
39
|
*
|
|
38
40
|
* invalidErrors.length; // => 1
|
|
39
41
|
*
|
|
40
42
|
* const validDocument = parse(`
|
|
41
43
|
* query ($id: ID) { field(arg: $id) }
|
|
42
44
|
* `);
|
|
43
|
-
* const validErrors = validate(schema, validDocument, [NoUnusedVariablesRule]);
|
|
44
|
-
*
|
|
45
|
-
* validErrors; // => []
|
|
45
|
+
* const validErrors = validate(schema, validDocument, [NoUnusedVariablesRule]); // => []
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
48
|
function NoUnusedVariablesRule(context) {
|
|
@@ -25,16 +25,16 @@ import { GraphQLError } from '../../error/GraphQLError.mjs';
|
|
|
25
25
|
* const invalidDocument = parse(`
|
|
26
26
|
* query ($id: ID) { name }
|
|
27
27
|
* `);
|
|
28
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
28
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
29
|
+
* NoUnusedVariablesRule,
|
|
30
|
+
* ]);
|
|
29
31
|
*
|
|
30
32
|
* invalidErrors.length; // => 1
|
|
31
33
|
*
|
|
32
34
|
* const validDocument = parse(`
|
|
33
35
|
* query ($id: ID) { field(arg: $id) }
|
|
34
36
|
* `);
|
|
35
|
-
* const validErrors = validate(schema, validDocument, [NoUnusedVariablesRule]);
|
|
36
|
-
*
|
|
37
|
-
* validErrors; // => []
|
|
37
|
+
* const validErrors = validate(schema, validDocument, [NoUnusedVariablesRule]); // => []
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
40
|
export function NoUnusedVariablesRule(context) {
|
|
@@ -9,7 +9,7 @@ import type { ValidationContext } from '../ValidationContext';
|
|
|
9
9
|
* without ambiguity.
|
|
10
10
|
*
|
|
11
11
|
* See https://spec.graphql.org/draft/#sec-Field-Selection-Merging
|
|
12
|
-
* @param
|
|
12
|
+
* @param validationContext - The validation context used while checking the document.
|
|
13
13
|
* @returns A visitor that reports validation errors for this rule.
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
@@ -30,18 +30,20 @@ import type { ValidationContext } from '../ValidationContext';
|
|
|
30
30
|
* const invalidDocument = parse(`
|
|
31
31
|
* { dog { value: barkVolume value: name } }
|
|
32
32
|
* `);
|
|
33
|
-
* const invalidErrors = validate(schema, invalidDocument, [
|
|
33
|
+
* const invalidErrors = validate(schema, invalidDocument, [
|
|
34
|
+
* OverlappingFieldsCanBeMergedRule,
|
|
35
|
+
* ]);
|
|
34
36
|
*
|
|
35
37
|
* invalidErrors.length; // => 1
|
|
36
38
|
*
|
|
37
39
|
* const validDocument = parse(`
|
|
38
40
|
* { dog { barkVolume name } }
|
|
39
41
|
* `);
|
|
40
|
-
* const validErrors = validate(schema, validDocument, [
|
|
41
|
-
*
|
|
42
|
-
*
|
|
42
|
+
* const validErrors = validate(schema, validDocument, [
|
|
43
|
+
* OverlappingFieldsCanBeMergedRule,
|
|
44
|
+
* ]); // => []
|
|
43
45
|
* ```
|
|
44
46
|
*/
|
|
45
47
|
export declare function OverlappingFieldsCanBeMergedRule(
|
|
46
|
-
|
|
48
|
+
validationContext: ValidationContext,
|
|
47
49
|
): ASTVisitor;
|