graphql 14.0.2 → 14.2.1
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/LICENSE +1 -1
- package/README.md +5 -5
- package/codecov.yml +14 -0
- package/error/GraphQLError.js +2 -2
- package/error/GraphQLError.js.flow +4 -4
- package/error/GraphQLError.mjs +2 -2
- package/error/formatError.js +2 -2
- package/error/formatError.js.flow +1 -1
- package/error/formatError.mjs +2 -2
- package/error/index.js.flow +1 -1
- package/error/index.mjs +2 -2
- package/error/locatedError.js +2 -2
- package/error/locatedError.js.flow +1 -1
- package/error/locatedError.mjs +2 -2
- package/error/printError.js +2 -2
- package/error/printError.js.flow +1 -1
- package/error/printError.mjs +2 -2
- package/error/syntaxError.js +2 -2
- package/error/syntaxError.js.flow +1 -1
- package/error/syntaxError.mjs +2 -2
- package/execution/execute.js +20 -11
- package/execution/execute.js.flow +41 -27
- package/execution/execute.mjs +19 -13
- package/execution/index.js +6 -0
- package/execution/index.js.flow +7 -2
- package/execution/index.mjs +3 -3
- package/execution/values.js +10 -10
- package/execution/values.js.flow +8 -8
- package/execution/values.mjs +9 -9
- package/graphql.js +8 -8
- package/graphql.js.flow +18 -4
- package/graphql.mjs +8 -8
- package/index.js +18 -0
- package/index.js.flow +4 -1
- package/index.mjs +4 -4
- package/jsutils/ObjMap.js.flow +1 -1
- package/jsutils/{MaybePromise.js → PromiseOrValue.js} +0 -0
- package/jsutils/{MaybePromise.js.flow → PromiseOrValue.js.flow} +2 -2
- package/jsutils/{MaybePromise.mjs → PromiseOrValue.mjs} +0 -0
- package/jsutils/dedent.js +2 -2
- package/jsutils/dedent.js.flow +1 -1
- package/jsutils/dedent.mjs +2 -2
- package/jsutils/defineToJSON.js +18 -7
- package/jsutils/defineToJSON.js.flow +15 -6
- package/jsutils/defineToJSON.mjs +15 -7
- package/jsutils/defineToStringTag.js +6 -6
- package/jsutils/defineToStringTag.js.flow +4 -4
- package/jsutils/defineToStringTag.mjs +5 -5
- package/jsutils/inspect.js +109 -23
- package/jsutils/inspect.js.flow +112 -14
- package/jsutils/inspect.mjs +108 -17
- package/jsutils/instanceOf.js +2 -2
- package/jsutils/instanceOf.js.flow +1 -1
- package/jsutils/instanceOf.mjs +2 -2
- package/jsutils/invariant.js +2 -2
- package/jsutils/invariant.js.flow +1 -1
- package/jsutils/invariant.mjs +2 -2
- package/jsutils/isInvalid.js +2 -2
- package/jsutils/isInvalid.js.flow +1 -1
- package/jsutils/isInvalid.mjs +2 -2
- package/jsutils/isNullish.js +2 -2
- package/jsutils/isNullish.js.flow +1 -1
- package/jsutils/isNullish.mjs +2 -2
- package/jsutils/isPromise.js +2 -2
- package/jsutils/isPromise.js.flow +1 -1
- package/jsutils/isPromise.mjs +2 -2
- package/jsutils/keyMap.js +2 -2
- package/jsutils/keyMap.js.flow +1 -1
- package/jsutils/keyMap.mjs +2 -2
- package/jsutils/keyValMap.js +2 -2
- package/jsutils/keyValMap.js.flow +1 -1
- package/jsutils/keyValMap.mjs +2 -2
- package/jsutils/mapValue.js +54 -0
- package/jsutils/mapValue.js.flow +27 -0
- package/jsutils/mapValue.mjs +44 -0
- package/jsutils/memoize3.js +2 -2
- package/jsutils/memoize3.js.flow +1 -1
- package/jsutils/memoize3.mjs +2 -2
- package/jsutils/nodejsCustomInspectSymbol.js +18 -0
- package/jsutils/nodejsCustomInspectSymbol.js.flow +15 -0
- package/jsutils/nodejsCustomInspectSymbol.mjs +10 -0
- package/jsutils/orList.js +18 -5
- package/jsutils/orList.js.flow +14 -8
- package/jsutils/orList.mjs +15 -5
- package/jsutils/promiseForObject.js +2 -2
- package/jsutils/promiseForObject.js.flow +1 -1
- package/jsutils/promiseForObject.mjs +2 -2
- package/jsutils/promiseReduce.js +2 -2
- package/jsutils/promiseReduce.js.flow +5 -5
- package/jsutils/promiseReduce.mjs +2 -2
- package/jsutils/quotedOrList.js +2 -2
- package/jsutils/quotedOrList.js.flow +1 -1
- package/jsutils/quotedOrList.mjs +2 -2
- package/jsutils/suggestionList.js +2 -2
- package/jsutils/suggestionList.js.flow +1 -1
- package/jsutils/suggestionList.mjs +2 -2
- package/language/ast.js.flow +1 -1
- package/language/{blockStringValue.mjs → blockString.js} +39 -3
- package/language/{blockStringValue.js.flow → blockString.js.flow} +31 -2
- package/language/{blockStringValue.js → blockString.mjs} +31 -10
- package/language/directiveLocation.js +2 -2
- package/language/directiveLocation.js.flow +1 -1
- package/language/directiveLocation.mjs +2 -2
- package/language/index.js.flow +1 -1
- package/language/index.mjs +2 -2
- package/language/kinds.js +2 -2
- package/language/kinds.js.flow +1 -1
- package/language/kinds.mjs +2 -2
- package/language/lexer.js +60 -46
- package/language/lexer.js.flow +71 -69
- package/language/lexer.mjs +58 -45
- package/language/location.js +2 -2
- package/language/location.js.flow +1 -1
- package/language/location.mjs +2 -2
- package/language/parser.js +84 -83
- package/language/parser.js.flow +85 -94
- package/language/parser.mjs +83 -83
- package/language/predicates.js +2 -2
- package/language/predicates.js.flow +1 -1
- package/language/predicates.mjs +2 -2
- package/language/printer.js +15 -17
- package/language/printer.js.flow +21 -20
- package/language/printer.mjs +14 -17
- package/language/source.js +8 -7
- package/language/source.js.flow +1 -1
- package/language/source.mjs +2 -10
- package/language/visitor.js +7 -6
- package/language/visitor.js.flow +3 -5
- package/language/visitor.mjs +7 -6
- package/package.json +5 -2
- package/polyfills/find.js +31 -0
- package/polyfills/find.js.flow +29 -0
- package/polyfills/find.mjs +23 -0
- package/polyfills/flatMap.js +38 -0
- package/polyfills/flatMap.js.flow +34 -0
- package/polyfills/flatMap.mjs +30 -0
- package/{jsutils → polyfills}/isFinite.js +2 -2
- package/{jsutils → polyfills}/isFinite.js.flow +1 -1
- package/{jsutils → polyfills}/isFinite.mjs +2 -2
- package/{jsutils → polyfills}/isInteger.js +2 -2
- package/{jsutils → polyfills}/isInteger.js.flow +1 -1
- package/{jsutils → polyfills}/isInteger.mjs +2 -2
- package/polyfills/objectEntries.js +26 -0
- package/polyfills/objectEntries.js.flow +19 -0
- package/polyfills/objectEntries.mjs +18 -0
- package/{jsutils → polyfills}/objectValues.js +2 -2
- package/{jsutils → polyfills}/objectValues.js.flow +2 -2
- package/{jsutils → polyfills}/objectValues.mjs +2 -2
- package/subscription/asyncIteratorReject.js.flow +1 -1
- package/subscription/asyncIteratorReject.mjs +2 -2
- package/subscription/index.js.flow +1 -1
- package/subscription/index.mjs +2 -2
- package/subscription/mapAsyncIterator.js.flow +5 -5
- package/subscription/mapAsyncIterator.mjs +2 -2
- package/subscription/subscribe.js +2 -2
- package/subscription/subscribe.js.flow +1 -1
- package/subscription/subscribe.mjs +2 -2
- package/type/definition.js +161 -138
- package/type/definition.js.flow +193 -57
- package/type/definition.mjs +158 -140
- package/type/directives.js +35 -29
- package/type/directives.js.flow +39 -21
- package/type/directives.mjs +34 -31
- package/type/index.js +12 -0
- package/type/index.js.flow +5 -1
- package/type/index.mjs +6 -4
- package/type/introspection.js +11 -7
- package/type/introspection.js.flow +11 -8
- package/type/introspection.mjs +11 -7
- package/type/scalars.js +45 -34
- package/type/scalars.js.flow +41 -27
- package/type/scalars.mjs +45 -27
- package/type/schema.js +134 -88
- package/type/schema.js.flow +77 -11
- package/type/schema.mjs +132 -88
- package/type/validate.js +152 -187
- package/type/validate.js.flow +12 -61
- package/type/validate.mjs +143 -188
- package/utilities/TypeInfo.js +10 -23
- package/utilities/TypeInfo.js.flow +2 -2
- package/utilities/TypeInfo.mjs +3 -25
- package/utilities/assertValidName.js +2 -2
- package/utilities/assertValidName.js.flow +1 -1
- package/utilities/assertValidName.mjs +2 -2
- package/utilities/astFromValue.js +7 -6
- package/utilities/astFromValue.js.flow +7 -6
- package/utilities/astFromValue.mjs +9 -8
- package/utilities/buildASTSchema.js +213 -197
- package/utilities/buildASTSchema.js.flow +163 -173
- package/utilities/buildASTSchema.mjs +203 -198
- package/utilities/buildClientSchema.js +39 -47
- package/utilities/buildClientSchema.js.flow +49 -58
- package/utilities/buildClientSchema.mjs +38 -46
- package/utilities/coerceValue.js +41 -21
- package/utilities/coerceValue.js.flow +44 -49
- package/utilities/coerceValue.mjs +42 -23
- package/utilities/concatAST.js +9 -13
- package/utilities/concatAST.js.flow +3 -9
- package/utilities/concatAST.mjs +6 -13
- package/utilities/extendSchema.js +256 -630
- package/utilities/extendSchema.js.flow +190 -426
- package/utilities/extendSchema.mjs +256 -631
- package/utilities/findBreakingChanges.js +8 -6
- package/utilities/findBreakingChanges.js.flow +4 -3
- package/utilities/findBreakingChanges.mjs +7 -6
- package/utilities/findDeprecatedUsages.js +4 -4
- package/utilities/findDeprecatedUsages.js.flow +3 -3
- package/utilities/findDeprecatedUsages.mjs +4 -4
- package/utilities/getOperationAST.js +2 -2
- package/utilities/getOperationAST.js.flow +1 -1
- package/utilities/getOperationAST.mjs +2 -2
- package/utilities/getOperationRootType.js +6 -6
- package/utilities/getOperationRootType.js.flow +9 -7
- package/utilities/getOperationRootType.mjs +6 -6
- package/utilities/index.js.flow +1 -1
- package/utilities/index.mjs +2 -2
- package/utilities/introspectionFromSchema.js +2 -2
- package/utilities/introspectionFromSchema.js.flow +1 -1
- package/utilities/introspectionFromSchema.mjs +2 -2
- package/utilities/introspectionQuery.js +2 -2
- package/utilities/introspectionQuery.js.flow +1 -1
- package/utilities/introspectionQuery.mjs +2 -2
- package/utilities/isValidJSValue.js +4 -2
- package/utilities/isValidJSValue.js.flow +2 -1
- package/utilities/isValidJSValue.mjs +4 -2
- package/utilities/isValidLiteralValue.js +2 -2
- package/utilities/isValidLiteralValue.js.flow +1 -1
- package/utilities/isValidLiteralValue.mjs +2 -2
- package/utilities/lexicographicSortSchema.js +86 -124
- package/utilities/lexicographicSortSchema.js.flow +68 -96
- package/utilities/lexicographicSortSchema.mjs +86 -124
- package/utilities/schemaPrinter.js +47 -73
- package/utilities/schemaPrinter.js.flow +62 -111
- package/utilities/schemaPrinter.mjs +46 -73
- package/utilities/separateOperations.js +11 -10
- package/utilities/separateOperations.js.flow +1 -1
- package/utilities/separateOperations.mjs +11 -10
- package/utilities/typeComparators.js +2 -2
- package/utilities/typeComparators.js.flow +1 -1
- package/utilities/typeComparators.mjs +2 -2
- package/utilities/typeFromAST.js +9 -4
- package/utilities/typeFromAST.js.flow +5 -2
- package/utilities/typeFromAST.mjs +6 -4
- package/utilities/valueFromAST.js +9 -6
- package/utilities/valueFromAST.js.flow +5 -3
- package/utilities/valueFromAST.mjs +7 -5
- package/utilities/valueFromASTUntyped.js +7 -4
- package/utilities/valueFromASTUntyped.js.flow +5 -2
- package/utilities/valueFromASTUntyped.mjs +6 -4
- package/validation/ValidationContext.js +57 -82
- package/validation/ValidationContext.js.flow +53 -50
- package/validation/ValidationContext.mjs +53 -78
- package/validation/index.js.flow +1 -1
- package/validation/index.mjs +2 -2
- package/validation/rules/ExecutableDefinitions.js +3 -3
- package/validation/rules/ExecutableDefinitions.js.flow +3 -3
- package/validation/rules/ExecutableDefinitions.mjs +3 -3
- package/validation/rules/FieldsOnCorrectType.js +3 -3
- package/validation/rules/FieldsOnCorrectType.js.flow +2 -2
- package/validation/rules/FieldsOnCorrectType.mjs +3 -3
- package/validation/rules/FragmentsOnCompositeTypes.js +4 -4
- package/validation/rules/FragmentsOnCompositeTypes.js.flow +3 -3
- package/validation/rules/FragmentsOnCompositeTypes.mjs +4 -4
- package/validation/rules/KnownArgumentNames.js.flow +1 -1
- package/validation/rules/KnownArgumentNames.mjs +2 -2
- package/validation/rules/KnownDirectives.js +4 -4
- package/validation/rules/KnownDirectives.js.flow +5 -4
- package/validation/rules/KnownDirectives.mjs +4 -4
- package/validation/rules/KnownFragmentNames.js +3 -3
- package/validation/rules/KnownFragmentNames.js.flow +2 -2
- package/validation/rules/KnownFragmentNames.mjs +3 -3
- package/validation/rules/KnownTypeNames.js +60 -22
- package/validation/rules/KnownTypeNames.js.flow +55 -21
- package/validation/rules/KnownTypeNames.mjs +57 -22
- package/validation/rules/LoneAnonymousOperation.js +3 -3
- package/validation/rules/LoneAnonymousOperation.js.flow +2 -2
- package/validation/rules/LoneAnonymousOperation.mjs +3 -3
- package/validation/rules/LoneSchemaDefinition.js +2 -2
- package/validation/rules/LoneSchemaDefinition.js.flow +1 -1
- package/validation/rules/LoneSchemaDefinition.mjs +2 -2
- package/validation/rules/NoFragmentCycles.js +2 -2
- package/validation/rules/NoFragmentCycles.js.flow +3 -3
- package/validation/rules/NoFragmentCycles.mjs +2 -2
- package/validation/rules/NoUndefinedVariables.js +2 -2
- package/validation/rules/NoUndefinedVariables.js.flow +1 -1
- package/validation/rules/NoUndefinedVariables.mjs +2 -2
- package/validation/rules/NoUnusedFragments.js +10 -7
- package/validation/rules/NoUnusedFragments.js.flow +4 -4
- package/validation/rules/NoUnusedFragments.mjs +10 -7
- package/validation/rules/NoUnusedVariables.js +7 -5
- package/validation/rules/NoUnusedVariables.js.flow +4 -3
- package/validation/rules/NoUnusedVariables.mjs +7 -5
- package/validation/rules/OverlappingFieldsCanBeMerged.js +58 -33
- package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +4 -4
- package/validation/rules/OverlappingFieldsCanBeMerged.mjs +50 -34
- package/validation/rules/PossibleFragmentSpreads.js +4 -4
- package/validation/rules/PossibleFragmentSpreads.js.flow +3 -3
- package/validation/rules/PossibleFragmentSpreads.mjs +4 -4
- package/validation/rules/PossibleTypeExtensions.js +158 -0
- package/validation/rules/PossibleTypeExtensions.js.flow +160 -0
- package/validation/rules/PossibleTypeExtensions.mjs +146 -0
- package/validation/rules/ProvidedRequiredArguments.js +3 -3
- package/validation/rules/ProvidedRequiredArguments.js.flow +4 -4
- package/validation/rules/ProvidedRequiredArguments.mjs +5 -5
- package/validation/rules/ScalarLeafs.js +4 -4
- package/validation/rules/ScalarLeafs.js.flow +3 -3
- package/validation/rules/ScalarLeafs.mjs +4 -4
- package/validation/rules/SingleFieldSubscriptions.js +2 -2
- package/validation/rules/SingleFieldSubscriptions.js.flow +1 -1
- package/validation/rules/SingleFieldSubscriptions.mjs +2 -2
- package/validation/rules/UniqueArgumentNames.js +2 -2
- package/validation/rules/UniqueArgumentNames.js.flow +1 -1
- package/validation/rules/UniqueArgumentNames.mjs +2 -2
- package/validation/rules/UniqueDirectiveNames.js +55 -0
- package/validation/rules/UniqueDirectiveNames.js.flow +64 -0
- package/validation/rules/UniqueDirectiveNames.mjs +43 -0
- package/validation/rules/UniqueDirectivesPerLocation.js +2 -2
- package/validation/rules/UniqueDirectivesPerLocation.js.flow +1 -1
- package/validation/rules/UniqueDirectivesPerLocation.mjs +2 -2
- package/validation/rules/UniqueEnumValueNames.js +90 -0
- package/validation/rules/UniqueEnumValueNames.js.flow +85 -0
- package/validation/rules/UniqueEnumValueNames.mjs +77 -0
- package/validation/rules/UniqueFieldDefinitionNames.js +101 -0
- package/validation/rules/UniqueFieldDefinitionNames.js.flow +99 -0
- package/validation/rules/UniqueFieldDefinitionNames.mjs +88 -0
- package/validation/rules/UniqueFragmentNames.js +2 -2
- package/validation/rules/UniqueFragmentNames.js.flow +1 -1
- package/validation/rules/UniqueFragmentNames.mjs +2 -2
- package/validation/rules/UniqueInputFieldNames.js +2 -4
- package/validation/rules/UniqueInputFieldNames.js.flow +1 -2
- package/validation/rules/UniqueInputFieldNames.mjs +2 -4
- package/validation/rules/UniqueOperationNames.js +2 -2
- package/validation/rules/UniqueOperationNames.js.flow +1 -1
- package/validation/rules/UniqueOperationNames.mjs +2 -2
- package/validation/rules/UniqueOperationTypes.js +85 -0
- package/validation/rules/UniqueOperationTypes.js.flow +76 -0
- package/validation/rules/UniqueOperationTypes.mjs +73 -0
- package/validation/rules/UniqueTypeNames.js +62 -0
- package/validation/rules/UniqueTypeNames.js.flow +67 -0
- package/validation/rules/UniqueTypeNames.mjs +50 -0
- package/validation/rules/UniqueVariableNames.js +2 -2
- package/validation/rules/UniqueVariableNames.js.flow +1 -1
- package/validation/rules/UniqueVariableNames.mjs +2 -2
- package/validation/rules/ValuesOfCorrectType.js +30 -14
- package/validation/rules/ValuesOfCorrectType.js.flow +5 -6
- package/validation/rules/ValuesOfCorrectType.mjs +29 -14
- package/validation/rules/VariablesAreInputTypes.js +3 -3
- package/validation/rules/VariablesAreInputTypes.js.flow +2 -2
- package/validation/rules/VariablesAreInputTypes.mjs +3 -3
- package/validation/rules/VariablesInAllowedPosition.js +5 -5
- package/validation/rules/VariablesInAllowedPosition.js.flow +1 -1
- package/validation/rules/VariablesInAllowedPosition.mjs +5 -5
- package/validation/specifiedRules.js +15 -3
- package/validation/specifiedRules.js.flow +14 -1
- package/validation/specifiedRules.mjs +9 -3
- package/validation/validate.js +2 -2
- package/validation/validate.js.flow +1 -1
- package/validation/validate.mjs +2 -2
- package/jsutils/find.js +0 -22
- package/jsutils/find.js.flow +0 -19
- package/jsutils/find.mjs +0 -15
package/language/parser.js.flow
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import inspect from '../jsutils/inspect';
|
|
11
|
+
import defineToJSON from '../jsutils/defineToJSON';
|
|
11
12
|
import { Source } from './source';
|
|
12
13
|
import { syntaxError } from '../error';
|
|
13
14
|
import type { GraphQLError } from '../error';
|
|
@@ -115,17 +116,6 @@ export type ParseOptions = {
|
|
|
115
116
|
* future.
|
|
116
117
|
*/
|
|
117
118
|
experimentalFragmentVariables?: boolean,
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* EXPERIMENTAL:
|
|
121
|
-
*
|
|
122
|
-
* If enabled, the parser understands directives on variable definitions:
|
|
123
|
-
*
|
|
124
|
-
* query Foo($var: String = "abc" @variable_definition_directive) {
|
|
125
|
-
* ...
|
|
126
|
-
* }
|
|
127
|
-
*/
|
|
128
|
-
experimentalVariableDefinitionDirectives?: boolean,
|
|
129
119
|
};
|
|
130
120
|
|
|
131
121
|
/**
|
|
@@ -160,9 +150,9 @@ export function parseValue(
|
|
|
160
150
|
): ValueNode {
|
|
161
151
|
const sourceObj = typeof source === 'string' ? new Source(source) : source;
|
|
162
152
|
const lexer = createLexer(sourceObj, options || {});
|
|
163
|
-
|
|
153
|
+
expectToken(lexer, TokenKind.SOF);
|
|
164
154
|
const value = parseValueLiteral(lexer, false);
|
|
165
|
-
|
|
155
|
+
expectToken(lexer, TokenKind.EOF);
|
|
166
156
|
return value;
|
|
167
157
|
}
|
|
168
158
|
|
|
@@ -182,9 +172,9 @@ export function parseType(
|
|
|
182
172
|
): TypeNode {
|
|
183
173
|
const sourceObj = typeof source === 'string' ? new Source(source) : source;
|
|
184
174
|
const lexer = createLexer(sourceObj, options || {});
|
|
185
|
-
|
|
175
|
+
expectToken(lexer, TokenKind.SOF);
|
|
186
176
|
const type = parseTypeReference(lexer);
|
|
187
|
-
|
|
177
|
+
expectToken(lexer, TokenKind.EOF);
|
|
188
178
|
return type;
|
|
189
179
|
}
|
|
190
180
|
|
|
@@ -192,7 +182,7 @@ export function parseType(
|
|
|
192
182
|
* Converts a name lex token into a name parse node.
|
|
193
183
|
*/
|
|
194
184
|
function parseName(lexer: Lexer<*>): NameNode {
|
|
195
|
-
const token =
|
|
185
|
+
const token = expectToken(lexer, TokenKind.NAME);
|
|
196
186
|
return {
|
|
197
187
|
kind: Kind.NAME,
|
|
198
188
|
value: ((token.value: any): string),
|
|
@@ -312,7 +302,7 @@ function parseOperationDefinition(lexer: Lexer<*>): OperationDefinitionNode {
|
|
|
312
302
|
* OperationType : one of query mutation subscription
|
|
313
303
|
*/
|
|
314
304
|
function parseOperationType(lexer: Lexer<*>): OperationTypeNode {
|
|
315
|
-
const operationToken =
|
|
305
|
+
const operationToken = expectToken(lexer, TokenKind.NAME);
|
|
316
306
|
switch (operationToken.value) {
|
|
317
307
|
case 'query':
|
|
318
308
|
return 'query';
|
|
@@ -341,26 +331,14 @@ function parseVariableDefinitions(
|
|
|
341
331
|
*/
|
|
342
332
|
function parseVariableDefinition(lexer: Lexer<*>): VariableDefinitionNode {
|
|
343
333
|
const start = lexer.token;
|
|
344
|
-
if (lexer.options.experimentalVariableDefinitionDirectives) {
|
|
345
|
-
return {
|
|
346
|
-
kind: Kind.VARIABLE_DEFINITION,
|
|
347
|
-
variable: parseVariable(lexer),
|
|
348
|
-
type: (expect(lexer, TokenKind.COLON), parseTypeReference(lexer)),
|
|
349
|
-
defaultValue: skip(lexer, TokenKind.EQUALS)
|
|
350
|
-
? parseValueLiteral(lexer, true)
|
|
351
|
-
: undefined,
|
|
352
|
-
directives: parseDirectives(lexer, true),
|
|
353
|
-
loc: loc(lexer, start),
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
|
|
357
334
|
return {
|
|
358
335
|
kind: Kind.VARIABLE_DEFINITION,
|
|
359
336
|
variable: parseVariable(lexer),
|
|
360
|
-
type: (
|
|
361
|
-
defaultValue:
|
|
337
|
+
type: (expectToken(lexer, TokenKind.COLON), parseTypeReference(lexer)),
|
|
338
|
+
defaultValue: expectOptionalToken(lexer, TokenKind.EQUALS)
|
|
362
339
|
? parseValueLiteral(lexer, true)
|
|
363
340
|
: undefined,
|
|
341
|
+
directives: parseDirectives(lexer, true),
|
|
364
342
|
loc: loc(lexer, start),
|
|
365
343
|
};
|
|
366
344
|
}
|
|
@@ -370,7 +348,7 @@ function parseVariableDefinition(lexer: Lexer<*>): VariableDefinitionNode {
|
|
|
370
348
|
*/
|
|
371
349
|
function parseVariable(lexer: Lexer<*>): VariableNode {
|
|
372
350
|
const start = lexer.token;
|
|
373
|
-
|
|
351
|
+
expectToken(lexer, TokenKind.DOLLAR);
|
|
374
352
|
return {
|
|
375
353
|
kind: Kind.VARIABLE,
|
|
376
354
|
name: parseName(lexer),
|
|
@@ -418,7 +396,7 @@ function parseField(lexer: Lexer<*>): FieldNode {
|
|
|
418
396
|
const nameOrAlias = parseName(lexer);
|
|
419
397
|
let alias;
|
|
420
398
|
let name;
|
|
421
|
-
if (
|
|
399
|
+
if (expectOptionalToken(lexer, TokenKind.COLON)) {
|
|
422
400
|
alias = nameOrAlias;
|
|
423
401
|
name = parseName(lexer);
|
|
424
402
|
} else {
|
|
@@ -456,10 +434,13 @@ function parseArguments(
|
|
|
456
434
|
*/
|
|
457
435
|
function parseArgument(lexer: Lexer<*>): ArgumentNode {
|
|
458
436
|
const start = lexer.token;
|
|
437
|
+
const name = parseName(lexer);
|
|
438
|
+
|
|
439
|
+
expectToken(lexer, TokenKind.COLON);
|
|
459
440
|
return {
|
|
460
441
|
kind: Kind.ARGUMENT,
|
|
461
|
-
name
|
|
462
|
-
value:
|
|
442
|
+
name,
|
|
443
|
+
value: parseValueLiteral(lexer, false),
|
|
463
444
|
loc: loc(lexer, start),
|
|
464
445
|
};
|
|
465
446
|
}
|
|
@@ -469,7 +450,7 @@ function parseConstArgument(lexer: Lexer<*>): ArgumentNode {
|
|
|
469
450
|
return {
|
|
470
451
|
kind: Kind.ARGUMENT,
|
|
471
452
|
name: parseName(lexer),
|
|
472
|
-
value: (
|
|
453
|
+
value: (expectToken(lexer, TokenKind.COLON), parseConstValue(lexer)),
|
|
473
454
|
loc: loc(lexer, start),
|
|
474
455
|
};
|
|
475
456
|
}
|
|
@@ -487,8 +468,10 @@ function parseFragment(
|
|
|
487
468
|
lexer: Lexer<*>,
|
|
488
469
|
): FragmentSpreadNode | InlineFragmentNode {
|
|
489
470
|
const start = lexer.token;
|
|
490
|
-
|
|
491
|
-
|
|
471
|
+
expectToken(lexer, TokenKind.SPREAD);
|
|
472
|
+
|
|
473
|
+
const hasTypeCondition = expectOptionalKeyword(lexer, 'on');
|
|
474
|
+
if (!hasTypeCondition && peek(lexer, TokenKind.NAME)) {
|
|
492
475
|
return {
|
|
493
476
|
kind: Kind.FRAGMENT_SPREAD,
|
|
494
477
|
name: parseFragmentName(lexer),
|
|
@@ -496,14 +479,9 @@ function parseFragment(
|
|
|
496
479
|
loc: loc(lexer, start),
|
|
497
480
|
};
|
|
498
481
|
}
|
|
499
|
-
let typeCondition;
|
|
500
|
-
if (lexer.token.value === 'on') {
|
|
501
|
-
lexer.advance();
|
|
502
|
-
typeCondition = parseNamedType(lexer);
|
|
503
|
-
}
|
|
504
482
|
return {
|
|
505
483
|
kind: Kind.INLINE_FRAGMENT,
|
|
506
|
-
typeCondition,
|
|
484
|
+
typeCondition: hasTypeCondition ? parseNamedType(lexer) : undefined,
|
|
507
485
|
directives: parseDirectives(lexer, false),
|
|
508
486
|
selectionSet: parseSelectionSet(lexer),
|
|
509
487
|
loc: loc(lexer, start),
|
|
@@ -668,14 +646,10 @@ function parseList(lexer: Lexer<*>, isConst: boolean): ListValueNode {
|
|
|
668
646
|
*/
|
|
669
647
|
function parseObject(lexer: Lexer<*>, isConst: boolean): ObjectValueNode {
|
|
670
648
|
const start = lexer.token;
|
|
671
|
-
|
|
672
|
-
const fields = [];
|
|
673
|
-
while (!skip(lexer, TokenKind.BRACE_R)) {
|
|
674
|
-
fields.push(parseObjectField(lexer, isConst));
|
|
675
|
-
}
|
|
649
|
+
const item = () => parseObjectField(lexer, isConst);
|
|
676
650
|
return {
|
|
677
651
|
kind: Kind.OBJECT,
|
|
678
|
-
fields,
|
|
652
|
+
fields: any(lexer, TokenKind.BRACE_L, item, TokenKind.BRACE_R),
|
|
679
653
|
loc: loc(lexer, start),
|
|
680
654
|
};
|
|
681
655
|
}
|
|
@@ -685,10 +659,13 @@ function parseObject(lexer: Lexer<*>, isConst: boolean): ObjectValueNode {
|
|
|
685
659
|
*/
|
|
686
660
|
function parseObjectField(lexer: Lexer<*>, isConst: boolean): ObjectFieldNode {
|
|
687
661
|
const start = lexer.token;
|
|
662
|
+
const name = parseName(lexer);
|
|
663
|
+
expectToken(lexer, TokenKind.COLON);
|
|
664
|
+
|
|
688
665
|
return {
|
|
689
666
|
kind: Kind.OBJECT_FIELD,
|
|
690
|
-
name
|
|
691
|
-
value:
|
|
667
|
+
name,
|
|
668
|
+
value: parseValueLiteral(lexer, isConst),
|
|
692
669
|
loc: loc(lexer, start),
|
|
693
670
|
};
|
|
694
671
|
}
|
|
@@ -714,7 +691,7 @@ function parseDirectives(
|
|
|
714
691
|
*/
|
|
715
692
|
function parseDirective(lexer: Lexer<*>, isConst: boolean): DirectiveNode {
|
|
716
693
|
const start = lexer.token;
|
|
717
|
-
|
|
694
|
+
expectToken(lexer, TokenKind.AT);
|
|
718
695
|
return {
|
|
719
696
|
kind: Kind.DIRECTIVE,
|
|
720
697
|
name: parseName(lexer),
|
|
@@ -734,9 +711,9 @@ function parseDirective(lexer: Lexer<*>, isConst: boolean): DirectiveNode {
|
|
|
734
711
|
export function parseTypeReference(lexer: Lexer<*>): TypeNode {
|
|
735
712
|
const start = lexer.token;
|
|
736
713
|
let type;
|
|
737
|
-
if (
|
|
714
|
+
if (expectOptionalToken(lexer, TokenKind.BRACKET_L)) {
|
|
738
715
|
type = parseTypeReference(lexer);
|
|
739
|
-
|
|
716
|
+
expectToken(lexer, TokenKind.BRACKET_R);
|
|
740
717
|
type = ({
|
|
741
718
|
kind: Kind.LIST_TYPE,
|
|
742
719
|
type,
|
|
@@ -745,7 +722,7 @@ export function parseTypeReference(lexer: Lexer<*>): TypeNode {
|
|
|
745
722
|
} else {
|
|
746
723
|
type = parseNamedType(lexer);
|
|
747
724
|
}
|
|
748
|
-
if (
|
|
725
|
+
if (expectOptionalToken(lexer, TokenKind.BANG)) {
|
|
749
726
|
return ({
|
|
750
727
|
kind: Kind.NON_NULL_TYPE,
|
|
751
728
|
type,
|
|
@@ -853,7 +830,7 @@ function parseOperationTypeDefinition(
|
|
|
853
830
|
): OperationTypeDefinitionNode {
|
|
854
831
|
const start = lexer.token;
|
|
855
832
|
const operation = parseOperationType(lexer);
|
|
856
|
-
|
|
833
|
+
expectToken(lexer, TokenKind.COLON);
|
|
857
834
|
const type = parseNamedType(lexer);
|
|
858
835
|
return {
|
|
859
836
|
kind: Kind.OPERATION_TYPE_DEFINITION,
|
|
@@ -912,14 +889,13 @@ function parseObjectTypeDefinition(lexer: Lexer<*>): ObjectTypeDefinitionNode {
|
|
|
912
889
|
*/
|
|
913
890
|
function parseImplementsInterfaces(lexer: Lexer<*>): Array<NamedTypeNode> {
|
|
914
891
|
const types = [];
|
|
915
|
-
if (lexer
|
|
916
|
-
lexer.advance();
|
|
892
|
+
if (expectOptionalKeyword(lexer, 'implements')) {
|
|
917
893
|
// Optional leading ampersand
|
|
918
|
-
|
|
894
|
+
expectOptionalToken(lexer, TokenKind.AMP);
|
|
919
895
|
do {
|
|
920
896
|
types.push(parseNamedType(lexer));
|
|
921
897
|
} while (
|
|
922
|
-
|
|
898
|
+
expectOptionalToken(lexer, TokenKind.AMP) ||
|
|
923
899
|
// Legacy support for the SDL?
|
|
924
900
|
(lexer.options.allowLegacySDLImplementsInterfaces &&
|
|
925
901
|
peek(lexer, TokenKind.NAME))
|
|
@@ -956,7 +932,7 @@ function parseFieldDefinition(lexer: Lexer<*>): FieldDefinitionNode {
|
|
|
956
932
|
const description = parseDescription(lexer);
|
|
957
933
|
const name = parseName(lexer);
|
|
958
934
|
const args = parseArgumentDefs(lexer);
|
|
959
|
-
|
|
935
|
+
expectToken(lexer, TokenKind.COLON);
|
|
960
936
|
const type = parseTypeReference(lexer);
|
|
961
937
|
const directives = parseDirectives(lexer, true);
|
|
962
938
|
return {
|
|
@@ -988,10 +964,10 @@ function parseInputValueDef(lexer: Lexer<*>): InputValueDefinitionNode {
|
|
|
988
964
|
const start = lexer.token;
|
|
989
965
|
const description = parseDescription(lexer);
|
|
990
966
|
const name = parseName(lexer);
|
|
991
|
-
|
|
967
|
+
expectToken(lexer, TokenKind.COLON);
|
|
992
968
|
const type = parseTypeReference(lexer);
|
|
993
969
|
let defaultValue;
|
|
994
|
-
if (
|
|
970
|
+
if (expectOptionalToken(lexer, TokenKind.EQUALS)) {
|
|
995
971
|
defaultValue = parseConstValue(lexer);
|
|
996
972
|
}
|
|
997
973
|
const directives = parseDirectives(lexer, true);
|
|
@@ -1057,12 +1033,12 @@ function parseUnionTypeDefinition(lexer: Lexer<*>): UnionTypeDefinitionNode {
|
|
|
1057
1033
|
*/
|
|
1058
1034
|
function parseUnionMemberTypes(lexer: Lexer<*>): Array<NamedTypeNode> {
|
|
1059
1035
|
const types = [];
|
|
1060
|
-
if (
|
|
1036
|
+
if (expectOptionalToken(lexer, TokenKind.EQUALS)) {
|
|
1061
1037
|
// Optional leading pipe
|
|
1062
|
-
|
|
1038
|
+
expectOptionalToken(lexer, TokenKind.PIPE);
|
|
1063
1039
|
do {
|
|
1064
1040
|
types.push(parseNamedType(lexer));
|
|
1065
|
-
} while (
|
|
1041
|
+
} while (expectOptionalToken(lexer, TokenKind.PIPE));
|
|
1066
1042
|
}
|
|
1067
1043
|
return types;
|
|
1068
1044
|
}
|
|
@@ -1384,7 +1360,7 @@ function parseDirectiveDefinition(lexer: Lexer<*>): DirectiveDefinitionNode {
|
|
|
1384
1360
|
const start = lexer.token;
|
|
1385
1361
|
const description = parseDescription(lexer);
|
|
1386
1362
|
expectKeyword(lexer, 'directive');
|
|
1387
|
-
|
|
1363
|
+
expectToken(lexer, TokenKind.AT);
|
|
1388
1364
|
const name = parseName(lexer);
|
|
1389
1365
|
const args = parseArgumentDefs(lexer);
|
|
1390
1366
|
expectKeyword(lexer, 'on');
|
|
@@ -1406,11 +1382,11 @@ function parseDirectiveDefinition(lexer: Lexer<*>): DirectiveDefinitionNode {
|
|
|
1406
1382
|
*/
|
|
1407
1383
|
function parseDirectiveLocations(lexer: Lexer<*>): Array<NameNode> {
|
|
1408
1384
|
// Optional leading pipe
|
|
1409
|
-
|
|
1385
|
+
expectOptionalToken(lexer, TokenKind.PIPE);
|
|
1410
1386
|
const locations = [];
|
|
1411
1387
|
do {
|
|
1412
1388
|
locations.push(parseDirectiveLocation(lexer));
|
|
1413
|
-
} while (
|
|
1389
|
+
} while (expectOptionalToken(lexer, TokenKind.PIPE));
|
|
1414
1390
|
return locations;
|
|
1415
1391
|
}
|
|
1416
1392
|
|
|
@@ -1471,9 +1447,9 @@ function Loc(startToken: Token, endToken: Token, source: Source) {
|
|
|
1471
1447
|
}
|
|
1472
1448
|
|
|
1473
1449
|
// Print a simplified form when appearing in JSON/util.inspect.
|
|
1474
|
-
Loc
|
|
1450
|
+
defineToJSON(Loc, function() {
|
|
1475
1451
|
return { start: this.start, end: this.end };
|
|
1476
|
-
};
|
|
1452
|
+
});
|
|
1477
1453
|
|
|
1478
1454
|
/**
|
|
1479
1455
|
* Determines if the next token is of a given kind
|
|
@@ -1482,28 +1458,17 @@ function peek(lexer: Lexer<*>, kind: TokenKindEnum): boolean {
|
|
|
1482
1458
|
return lexer.token.kind === kind;
|
|
1483
1459
|
}
|
|
1484
1460
|
|
|
1485
|
-
/**
|
|
1486
|
-
* If the next token is of the given kind, return true after advancing
|
|
1487
|
-
* the lexer. Otherwise, do not change the parser state and return false.
|
|
1488
|
-
*/
|
|
1489
|
-
function skip(lexer: Lexer<*>, kind: TokenKindEnum): boolean {
|
|
1490
|
-
const match = lexer.token.kind === kind;
|
|
1491
|
-
if (match) {
|
|
1492
|
-
lexer.advance();
|
|
1493
|
-
}
|
|
1494
|
-
return match;
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
1461
|
/**
|
|
1498
1462
|
* If the next token is of the given kind, return that token after advancing
|
|
1499
1463
|
* the lexer. Otherwise, do not change the parser state and throw an error.
|
|
1500
1464
|
*/
|
|
1501
|
-
function
|
|
1465
|
+
function expectToken(lexer: Lexer<*>, kind: TokenKindEnum): Token {
|
|
1502
1466
|
const token = lexer.token;
|
|
1503
1467
|
if (token.kind === kind) {
|
|
1504
1468
|
lexer.advance();
|
|
1505
1469
|
return token;
|
|
1506
1470
|
}
|
|
1471
|
+
|
|
1507
1472
|
throw syntaxError(
|
|
1508
1473
|
lexer.source,
|
|
1509
1474
|
token.start,
|
|
@@ -1512,9 +1477,21 @@ function expect(lexer: Lexer<*>, kind: TokenKindEnum): Token {
|
|
|
1512
1477
|
}
|
|
1513
1478
|
|
|
1514
1479
|
/**
|
|
1515
|
-
* If the next token is
|
|
1516
|
-
*
|
|
1517
|
-
|
|
1480
|
+
* If the next token is of the given kind, return that token after advancing
|
|
1481
|
+
* the lexer. Otherwise, do not change the parser state and return undefined.
|
|
1482
|
+
*/
|
|
1483
|
+
function expectOptionalToken(lexer: Lexer<*>, kind: TokenKindEnum): ?Token {
|
|
1484
|
+
const token = lexer.token;
|
|
1485
|
+
if (token.kind === kind) {
|
|
1486
|
+
lexer.advance();
|
|
1487
|
+
return token;
|
|
1488
|
+
}
|
|
1489
|
+
return undefined;
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
/**
|
|
1493
|
+
* If the next token is a given keyword, return that token after advancing
|
|
1494
|
+
* the lexer. Otherwise, do not change the parser state and throw an error.
|
|
1518
1495
|
*/
|
|
1519
1496
|
function expectKeyword(lexer: Lexer<*>, value: string): Token {
|
|
1520
1497
|
const token = lexer.token;
|
|
@@ -1522,6 +1499,7 @@ function expectKeyword(lexer: Lexer<*>, value: string): Token {
|
|
|
1522
1499
|
lexer.advance();
|
|
1523
1500
|
return token;
|
|
1524
1501
|
}
|
|
1502
|
+
|
|
1525
1503
|
throw syntaxError(
|
|
1526
1504
|
lexer.source,
|
|
1527
1505
|
token.start,
|
|
@@ -1529,6 +1507,19 @@ function expectKeyword(lexer: Lexer<*>, value: string): Token {
|
|
|
1529
1507
|
);
|
|
1530
1508
|
}
|
|
1531
1509
|
|
|
1510
|
+
/**
|
|
1511
|
+
* If the next token is a given keyword, return that token after advancing
|
|
1512
|
+
* the lexer. Otherwise, do not change the parser state and return undefined.
|
|
1513
|
+
*/
|
|
1514
|
+
function expectOptionalKeyword(lexer: Lexer<*>, value: string): ?Token {
|
|
1515
|
+
const token = lexer.token;
|
|
1516
|
+
if (token.kind === TokenKind.NAME && token.value === value) {
|
|
1517
|
+
lexer.advance();
|
|
1518
|
+
return token;
|
|
1519
|
+
}
|
|
1520
|
+
return undefined;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1532
1523
|
/**
|
|
1533
1524
|
* Helper function for creating an error when an unexpected lexed token
|
|
1534
1525
|
* is encountered.
|
|
@@ -1554,9 +1545,9 @@ function any<T>(
|
|
|
1554
1545
|
parseFn: (lexer: Lexer<*>) => T,
|
|
1555
1546
|
closeKind: TokenKindEnum,
|
|
1556
1547
|
): Array<T> {
|
|
1557
|
-
|
|
1548
|
+
expectToken(lexer, openKind);
|
|
1558
1549
|
const nodes = [];
|
|
1559
|
-
while (!
|
|
1550
|
+
while (!expectOptionalToken(lexer, closeKind)) {
|
|
1560
1551
|
nodes.push(parseFn(lexer));
|
|
1561
1552
|
}
|
|
1562
1553
|
return nodes;
|
|
@@ -1574,9 +1565,9 @@ function many<T>(
|
|
|
1574
1565
|
parseFn: (lexer: Lexer<*>) => T,
|
|
1575
1566
|
closeKind: TokenKindEnum,
|
|
1576
1567
|
): Array<T> {
|
|
1577
|
-
|
|
1568
|
+
expectToken(lexer, openKind);
|
|
1578
1569
|
const nodes = [parseFn(lexer)];
|
|
1579
|
-
while (!
|
|
1570
|
+
while (!expectOptionalToken(lexer, closeKind)) {
|
|
1580
1571
|
nodes.push(parseFn(lexer));
|
|
1581
1572
|
}
|
|
1582
1573
|
return nodes;
|