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
package/language/location.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/** @category Source */
|
|
2
|
-
|
|
3
|
-
const LineRegExp = /\r\n|[\n\r]/g;
|
|
2
|
+
|
|
4
3
|
/** Represents a location in a Source. */
|
|
5
4
|
|
|
6
5
|
/**
|
|
@@ -14,28 +13,69 @@ const LineRegExp = /\r\n|[\n\r]/g;
|
|
|
14
13
|
* import { Source, getLocation } from 'graphql/language';
|
|
15
14
|
*
|
|
16
15
|
* const source = new Source('type Query { hello: String }');
|
|
17
|
-
* const location = getLocation(source, 13);
|
|
18
|
-
*
|
|
19
|
-
* location; // => { line: 1, column: 14 }
|
|
16
|
+
* const location = getLocation(source, 13); // => { line: 1, column: 14 }
|
|
20
17
|
* ```
|
|
21
18
|
*/
|
|
22
19
|
export function getLocation(source, position) {
|
|
23
|
-
|
|
20
|
+
const lineRegexp = /\r\n|[\n\r]/g;
|
|
24
21
|
let line = 1;
|
|
22
|
+
let column = position + 1;
|
|
23
|
+
let match;
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (match.index >= position) {
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
lastLineStart = match.index + match[0].length;
|
|
34
|
-
line += 1;
|
|
25
|
+
while ((match = lineRegexp.exec(source.body)) && match.index < position) {
|
|
26
|
+
line++;
|
|
27
|
+
column = position + 1 - (match.index + match[0].length);
|
|
35
28
|
}
|
|
36
29
|
|
|
37
30
|
return {
|
|
38
31
|
line,
|
|
39
|
-
column
|
|
32
|
+
column,
|
|
40
33
|
};
|
|
41
34
|
}
|
|
35
|
+
/** @internal */
|
|
36
|
+
|
|
37
|
+
export function getLocations(locations) {
|
|
38
|
+
if (locations.length < 2) {
|
|
39
|
+
return locations.map(({ source, start }) => getLocation(source, start));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const bySource = new Map();
|
|
43
|
+
locations.forEach(({ source, start }, index) => {
|
|
44
|
+
let positions = bySource.get(source);
|
|
45
|
+
|
|
46
|
+
if (positions === undefined) {
|
|
47
|
+
positions = [];
|
|
48
|
+
bySource.set(source, positions);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
positions.push({
|
|
52
|
+
position: start,
|
|
53
|
+
index,
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
const result = new Array(locations.length);
|
|
57
|
+
|
|
58
|
+
for (const [source, positions] of bySource) {
|
|
59
|
+
const lineRegexp = /\r\n|[\n\r]/g;
|
|
60
|
+
let match = lineRegexp.exec(source.body);
|
|
61
|
+
let line = 1;
|
|
62
|
+
let lastLineStart = 0; // These arrays are local; sorting never changes the caller's input.
|
|
63
|
+
|
|
64
|
+
positions.sort((a, b) => a.position - b.position);
|
|
65
|
+
|
|
66
|
+
for (const { position, index } of positions) {
|
|
67
|
+
while (match !== null && match.index < position) {
|
|
68
|
+
lastLineStart = match.index + match[0].length;
|
|
69
|
+
line++;
|
|
70
|
+
match = lineRegexp.exec(source.body);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
result[index] = {
|
|
74
|
+
line,
|
|
75
|
+
column: position + 1 - lastLineStart,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return result;
|
|
81
|
+
}
|
package/language/parser.d.ts
CHANGED
|
@@ -66,11 +66,22 @@ export interface ParseOptions {
|
|
|
66
66
|
*/
|
|
67
67
|
noLocation?: boolean;
|
|
68
68
|
/**
|
|
69
|
-
* Parser CPU and memory usage is linear to the number of tokens in a
|
|
70
|
-
* however in extreme cases it becomes quadratic due to memory
|
|
71
|
-
* Parsing happens before validation so even invalid queries can
|
|
72
|
-
* CPU time and memory.
|
|
73
|
-
*
|
|
69
|
+
* Parser CPU and memory usage is linear to the number of lexical tokens in a
|
|
70
|
+
* document; however, in extreme cases it becomes quadratic due to memory
|
|
71
|
+
* exhaustion. Parsing happens before validation, so even invalid queries can
|
|
72
|
+
* consume significant CPU time and memory.
|
|
73
|
+
*
|
|
74
|
+
* Use this option to limit the number of lexical tokens allowed in a document.
|
|
75
|
+
* This does not limit the length of the source text or of an individual token.
|
|
76
|
+
*/
|
|
77
|
+
maxLexicalTokens?: number | undefined;
|
|
78
|
+
/** Maximum number of comments. */
|
|
79
|
+
maxComments?: number | undefined;
|
|
80
|
+
/** Maximum source length in UTF-16 code units. */
|
|
81
|
+
maxSourceLength?: number | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Deprecated alias for `maxLexicalTokens`.
|
|
84
|
+
* @deprecated Use `maxLexicalTokens` instead. Will be removed in v18.
|
|
74
85
|
*/
|
|
75
86
|
maxTokens?: number | undefined;
|
|
76
87
|
/**
|
|
@@ -82,7 +93,7 @@ export interface ParseOptions {
|
|
|
82
93
|
* @example
|
|
83
94
|
* The syntax is identical to normal, query-defined variables.
|
|
84
95
|
*
|
|
85
|
-
* ```graphql
|
|
96
|
+
* ```graphql prettier-ignore
|
|
86
97
|
* fragment A($var: Boolean = false) on T {
|
|
87
98
|
* ...
|
|
88
99
|
* }
|
|
@@ -100,7 +111,7 @@ export interface ParseOptions {
|
|
|
100
111
|
* If enabled, the parser will parse directives on directive definitions.
|
|
101
112
|
* This syntax is not part of the GraphQL specification and may change.
|
|
102
113
|
* @example
|
|
103
|
-
* ```graphql
|
|
114
|
+
* ```graphql prettier-ignore
|
|
104
115
|
* directive @foo @bar on FIELD
|
|
105
116
|
* ```
|
|
106
117
|
*/
|
|
@@ -134,7 +145,7 @@ export interface ParseOptions {
|
|
|
134
145
|
*
|
|
135
146
|
* const document = parse('fragment A($var: Boolean) on Query { field }', {
|
|
136
147
|
* allowLegacyFragmentVariables: true,
|
|
137
|
-
*
|
|
148
|
+
* maxLexicalTokens: 20,
|
|
138
149
|
* noLocation: true,
|
|
139
150
|
* });
|
|
140
151
|
* const directiveDocument = parse('directive @foo @bar on FIELD', {
|
|
@@ -720,15 +731,18 @@ export declare class Parser {
|
|
|
720
731
|
* @returns Parsed schema coordinate AST.
|
|
721
732
|
* @example
|
|
722
733
|
* ```ts
|
|
723
|
-
* import
|
|
734
|
+
* import assert from 'node:assert/strict';
|
|
735
|
+
* import { Kind, parseSchemaCoordinate } from 'graphql/language';
|
|
724
736
|
*
|
|
725
|
-
* const typeCoordinate =
|
|
726
|
-
* const directiveCoordinate =
|
|
737
|
+
* const typeCoordinate = parseSchemaCoordinate('User.name');
|
|
738
|
+
* const directiveCoordinate = parseSchemaCoordinate('@include(if:)');
|
|
739
|
+
* assert(typeCoordinate.kind === Kind.MEMBER_COORDINATE);
|
|
740
|
+
* assert(directiveCoordinate.kind === Kind.DIRECTIVE_ARGUMENT_COORDINATE);
|
|
727
741
|
*
|
|
728
742
|
* typeCoordinate.name.value; // => 'User'
|
|
729
743
|
* typeCoordinate.memberName?.value; // => 'name'
|
|
730
|
-
* directiveCoordinate.name.value; // => '
|
|
731
|
-
* directiveCoordinate.argumentName?.value; // => '
|
|
744
|
+
* directiveCoordinate.name.value; // => 'include'
|
|
745
|
+
* directiveCoordinate.argumentName?.value; // => 'if'
|
|
732
746
|
* ```
|
|
733
747
|
*/
|
|
734
748
|
parseSchemaCoordinate(): SchemaCoordinateNode;
|
package/language/parser.js
CHANGED
|
@@ -50,7 +50,7 @@ var _tokenKind = require('./tokenKind.js');
|
|
|
50
50
|
*
|
|
51
51
|
* const document = parse('fragment A($var: Boolean) on Query { field }', {
|
|
52
52
|
* allowLegacyFragmentVariables: true,
|
|
53
|
-
*
|
|
53
|
+
* maxLexicalTokens: 20,
|
|
54
54
|
* noLocation: true,
|
|
55
55
|
* });
|
|
56
56
|
* const directiveDocument = parse('directive @foo @bar on FIELD', {
|
|
@@ -216,6 +216,22 @@ class Parser {
|
|
|
216
216
|
|
|
217
217
|
this._options = _options;
|
|
218
218
|
this._tokenCounter = 0;
|
|
219
|
+
this._lexer._maxComments =
|
|
220
|
+
options === null || options === void 0 ? void 0 : options.maxComments;
|
|
221
|
+
this._lexer._commentCount = 0;
|
|
222
|
+
const maxSourceLength =
|
|
223
|
+
options === null || options === void 0 ? void 0 : options.maxSourceLength;
|
|
224
|
+
|
|
225
|
+
if (
|
|
226
|
+
maxSourceLength !== undefined &&
|
|
227
|
+
this._lexer.source.body.length > maxSourceLength
|
|
228
|
+
) {
|
|
229
|
+
throw (0, _syntaxError.syntaxError)(
|
|
230
|
+
this._lexer.source,
|
|
231
|
+
maxSourceLength,
|
|
232
|
+
`Source contains more than ${maxSourceLength} UTF-16 code units. Parsing aborted.`,
|
|
233
|
+
);
|
|
234
|
+
}
|
|
219
235
|
}
|
|
220
236
|
|
|
221
237
|
get tokenCount() {
|
|
@@ -1644,15 +1660,18 @@ class Parser {
|
|
|
1644
1660
|
* @returns Parsed schema coordinate AST.
|
|
1645
1661
|
* @example
|
|
1646
1662
|
* ```ts
|
|
1647
|
-
* import
|
|
1663
|
+
* import assert from 'node:assert/strict';
|
|
1664
|
+
* import { Kind, parseSchemaCoordinate } from 'graphql/language';
|
|
1648
1665
|
*
|
|
1649
|
-
* const typeCoordinate =
|
|
1650
|
-
* const directiveCoordinate =
|
|
1666
|
+
* const typeCoordinate = parseSchemaCoordinate('User.name');
|
|
1667
|
+
* const directiveCoordinate = parseSchemaCoordinate('@include(if:)');
|
|
1668
|
+
* assert(typeCoordinate.kind === Kind.MEMBER_COORDINATE);
|
|
1669
|
+
* assert(directiveCoordinate.kind === Kind.DIRECTIVE_ARGUMENT_COORDINATE);
|
|
1651
1670
|
*
|
|
1652
1671
|
* typeCoordinate.name.value; // => 'User'
|
|
1653
1672
|
* typeCoordinate.memberName?.value; // => 'name'
|
|
1654
|
-
* directiveCoordinate.name.value; // => '
|
|
1655
|
-
* directiveCoordinate.argumentName?.value; // => '
|
|
1673
|
+
* directiveCoordinate.name.value; // => 'include'
|
|
1674
|
+
* directiveCoordinate.argumentName?.value; // => 'if'
|
|
1656
1675
|
* ```
|
|
1657
1676
|
*/
|
|
1658
1677
|
|
|
@@ -1909,18 +1928,21 @@ class Parser {
|
|
|
1909
1928
|
}
|
|
1910
1929
|
|
|
1911
1930
|
advanceLexer() {
|
|
1912
|
-
const { maxTokens } = this._options;
|
|
1931
|
+
const { maxLexicalTokens = this._options.maxTokens } = this._options;
|
|
1913
1932
|
|
|
1914
1933
|
const token = this._lexer.advance();
|
|
1915
1934
|
|
|
1916
1935
|
if (token.kind !== _tokenKind.TokenKind.EOF) {
|
|
1917
1936
|
++this._tokenCounter;
|
|
1918
1937
|
|
|
1919
|
-
if (
|
|
1938
|
+
if (
|
|
1939
|
+
maxLexicalTokens !== undefined &&
|
|
1940
|
+
this._tokenCounter > maxLexicalTokens
|
|
1941
|
+
) {
|
|
1920
1942
|
throw (0, _syntaxError.syntaxError)(
|
|
1921
1943
|
this._lexer.source,
|
|
1922
1944
|
token.start,
|
|
1923
|
-
`Document contains more that ${
|
|
1945
|
+
`Document contains more that ${maxLexicalTokens} tokens. Parsing aborted.`,
|
|
1924
1946
|
);
|
|
1925
1947
|
}
|
|
1926
1948
|
}
|
package/language/parser.mjs
CHANGED
|
@@ -31,7 +31,7 @@ import { TokenKind } from './tokenKind.mjs';
|
|
|
31
31
|
*
|
|
32
32
|
* const document = parse('fragment A($var: Boolean) on Query { field }', {
|
|
33
33
|
* allowLegacyFragmentVariables: true,
|
|
34
|
-
*
|
|
34
|
+
* maxLexicalTokens: 20,
|
|
35
35
|
* noLocation: true,
|
|
36
36
|
* });
|
|
37
37
|
* const directiveDocument = parse('directive @foo @bar on FIELD', {
|
|
@@ -193,6 +193,22 @@ export class Parser {
|
|
|
193
193
|
|
|
194
194
|
this._options = _options;
|
|
195
195
|
this._tokenCounter = 0;
|
|
196
|
+
this._lexer._maxComments =
|
|
197
|
+
options === null || options === void 0 ? void 0 : options.maxComments;
|
|
198
|
+
this._lexer._commentCount = 0;
|
|
199
|
+
const maxSourceLength =
|
|
200
|
+
options === null || options === void 0 ? void 0 : options.maxSourceLength;
|
|
201
|
+
|
|
202
|
+
if (
|
|
203
|
+
maxSourceLength !== undefined &&
|
|
204
|
+
this._lexer.source.body.length > maxSourceLength
|
|
205
|
+
) {
|
|
206
|
+
throw syntaxError(
|
|
207
|
+
this._lexer.source,
|
|
208
|
+
maxSourceLength,
|
|
209
|
+
`Source contains more than ${maxSourceLength} UTF-16 code units. Parsing aborted.`,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
196
212
|
}
|
|
197
213
|
|
|
198
214
|
get tokenCount() {
|
|
@@ -1596,15 +1612,18 @@ export class Parser {
|
|
|
1596
1612
|
* @returns Parsed schema coordinate AST.
|
|
1597
1613
|
* @example
|
|
1598
1614
|
* ```ts
|
|
1599
|
-
* import
|
|
1615
|
+
* import assert from 'node:assert/strict';
|
|
1616
|
+
* import { Kind, parseSchemaCoordinate } from 'graphql/language';
|
|
1600
1617
|
*
|
|
1601
|
-
* const typeCoordinate =
|
|
1602
|
-
* const directiveCoordinate =
|
|
1618
|
+
* const typeCoordinate = parseSchemaCoordinate('User.name');
|
|
1619
|
+
* const directiveCoordinate = parseSchemaCoordinate('@include(if:)');
|
|
1620
|
+
* assert(typeCoordinate.kind === Kind.MEMBER_COORDINATE);
|
|
1621
|
+
* assert(directiveCoordinate.kind === Kind.DIRECTIVE_ARGUMENT_COORDINATE);
|
|
1603
1622
|
*
|
|
1604
1623
|
* typeCoordinate.name.value; // => 'User'
|
|
1605
1624
|
* typeCoordinate.memberName?.value; // => 'name'
|
|
1606
|
-
* directiveCoordinate.name.value; // => '
|
|
1607
|
-
* directiveCoordinate.argumentName?.value; // => '
|
|
1625
|
+
* directiveCoordinate.name.value; // => 'include'
|
|
1626
|
+
* directiveCoordinate.argumentName?.value; // => 'if'
|
|
1608
1627
|
* ```
|
|
1609
1628
|
*/
|
|
1610
1629
|
|
|
@@ -1861,18 +1880,21 @@ export class Parser {
|
|
|
1861
1880
|
}
|
|
1862
1881
|
|
|
1863
1882
|
advanceLexer() {
|
|
1864
|
-
const { maxTokens } = this._options;
|
|
1883
|
+
const { maxLexicalTokens = this._options.maxTokens } = this._options;
|
|
1865
1884
|
|
|
1866
1885
|
const token = this._lexer.advance();
|
|
1867
1886
|
|
|
1868
1887
|
if (token.kind !== TokenKind.EOF) {
|
|
1869
1888
|
++this._tokenCounter;
|
|
1870
1889
|
|
|
1871
|
-
if (
|
|
1890
|
+
if (
|
|
1891
|
+
maxLexicalTokens !== undefined &&
|
|
1892
|
+
this._tokenCounter > maxLexicalTokens
|
|
1893
|
+
) {
|
|
1872
1894
|
throw syntaxError(
|
|
1873
1895
|
this._lexer.source,
|
|
1874
1896
|
token.start,
|
|
1875
|
-
`Document contains more that ${
|
|
1897
|
+
`Document contains more that ${maxLexicalTokens} tokens. Parsing aborted.`,
|
|
1876
1898
|
);
|
|
1877
1899
|
}
|
|
1878
1900
|
}
|
package/language/predicates.d.ts
CHANGED
|
@@ -54,8 +54,11 @@ export declare function isExecutableDefinitionNode(
|
|
|
54
54
|
* ```ts
|
|
55
55
|
* import { Kind, isSelectionNode } from 'graphql/language';
|
|
56
56
|
*
|
|
57
|
-
* const field = {
|
|
58
|
-
*
|
|
57
|
+
* const field = {
|
|
58
|
+
* kind: Kind.FIELD,
|
|
59
|
+
* name: { kind: Kind.NAME, value: 'hello' },
|
|
60
|
+
* } as const;
|
|
61
|
+
* const document = { kind: Kind.DOCUMENT, definitions: [] } as const;
|
|
59
62
|
*
|
|
60
63
|
* isSelectionNode(field); // => true
|
|
61
64
|
* isSelectionNode(document); // => false
|
|
@@ -84,7 +87,11 @@ export declare function isValueNode(node: ASTNode): node is ValueNode;
|
|
|
84
87
|
* @returns True when the AST node is a constant value node.
|
|
85
88
|
* @example
|
|
86
89
|
* ```ts
|
|
87
|
-
* import {
|
|
90
|
+
* import {
|
|
91
|
+
* parseConstValue,
|
|
92
|
+
* parseValue,
|
|
93
|
+
* isConstValueNode,
|
|
94
|
+
* } from 'graphql/language';
|
|
88
95
|
*
|
|
89
96
|
* const value = parseConstValue('[42]');
|
|
90
97
|
* const variable = parseValue('$id');
|
package/language/predicates.js
CHANGED
|
@@ -70,8 +70,11 @@ function isExecutableDefinitionNode(node) {
|
|
|
70
70
|
* ```ts
|
|
71
71
|
* import { Kind, isSelectionNode } from 'graphql/language';
|
|
72
72
|
*
|
|
73
|
-
* const field = {
|
|
74
|
-
*
|
|
73
|
+
* const field = {
|
|
74
|
+
* kind: Kind.FIELD,
|
|
75
|
+
* name: { kind: Kind.NAME, value: 'hello' },
|
|
76
|
+
* } as const;
|
|
77
|
+
* const document = { kind: Kind.DOCUMENT, definitions: [] } as const;
|
|
75
78
|
*
|
|
76
79
|
* isSelectionNode(field); // => true
|
|
77
80
|
* isSelectionNode(document); // => false
|
|
@@ -120,7 +123,11 @@ function isValueNode(node) {
|
|
|
120
123
|
* @returns True when the AST node is a constant value node.
|
|
121
124
|
* @example
|
|
122
125
|
* ```ts
|
|
123
|
-
* import {
|
|
126
|
+
* import {
|
|
127
|
+
* parseConstValue,
|
|
128
|
+
* parseValue,
|
|
129
|
+
* isConstValueNode,
|
|
130
|
+
* } from 'graphql/language';
|
|
124
131
|
*
|
|
125
132
|
* const value = parseConstValue('[42]');
|
|
126
133
|
* const variable = parseValue('$id');
|
package/language/predicates.mjs
CHANGED
|
@@ -52,8 +52,11 @@ export function isExecutableDefinitionNode(node) {
|
|
|
52
52
|
* ```ts
|
|
53
53
|
* import { Kind, isSelectionNode } from 'graphql/language';
|
|
54
54
|
*
|
|
55
|
-
* const field = {
|
|
56
|
-
*
|
|
55
|
+
* const field = {
|
|
56
|
+
* kind: Kind.FIELD,
|
|
57
|
+
* name: { kind: Kind.NAME, value: 'hello' },
|
|
58
|
+
* } as const;
|
|
59
|
+
* const document = { kind: Kind.DOCUMENT, definitions: [] } as const;
|
|
57
60
|
*
|
|
58
61
|
* isSelectionNode(field); // => true
|
|
59
62
|
* isSelectionNode(document); // => false
|
|
@@ -102,7 +105,11 @@ export function isValueNode(node) {
|
|
|
102
105
|
* @returns True when the AST node is a constant value node.
|
|
103
106
|
* @example
|
|
104
107
|
* ```ts
|
|
105
|
-
* import {
|
|
108
|
+
* import {
|
|
109
|
+
* parseConstValue,
|
|
110
|
+
* parseValue,
|
|
111
|
+
* isConstValueNode,
|
|
112
|
+
* } from 'graphql/language';
|
|
106
113
|
*
|
|
107
114
|
* const value = parseConstValue('[42]');
|
|
108
115
|
* const variable = parseValue('$id');
|
|
@@ -14,9 +14,7 @@ import type { Source } from './source';
|
|
|
14
14
|
* const location = document.definitions[0].loc;
|
|
15
15
|
*
|
|
16
16
|
* if (location) {
|
|
17
|
-
* const printed = printLocation(location);
|
|
18
|
-
*
|
|
19
|
-
* printed; // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n | ^'
|
|
17
|
+
* const printed = printLocation(location); // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n | ^'
|
|
20
18
|
* }
|
|
21
19
|
* ```
|
|
22
20
|
*/
|
|
@@ -31,9 +29,7 @@ export declare function printLocation(location: Location): string;
|
|
|
31
29
|
* import { Source, printSourceLocation } from 'graphql/language';
|
|
32
30
|
*
|
|
33
31
|
* const source = new Source('type Query { hello: String }');
|
|
34
|
-
* const printed = printSourceLocation(source, { line: 1, column: 14 });
|
|
35
|
-
*
|
|
36
|
-
* printed; // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n | ^'
|
|
32
|
+
* const printed = printSourceLocation(source, { line: 1, column: 14 }); // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n | ^'
|
|
37
33
|
* ```
|
|
38
34
|
*/
|
|
39
35
|
export declare function printSourceLocation(
|
|
@@ -22,9 +22,7 @@ var _location = require('./location.js');
|
|
|
22
22
|
* const location = document.definitions[0].loc;
|
|
23
23
|
*
|
|
24
24
|
* if (location) {
|
|
25
|
-
* const printed = printLocation(location);
|
|
26
|
-
*
|
|
27
|
-
* printed; // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n | ^'
|
|
25
|
+
* const printed = printLocation(location); // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n | ^'
|
|
28
26
|
* }
|
|
29
27
|
* ```
|
|
30
28
|
*/
|
|
@@ -44,9 +42,7 @@ function printLocation(location) {
|
|
|
44
42
|
* import { Source, printSourceLocation } from 'graphql/language';
|
|
45
43
|
*
|
|
46
44
|
* const source = new Source('type Query { hello: String }');
|
|
47
|
-
* const printed = printSourceLocation(source, { line: 1, column: 14 });
|
|
48
|
-
*
|
|
49
|
-
* printed; // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n | ^'
|
|
45
|
+
* const printed = printSourceLocation(source, { line: 1, column: 14 }); // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n | ^'
|
|
50
46
|
* ```
|
|
51
47
|
*/
|
|
52
48
|
|
|
@@ -13,9 +13,7 @@ import { getLocation } from './location.mjs';
|
|
|
13
13
|
* const location = document.definitions[0].loc;
|
|
14
14
|
*
|
|
15
15
|
* if (location) {
|
|
16
|
-
* const printed = printLocation(location);
|
|
17
|
-
*
|
|
18
|
-
* printed; // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n | ^'
|
|
16
|
+
* const printed = printLocation(location); // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n | ^'
|
|
19
17
|
* }
|
|
20
18
|
* ```
|
|
21
19
|
*/
|
|
@@ -35,9 +33,7 @@ export function printLocation(location) {
|
|
|
35
33
|
* import { Source, printSourceLocation } from 'graphql/language';
|
|
36
34
|
*
|
|
37
35
|
* const source = new Source('type Query { hello: String }');
|
|
38
|
-
* const printed = printSourceLocation(source, { line: 1, column: 14 });
|
|
39
|
-
*
|
|
40
|
-
* printed; // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n | ^'
|
|
36
|
+
* const printed = printSourceLocation(source, { line: 1, column: 14 }); // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n | ^'
|
|
41
37
|
* ```
|
|
42
38
|
*/
|
|
43
39
|
|
package/language/printer.d.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
/** @category Printing */
|
|
2
2
|
import type { ASTNode } from './ast';
|
|
3
|
+
interface PrintOptions {
|
|
4
|
+
/** Maximum indentation depth. Defaults to Infinity. */
|
|
5
|
+
maxIndentDepth?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Prints an AST with indentation and inserted newlines disabled at the given depth.
|
|
9
|
+
* @param ast - The GraphQL AST node to print.
|
|
10
|
+
* @param options - Output configuration.
|
|
11
|
+
* Indentation depth defaults to `Infinity`.
|
|
12
|
+
* @returns A string representation of the AST.
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { parse, print } from 'graphql/language';
|
|
16
|
+
*
|
|
17
|
+
* print(parse('{ a { b } }'), { maxIndentDepth: 0 }); // => '{ a { b } }'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function print(ast: ASTNode, options: PrintOptions): string;
|
|
3
21
|
/**
|
|
4
22
|
* Converts an AST into a string, using one set of reasonable
|
|
5
23
|
* formatting rules.
|
|
@@ -10,9 +28,10 @@ import type { ASTNode } from './ast';
|
|
|
10
28
|
* import { parse, print } from 'graphql';
|
|
11
29
|
*
|
|
12
30
|
* const ast = parse('{ hero { name } }');
|
|
13
|
-
* const text = print(ast);
|
|
14
|
-
*
|
|
15
|
-
* text; // => '{\n hero {\n name\n }\n}'
|
|
31
|
+
* const text = print(ast); // => '{\n hero {\n name\n }\n}'
|
|
16
32
|
* ```
|
|
17
33
|
*/
|
|
18
34
|
export declare function print(ast: ASTNode): string;
|
|
35
|
+
/** @internal */
|
|
36
|
+
export declare function printForError(ast: ASTNode): string;
|
|
37
|
+
export {};
|