graphql 15.10.3 → 15.11.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.js +7 -6
- package/error/GraphQLError.js.flow +3 -3
- package/error/GraphQLError.mjs +8 -7
- package/execution/execute.d.ts +2 -0
- package/execution/execute.js +33 -12
- package/execution/execute.js.flow +32 -11
- package/execution/execute.mjs +33 -12
- package/execution/values.d.ts +1 -1
- package/execution/values.js +5 -5
- package/execution/values.js.flow +5 -2
- package/execution/values.mjs +4 -4
- package/graphql.d.ts +1 -0
- package/graphql.js +4 -1
- package/graphql.js.flow +5 -1
- package/graphql.mjs +4 -1
- package/jsutils/SetMap.js +56 -0
- package/jsutils/SetMap.js.flow +39 -0
- package/jsutils/SetMap.mjs +47 -0
- package/language/lexer.js +21 -2
- package/language/lexer.js.flow +24 -2
- package/language/lexer.mjs +21 -2
- package/language/location.d.ts +5 -0
- package/language/location.js +64 -0
- package/language/location.js.flow +39 -0
- package/language/location.mjs +62 -0
- package/language/parser.js +34 -19
- package/language/parser.js.flow +54 -10
- package/language/parser.mjs +34 -19
- package/language/printer.d.ts +7 -0
- package/language/printer.js +251 -118
- package/language/printer.js.flow +345 -141
- package/language/printer.mjs +246 -116
- package/language/reducer.js +99 -0
- package/language/reducer.js.flow +89 -0
- package/language/reducer.mjs +89 -0
- package/package.json +1 -1
- package/subscription/subscribe.d.ts +2 -0
- package/subscription/subscribe.js +4 -3
- package/subscription/subscribe.js.flow +6 -0
- package/subscription/subscribe.mjs +4 -3
- package/type/definition.d.ts +2 -1
- package/type/definition.js +8 -8
- package/type/definition.js.flow +13 -7
- package/type/definition.mjs +7 -7
- package/type/scalars.js +5 -5
- package/type/scalars.js.flow +1 -1
- package/type/scalars.mjs +1 -1
- package/utilities/buildASTSchema.js +3 -0
- package/utilities/buildASTSchema.js.flow +3 -0
- package/utilities/buildASTSchema.mjs +3 -0
- package/utilities/coerceInputValue.d.ts +1 -0
- package/utilities/coerceInputValue.js +9 -8
- package/utilities/coerceInputValue.js.flow +42 -9
- package/utilities/coerceInputValue.mjs +10 -9
- package/utilities/findBreakingChanges.js +3 -23
- package/utilities/findBreakingChanges.js.flow +2 -15
- package/utilities/findBreakingChanges.mjs +2 -21
- package/utilities/sortValueNode.js +52 -0
- package/utilities/sortValueNode.js.flow +42 -0
- package/utilities/sortValueNode.mjs +42 -0
- package/utilities/valueFromAST.js +2 -2
- package/utilities/valueFromAST.js.flow +8 -2
- package/utilities/valueFromAST.mjs +2 -2
- package/validation/ValidationContext.d.ts +8 -0
- package/validation/ValidationContext.js +82 -24
- package/validation/ValidationContext.js.flow +70 -21
- package/validation/ValidationContext.mjs +80 -24
- package/validation/rules/FieldsOnCorrectTypeRule.js +2 -2
- package/validation/rules/FieldsOnCorrectTypeRule.js.flow +8 -2
- package/validation/rules/FieldsOnCorrectTypeRule.mjs +2 -2
- package/validation/rules/KnownArgumentNamesRule.js +8 -9
- package/validation/rules/KnownArgumentNamesRule.js.flow +16 -6
- package/validation/rules/KnownArgumentNamesRule.mjs +8 -9
- package/validation/rules/KnownTypeNamesRule.js +1 -1
- package/validation/rules/KnownTypeNamesRule.js.flow +6 -4
- package/validation/rules/KnownTypeNamesRule.mjs +1 -1
- package/validation/rules/MaxIntrospectionDepthRule.js +37 -17
- package/validation/rules/MaxIntrospectionDepthRule.js.flow +46 -15
- package/validation/rules/MaxIntrospectionDepthRule.mjs +37 -17
- package/validation/rules/NoUnusedFragmentsRule.js +6 -13
- package/validation/rules/NoUnusedFragmentsRule.js.flow +6 -10
- package/validation/rules/NoUnusedFragmentsRule.mjs +6 -13
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +402 -208
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js.flow +566 -330
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +400 -206
- package/validation/rules/ValuesOfCorrectTypeRule.js +6 -6
- package/validation/rules/ValuesOfCorrectTypeRule.js.flow +11 -6
- package/validation/rules/ValuesOfCorrectTypeRule.mjs +4 -4
- package/validation/validate.d.ts +1 -1
- package/validation/validate.js +6 -2
- package/validation/validate.js.flow +8 -2
- package/validation/validate.mjs +5 -2
- package/validation/validationAbortedError.d.ts +4 -0
- package/validation/validationAbortedError.js +12 -0
- package/validation/validationAbortedError.js.flow +7 -0
- package/validation/validationAbortedError.mjs +4 -0
- package/version.js +3 -3
- package/version.js.flow +3 -3
- package/version.mjs +3 -3
|
@@ -31,8 +31,12 @@ export function KnownArgumentNamesRule(context: ValidationContext): ASTVisitor {
|
|
|
31
31
|
|
|
32
32
|
if (!argDef && fieldDef && parentType) {
|
|
33
33
|
const argName = argNode.name.value;
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
const suggestions = context.hideSuggestions
|
|
35
|
+
? []
|
|
36
|
+
: suggestionList(
|
|
37
|
+
argName,
|
|
38
|
+
fieldDef.args.map((arg) => arg.name),
|
|
39
|
+
);
|
|
36
40
|
context.reportError(
|
|
37
41
|
new GraphQLError(
|
|
38
42
|
`Unknown argument "${argName}" on field "${parentType.name}.${fieldDef.name}".` +
|
|
@@ -58,7 +62,9 @@ export function KnownArgumentNamesOnDirectivesRule(
|
|
|
58
62
|
? schema.getDirectives()
|
|
59
63
|
: specifiedDirectives;
|
|
60
64
|
for (const directive of definedDirectives) {
|
|
61
|
-
directiveArgs[directive.name] =
|
|
65
|
+
directiveArgs[directive.name] = new Set(
|
|
66
|
+
directive.args.map((arg) => arg.name),
|
|
67
|
+
);
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
const astDefinitions = context.getDocument().definitions;
|
|
@@ -67,7 +73,9 @@ export function KnownArgumentNamesOnDirectivesRule(
|
|
|
67
73
|
// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
|
|
68
74
|
const argsNodes = def.arguments ?? [];
|
|
69
75
|
|
|
70
|
-
directiveArgs[def.name.value] =
|
|
76
|
+
directiveArgs[def.name.value] = new Set(
|
|
77
|
+
argsNodes.map((arg) => arg.name.value),
|
|
78
|
+
);
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
81
|
|
|
@@ -79,8 +87,10 @@ export function KnownArgumentNamesOnDirectivesRule(
|
|
|
79
87
|
if (directiveNode.arguments && knownArgs) {
|
|
80
88
|
for (const argNode of directiveNode.arguments) {
|
|
81
89
|
const argName = argNode.name.value;
|
|
82
|
-
if (knownArgs.
|
|
83
|
-
const suggestions =
|
|
90
|
+
if (!knownArgs.has(argName)) {
|
|
91
|
+
const suggestions = context.hideSuggestions
|
|
92
|
+
? []
|
|
93
|
+
: suggestionList(argName, Array.from(knownArgs));
|
|
84
94
|
context.reportError(
|
|
85
95
|
new GraphQLError(
|
|
86
96
|
`Unknown argument "${argName}" on directive "@${directiveName}".` +
|
|
@@ -25,10 +25,9 @@ export function KnownArgumentNamesRule(context) {
|
|
|
25
25
|
|
|
26
26
|
if (!argDef && fieldDef && parentType) {
|
|
27
27
|
var argName = argNode.name.value;
|
|
28
|
-
var
|
|
28
|
+
var suggestions = context.hideSuggestions ? [] : suggestionList(argName, fieldDef.args.map(function (arg) {
|
|
29
29
|
return arg.name;
|
|
30
|
-
});
|
|
31
|
-
var suggestions = suggestionList(argName, knownArgsNames);
|
|
30
|
+
}));
|
|
32
31
|
context.reportError(new GraphQLError("Unknown argument \"".concat(argName, "\" on field \"").concat(parentType.name, ".").concat(fieldDef.name, "\".") + didYouMean(suggestions), argNode));
|
|
33
32
|
}
|
|
34
33
|
}
|
|
@@ -45,9 +44,9 @@ export function KnownArgumentNamesOnDirectivesRule(context) {
|
|
|
45
44
|
|
|
46
45
|
for (var _i2 = 0; _i2 < definedDirectives.length; _i2++) {
|
|
47
46
|
var directive = definedDirectives[_i2];
|
|
48
|
-
directiveArgs[directive.name] = directive.args.map(function (arg) {
|
|
47
|
+
directiveArgs[directive.name] = new Set(directive.args.map(function (arg) {
|
|
49
48
|
return arg.name;
|
|
50
|
-
});
|
|
49
|
+
}));
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
var astDefinitions = context.getDocument().definitions;
|
|
@@ -60,9 +59,9 @@ export function KnownArgumentNamesOnDirectivesRule(context) {
|
|
|
60
59
|
|
|
61
60
|
// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
|
|
62
61
|
var argsNodes = (_def$arguments = def.arguments) !== null && _def$arguments !== void 0 ? _def$arguments : [];
|
|
63
|
-
directiveArgs[def.name.value] = argsNodes.map(function (arg) {
|
|
62
|
+
directiveArgs[def.name.value] = new Set(argsNodes.map(function (arg) {
|
|
64
63
|
return arg.name.value;
|
|
65
|
-
});
|
|
64
|
+
}));
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
|
|
@@ -76,8 +75,8 @@ export function KnownArgumentNamesOnDirectivesRule(context) {
|
|
|
76
75
|
var argNode = _directiveNode$argume2[_i6];
|
|
77
76
|
var argName = argNode.name.value;
|
|
78
77
|
|
|
79
|
-
if (knownArgs.
|
|
80
|
-
var suggestions = suggestionList(argName, knownArgs);
|
|
78
|
+
if (!knownArgs.has(argName)) {
|
|
79
|
+
var suggestions = context.hideSuggestions ? [] : suggestionList(argName, Array.from(knownArgs));
|
|
81
80
|
context.reportError(new GraphQLError("Unknown argument \"".concat(argName, "\" on directive \"@").concat(directiveName, "\".") + didYouMean(suggestions), argNode));
|
|
82
81
|
}
|
|
83
82
|
}
|
|
@@ -53,7 +53,7 @@ function KnownTypeNamesRule(context) {
|
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
var suggestedTypes = (0, _suggestionList.default)(typeName, isSDL ? standardTypeNames.concat(typeNames) : typeNames);
|
|
56
|
+
var suggestedTypes = context.hideSuggestions ? [] : (0, _suggestionList.default)(typeName, isSDL ? standardTypeNames.concat(typeNames) : typeNames);
|
|
57
57
|
context.reportError(new _GraphQLError.GraphQLError("Unknown type \"".concat(typeName, "\".") + (0, _didYouMean.default)(suggestedTypes), node));
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -53,10 +53,12 @@ export function KnownTypeNamesRule(
|
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const suggestedTypes =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
const suggestedTypes = context.hideSuggestions
|
|
57
|
+
? []
|
|
58
|
+
: suggestionList(
|
|
59
|
+
typeName,
|
|
60
|
+
isSDL ? standardTypeNames.concat(typeNames) : typeNames,
|
|
61
|
+
);
|
|
60
62
|
context.reportError(
|
|
61
63
|
new GraphQLError(
|
|
62
64
|
`Unknown type "${typeName}".` + didYouMean(suggestedTypes),
|
|
@@ -39,7 +39,7 @@ export function KnownTypeNamesRule(context) {
|
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
var suggestedTypes = suggestionList(typeName, isSDL ? standardTypeNames.concat(typeNames) : typeNames);
|
|
42
|
+
var suggestedTypes = context.hideSuggestions ? [] : suggestionList(typeName, isSDL ? standardTypeNames.concat(typeNames) : typeNames);
|
|
43
43
|
context.reportError(new GraphQLError("Unknown type \"".concat(typeName, "\".") + didYouMean(suggestedTypes), node));
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -12,19 +12,37 @@ var _kinds = require("../../language/kinds.js");
|
|
|
12
12
|
var MAX_LISTS_DEPTH = 3;
|
|
13
13
|
|
|
14
14
|
function MaxIntrospectionDepthRule(context) {
|
|
15
|
+
// For each fragment, the greatest entry depth at which its check completed
|
|
16
|
+
// without reaching the limit. Shared across root checks.
|
|
17
|
+
// Entry depth is the list depth before entering the fragment.
|
|
18
|
+
var checkedFragments = Object.create(null); // For each fragment, the smallest entry depth at which its check reached
|
|
19
|
+
// the limit. Shared across root checks.
|
|
20
|
+
|
|
21
|
+
var exceededFragments = Object.create(null);
|
|
15
22
|
/**
|
|
16
23
|
* Counts the depth of list fields in "__Type" recursively and
|
|
17
24
|
* returns `true` if the limit has been reached.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
18
27
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
|
|
29
|
+
function checkDepth(node, visitedFragments) {
|
|
21
30
|
var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
22
31
|
|
|
23
32
|
if (node.kind === _kinds.Kind.FRAGMENT_SPREAD) {
|
|
24
33
|
var _fragmentName = node.name.value;
|
|
34
|
+
var exceededEntryDepth = exceededFragments[_fragmentName]; // A check that reached the limit will also do so when repeated at an
|
|
35
|
+
// equal or greater entry depth.
|
|
36
|
+
|
|
37
|
+
if (exceededEntryDepth !== undefined && exceededEntryDepth <= depth) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var visitedEntryDepth = visitedFragments[_fragmentName];
|
|
42
|
+
var checkedEntryDepth = checkedFragments[_fragmentName]; // At equal or shallower entry depths, skip revisits to break cycles
|
|
43
|
+
// or reuse a completed successful check.
|
|
25
44
|
|
|
26
|
-
if (
|
|
27
|
-
// Fragment cycles are handled by `NoFragmentCyclesRule`.
|
|
45
|
+
if (visitedEntryDepth !== undefined && visitedEntryDepth >= depth || checkedEntryDepth !== undefined && checkedEntryDepth >= depth) {
|
|
28
46
|
return false;
|
|
29
47
|
}
|
|
30
48
|
|
|
@@ -33,19 +51,17 @@ function MaxIntrospectionDepthRule(context) {
|
|
|
33
51
|
if (!fragment) {
|
|
34
52
|
// Missing fragments checks are handled by `KnownFragmentNamesRule`.
|
|
35
53
|
return false;
|
|
36
|
-
} // Rather than following an immutable programming pattern which has
|
|
37
|
-
// significant memory and garbage collection overhead, we've opted to
|
|
38
|
-
// take a mutable approach for efficiency's sake. Importantly visiting a
|
|
39
|
-
// fragment twice is fine, so long as you don't do one visit inside the
|
|
40
|
-
// other.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
visitedFragments[_fragmentName] = true;
|
|
45
|
-
return checkDepth(fragment, visitedFragments, depth);
|
|
46
|
-
} finally {
|
|
47
|
-
visitedFragments[_fragmentName] = null;
|
|
48
54
|
}
|
|
55
|
+
|
|
56
|
+
visitedFragments[_fragmentName] = depth;
|
|
57
|
+
|
|
58
|
+
if (checkDepth(fragment, visitedFragments, depth)) {
|
|
59
|
+
exceededFragments[_fragmentName] = depth;
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
checkedFragments[_fragmentName] = depth;
|
|
64
|
+
return false;
|
|
49
65
|
}
|
|
50
66
|
|
|
51
67
|
if (node.kind === _kinds.Kind.FIELD && ( // check all introspection lists
|
|
@@ -75,7 +91,11 @@ function MaxIntrospectionDepthRule(context) {
|
|
|
75
91
|
return {
|
|
76
92
|
Field: function Field(node) {
|
|
77
93
|
if (node.name.value === '__schema' || node.name.value === '__type') {
|
|
78
|
-
|
|
94
|
+
// For each fragment, the greatest entry depth at which it was visited
|
|
95
|
+
// during this root check, including visits still in progress.
|
|
96
|
+
var visitedFragments = Object.create(null);
|
|
97
|
+
|
|
98
|
+
if (checkDepth(node, visitedFragments)) {
|
|
79
99
|
context.reportError(new _GraphQLError.GraphQLError('Maximum introspection depth exceeded', [node]));
|
|
80
100
|
return false;
|
|
81
101
|
}
|
|
@@ -12,22 +12,51 @@ const MAX_LISTS_DEPTH = 3;
|
|
|
12
12
|
export function MaxIntrospectionDepthRule(
|
|
13
13
|
context: ASTValidationContext,
|
|
14
14
|
): ASTVisitor {
|
|
15
|
+
// For each fragment, the greatest entry depth at which its check completed
|
|
16
|
+
// without reaching the limit. Shared across root checks.
|
|
17
|
+
// Entry depth is the list depth before entering the fragment.
|
|
18
|
+
const checkedFragments: {
|
|
19
|
+
[key: string]: number | void,
|
|
20
|
+
__proto__: null,
|
|
21
|
+
} = Object.create(null);
|
|
22
|
+
|
|
23
|
+
// For each fragment, the smallest entry depth at which its check reached
|
|
24
|
+
// the limit. Shared across root checks.
|
|
25
|
+
const exceededFragments: {
|
|
26
|
+
[key: string]: number | void,
|
|
27
|
+
__proto__: null,
|
|
28
|
+
} = Object.create(null);
|
|
29
|
+
|
|
15
30
|
/**
|
|
16
31
|
* Counts the depth of list fields in "__Type" recursively and
|
|
17
32
|
* returns `true` if the limit has been reached.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
18
35
|
*/
|
|
19
36
|
function checkDepth(
|
|
20
37
|
node: ASTNode,
|
|
21
38
|
visitedFragments: {
|
|
22
|
-
[fragmentName: string]:
|
|
39
|
+
[fragmentName: string]: number | void,
|
|
23
40
|
__proto__: null,
|
|
24
|
-
}
|
|
41
|
+
},
|
|
25
42
|
depth: number = 0,
|
|
26
43
|
): boolean {
|
|
27
44
|
if (node.kind === Kind.FRAGMENT_SPREAD) {
|
|
28
45
|
const fragmentName = node.name.value;
|
|
29
|
-
|
|
30
|
-
|
|
46
|
+
const exceededEntryDepth = exceededFragments[fragmentName];
|
|
47
|
+
// A check that reached the limit will also do so when repeated at an
|
|
48
|
+
// equal or greater entry depth.
|
|
49
|
+
if (exceededEntryDepth !== undefined && exceededEntryDepth <= depth) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
const visitedEntryDepth = visitedFragments[fragmentName];
|
|
53
|
+
const checkedEntryDepth = checkedFragments[fragmentName];
|
|
54
|
+
// At equal or shallower entry depths, skip revisits to break cycles
|
|
55
|
+
// or reuse a completed successful check.
|
|
56
|
+
if (
|
|
57
|
+
(visitedEntryDepth !== undefined && visitedEntryDepth >= depth) ||
|
|
58
|
+
(checkedEntryDepth !== undefined && checkedEntryDepth >= depth)
|
|
59
|
+
) {
|
|
31
60
|
return false;
|
|
32
61
|
}
|
|
33
62
|
const fragment = context.getFragment(fragmentName);
|
|
@@ -36,17 +65,13 @@ export function MaxIntrospectionDepthRule(
|
|
|
36
65
|
return false;
|
|
37
66
|
}
|
|
38
67
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// other.
|
|
44
|
-
try {
|
|
45
|
-
visitedFragments[fragmentName] = true;
|
|
46
|
-
return checkDepth(fragment, visitedFragments, depth);
|
|
47
|
-
} finally {
|
|
48
|
-
visitedFragments[fragmentName] = null;
|
|
68
|
+
visitedFragments[fragmentName] = depth;
|
|
69
|
+
if (checkDepth(fragment, visitedFragments, depth)) {
|
|
70
|
+
exceededFragments[fragmentName] = depth;
|
|
71
|
+
return true;
|
|
49
72
|
}
|
|
73
|
+
checkedFragments[fragmentName] = depth;
|
|
74
|
+
return false;
|
|
50
75
|
}
|
|
51
76
|
|
|
52
77
|
if (
|
|
@@ -79,7 +104,13 @@ export function MaxIntrospectionDepthRule(
|
|
|
79
104
|
return {
|
|
80
105
|
Field(node) {
|
|
81
106
|
if (node.name.value === '__schema' || node.name.value === '__type') {
|
|
82
|
-
|
|
107
|
+
// For each fragment, the greatest entry depth at which it was visited
|
|
108
|
+
// during this root check, including visits still in progress.
|
|
109
|
+
const visitedFragments: {
|
|
110
|
+
[key: string]: number | void,
|
|
111
|
+
__proto__: null,
|
|
112
|
+
} = Object.create(null);
|
|
113
|
+
if (checkDepth(node, visitedFragments)) {
|
|
83
114
|
context.reportError(
|
|
84
115
|
new GraphQLError('Maximum introspection depth exceeded', [node]),
|
|
85
116
|
);
|
|
@@ -2,19 +2,37 @@ import { GraphQLError } from "../../error/GraphQLError.mjs";
|
|
|
2
2
|
import { Kind } from "../../language/kinds.mjs";
|
|
3
3
|
var MAX_LISTS_DEPTH = 3;
|
|
4
4
|
export function MaxIntrospectionDepthRule(context) {
|
|
5
|
+
// For each fragment, the greatest entry depth at which its check completed
|
|
6
|
+
// without reaching the limit. Shared across root checks.
|
|
7
|
+
// Entry depth is the list depth before entering the fragment.
|
|
8
|
+
var checkedFragments = Object.create(null); // For each fragment, the smallest entry depth at which its check reached
|
|
9
|
+
// the limit. Shared across root checks.
|
|
10
|
+
|
|
11
|
+
var exceededFragments = Object.create(null);
|
|
5
12
|
/**
|
|
6
13
|
* Counts the depth of list fields in "__Type" recursively and
|
|
7
14
|
* returns `true` if the limit has been reached.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
8
17
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
18
|
+
|
|
19
|
+
function checkDepth(node, visitedFragments) {
|
|
11
20
|
var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
12
21
|
|
|
13
22
|
if (node.kind === Kind.FRAGMENT_SPREAD) {
|
|
14
23
|
var _fragmentName = node.name.value;
|
|
24
|
+
var exceededEntryDepth = exceededFragments[_fragmentName]; // A check that reached the limit will also do so when repeated at an
|
|
25
|
+
// equal or greater entry depth.
|
|
26
|
+
|
|
27
|
+
if (exceededEntryDepth !== undefined && exceededEntryDepth <= depth) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var visitedEntryDepth = visitedFragments[_fragmentName];
|
|
32
|
+
var checkedEntryDepth = checkedFragments[_fragmentName]; // At equal or shallower entry depths, skip revisits to break cycles
|
|
33
|
+
// or reuse a completed successful check.
|
|
15
34
|
|
|
16
|
-
if (
|
|
17
|
-
// Fragment cycles are handled by `NoFragmentCyclesRule`.
|
|
35
|
+
if (visitedEntryDepth !== undefined && visitedEntryDepth >= depth || checkedEntryDepth !== undefined && checkedEntryDepth >= depth) {
|
|
18
36
|
return false;
|
|
19
37
|
}
|
|
20
38
|
|
|
@@ -23,19 +41,17 @@ export function MaxIntrospectionDepthRule(context) {
|
|
|
23
41
|
if (!fragment) {
|
|
24
42
|
// Missing fragments checks are handled by `KnownFragmentNamesRule`.
|
|
25
43
|
return false;
|
|
26
|
-
} // Rather than following an immutable programming pattern which has
|
|
27
|
-
// significant memory and garbage collection overhead, we've opted to
|
|
28
|
-
// take a mutable approach for efficiency's sake. Importantly visiting a
|
|
29
|
-
// fragment twice is fine, so long as you don't do one visit inside the
|
|
30
|
-
// other.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
visitedFragments[_fragmentName] = true;
|
|
35
|
-
return checkDepth(fragment, visitedFragments, depth);
|
|
36
|
-
} finally {
|
|
37
|
-
visitedFragments[_fragmentName] = null;
|
|
38
44
|
}
|
|
45
|
+
|
|
46
|
+
visitedFragments[_fragmentName] = depth;
|
|
47
|
+
|
|
48
|
+
if (checkDepth(fragment, visitedFragments, depth)) {
|
|
49
|
+
exceededFragments[_fragmentName] = depth;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
checkedFragments[_fragmentName] = depth;
|
|
54
|
+
return false;
|
|
39
55
|
}
|
|
40
56
|
|
|
41
57
|
if (node.kind === Kind.FIELD && ( // check all introspection lists
|
|
@@ -65,7 +81,11 @@ export function MaxIntrospectionDepthRule(context) {
|
|
|
65
81
|
return {
|
|
66
82
|
Field: function Field(node) {
|
|
67
83
|
if (node.name.value === '__schema' || node.name.value === '__type') {
|
|
68
|
-
|
|
84
|
+
// For each fragment, the greatest entry depth at which it was visited
|
|
85
|
+
// during this root check, including visits still in progress.
|
|
86
|
+
var visitedFragments = Object.create(null);
|
|
87
|
+
|
|
88
|
+
if (checkDepth(node, visitedFragments)) {
|
|
69
89
|
context.reportError(new GraphQLError('Maximum introspection depth exceeded', [node]));
|
|
70
90
|
return false;
|
|
71
91
|
}
|
|
@@ -27,22 +27,15 @@ function NoUnusedFragmentsRule(context) {
|
|
|
27
27
|
},
|
|
28
28
|
Document: {
|
|
29
29
|
leave: function leave() {
|
|
30
|
-
var fragmentNameUsed =
|
|
30
|
+
var fragmentNameUsed = new Set(context.getRecursivelyReferencedFragmentsForOperations(operationDefs).map(function (fragment) {
|
|
31
|
+
return fragment.name.value;
|
|
32
|
+
}));
|
|
31
33
|
|
|
32
|
-
for (var _i2 = 0; _i2 <
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
for (var _i4 = 0, _context$getRecursive2 = context.getRecursivelyReferencedFragments(operation); _i4 < _context$getRecursive2.length; _i4++) {
|
|
36
|
-
var fragment = _context$getRecursive2[_i4];
|
|
37
|
-
fragmentNameUsed[fragment.name.value] = true;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
for (var _i6 = 0; _i6 < fragmentDefs.length; _i6++) {
|
|
42
|
-
var fragmentDef = fragmentDefs[_i6];
|
|
34
|
+
for (var _i2 = 0; _i2 < fragmentDefs.length; _i2++) {
|
|
35
|
+
var fragmentDef = fragmentDefs[_i2];
|
|
43
36
|
var fragName = fragmentDef.name.value;
|
|
44
37
|
|
|
45
|
-
if (fragmentNameUsed
|
|
38
|
+
if (!fragmentNameUsed.has(fragName)) {
|
|
46
39
|
context.reportError(new _GraphQLError.GraphQLError("Fragment \"".concat(fragName, "\" is never used."), fragmentDef));
|
|
47
40
|
}
|
|
48
41
|
}
|
|
@@ -28,18 +28,14 @@ export function NoUnusedFragmentsRule(
|
|
|
28
28
|
},
|
|
29
29
|
Document: {
|
|
30
30
|
leave() {
|
|
31
|
-
const fragmentNameUsed =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
fragmentNameUsed[fragment.name.value] = true;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
31
|
+
const fragmentNameUsed = new Set(
|
|
32
|
+
context
|
|
33
|
+
.getRecursivelyReferencedFragmentsForOperations(operationDefs)
|
|
34
|
+
.map((fragment) => fragment.name.value),
|
|
35
|
+
);
|
|
40
36
|
for (const fragmentDef of fragmentDefs) {
|
|
41
37
|
const fragName = fragmentDef.name.value;
|
|
42
|
-
if (fragmentNameUsed
|
|
38
|
+
if (!fragmentNameUsed.has(fragName)) {
|
|
43
39
|
context.reportError(
|
|
44
40
|
new GraphQLError(
|
|
45
41
|
`Fragment "${fragName}" is never used.`,
|
|
@@ -20,22 +20,15 @@ export function NoUnusedFragmentsRule(context) {
|
|
|
20
20
|
},
|
|
21
21
|
Document: {
|
|
22
22
|
leave: function leave() {
|
|
23
|
-
var fragmentNameUsed =
|
|
23
|
+
var fragmentNameUsed = new Set(context.getRecursivelyReferencedFragmentsForOperations(operationDefs).map(function (fragment) {
|
|
24
|
+
return fragment.name.value;
|
|
25
|
+
}));
|
|
24
26
|
|
|
25
|
-
for (var _i2 = 0; _i2 <
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
for (var _i4 = 0, _context$getRecursive2 = context.getRecursivelyReferencedFragments(operation); _i4 < _context$getRecursive2.length; _i4++) {
|
|
29
|
-
var fragment = _context$getRecursive2[_i4];
|
|
30
|
-
fragmentNameUsed[fragment.name.value] = true;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
for (var _i6 = 0; _i6 < fragmentDefs.length; _i6++) {
|
|
35
|
-
var fragmentDef = fragmentDefs[_i6];
|
|
27
|
+
for (var _i2 = 0; _i2 < fragmentDefs.length; _i2++) {
|
|
28
|
+
var fragmentDef = fragmentDefs[_i2];
|
|
36
29
|
var fragName = fragmentDef.name.value;
|
|
37
30
|
|
|
38
|
-
if (fragmentNameUsed
|
|
31
|
+
if (!fragmentNameUsed.has(fragName)) {
|
|
39
32
|
context.reportError(new GraphQLError("Fragment \"".concat(fragName, "\" is never used."), fragmentDef));
|
|
40
33
|
}
|
|
41
34
|
}
|