graphql 14.4.2 → 14.5.3
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/README.md +5 -10
- package/error/GraphQLError.d.ts +87 -0
- package/error/GraphQLError.js +7 -45
- package/error/GraphQLError.js.flow +1 -0
- package/error/GraphQLError.mjs +7 -45
- package/error/formatError.d.ts +39 -0
- package/error/formatError.js +5 -2
- package/error/formatError.js.flow +27 -3
- package/error/formatError.mjs +5 -2
- package/error/index.d.ts +4 -0
- package/error/locatedError.d.ts +13 -0
- package/error/locatedError.js.flow +2 -1
- package/error/locatedError.mjs +1 -1
- package/error/syntaxError.d.ts +12 -0
- package/error/syntaxError.js.flow +1 -0
- package/execution/execute.d.ts +190 -0
- package/execution/execute.js +55 -89
- package/execution/execute.js.flow +95 -133
- package/execution/execute.mjs +75 -80
- package/execution/index.d.ts +11 -0
- package/execution/index.js +8 -6
- package/execution/index.js.flow +3 -6
- package/execution/index.mjs +2 -1
- package/execution/values.d.ts +68 -0
- package/execution/values.js +119 -128
- package/execution/values.js.flow +150 -127
- package/execution/values.mjs +117 -125
- package/graphql.d.ts +88 -0
- package/graphql.js +5 -5
- package/graphql.js.flow +9 -5
- package/graphql.mjs +41 -1
- package/index.d.ts +446 -0
- package/index.js +6 -0
- package/index.js.flow +3 -1
- package/index.mjs +2 -1
- package/jsutils/ObjMap.js.flow +6 -0
- package/jsutils/Path.d.ts +14 -0
- package/jsutils/Path.js +33 -0
- package/jsutils/Path.js.flow +26 -0
- package/jsutils/Path.mjs +24 -0
- package/jsutils/PromiseOrValue.d.ts +1 -0
- package/jsutils/dedent.js +6 -24
- package/jsutils/dedent.mjs +6 -24
- package/jsutils/defineToStringTag.js.flow +1 -1
- package/jsutils/devAssert.js +14 -0
- package/jsutils/devAssert.js.flow +8 -0
- package/jsutils/devAssert.mjs +7 -0
- package/jsutils/inspect.js +1 -1
- package/jsutils/inspect.js.flow +1 -1
- package/jsutils/inspect.mjs +1 -1
- package/jsutils/invariant.js +1 -2
- package/jsutils/invariant.js.flow +2 -3
- package/jsutils/invariant.mjs +1 -2
- package/jsutils/mapValue.js +6 -24
- package/jsutils/mapValue.js.flow +2 -1
- package/jsutils/mapValue.mjs +6 -24
- package/jsutils/printPathArray.js +15 -0
- package/jsutils/printPathArray.js.flow +14 -0
- package/jsutils/printPathArray.mjs +8 -0
- package/jsutils/suggestionList.js +14 -34
- package/jsutils/suggestionList.js.flow +4 -6
- package/jsutils/suggestionList.mjs +14 -34
- package/jsutils/toObjMap.js +28 -0
- package/jsutils/toObjMap.js.flow +26 -0
- package/jsutils/toObjMap.mjs +18 -0
- package/language/ast.d.ts +573 -0
- package/language/blockString.d.ts +21 -0
- package/language/directiveLocation.d.ts +35 -0
- package/language/index.d.ts +96 -0
- package/language/kinds.d.ts +77 -0
- package/language/lexer.d.ts +60 -0
- package/language/lexer.js +2 -12
- package/language/lexer.js.flow +6 -12
- package/language/lexer.mjs +1 -9
- package/language/location.d.ts +15 -0
- package/language/parser.d.ts +89 -0
- package/language/parser.js +1329 -1302
- package/language/parser.js.flow +1289 -1298
- package/language/parser.mjs +1326 -1297
- package/language/predicates.d.ts +36 -0
- package/language/predicates.js.flow +1 -1
- package/language/printLocation.d.ts +16 -0
- package/language/printLocation.js.flow +1 -1
- package/language/printer.d.ts +7 -0
- package/language/printer.js.flow +1 -1
- package/language/source.d.ts +19 -0
- package/language/source.js +3 -3
- package/language/source.js.flow +3 -3
- package/language/source.mjs +3 -3
- package/language/tokenKind.d.ts +35 -0
- package/language/visitor.d.ts +264 -0
- package/language/visitor.js +2 -2
- package/language/visitor.js.flow +3 -1
- package/language/visitor.mjs +2 -2
- package/package.json +1 -1
- package/polyfills/find.js +2 -2
- package/polyfills/find.js.flow +1 -2
- package/polyfills/find.mjs +2 -2
- package/polyfills/flatMap.js +3 -3
- package/polyfills/flatMap.js.flow +2 -3
- package/polyfills/flatMap.mjs +3 -3
- package/subscription/asyncIteratorReject.d.ts +6 -0
- package/subscription/index.d.ts +5 -0
- package/subscription/mapAsyncIterator.d.ts +9 -0
- package/subscription/mapAsyncIterator.js.flow +1 -0
- package/subscription/subscribe.d.ts +86 -0
- package/subscription/subscribe.js +29 -10
- package/subscription/subscribe.js.flow +45 -24
- package/subscription/subscribe.mjs +27 -9
- package/tsutils/Maybe.d.ts +4 -0
- package/type/definition.d.ts +805 -0
- package/type/definition.js +154 -70
- package/type/definition.js.flow +217 -160
- package/type/definition.mjs +149 -66
- package/type/directives.d.ts +72 -0
- package/type/directives.js +20 -12
- package/type/directives.js.flow +34 -19
- package/type/directives.mjs +17 -10
- package/type/index.d.ts +155 -0
- package/type/index.js.flow +2 -2
- package/type/introspection.d.ts +40 -0
- package/type/introspection.js +24 -10
- package/type/introspection.js.flow +29 -8
- package/type/introspection.mjs +23 -10
- package/type/scalars.d.ts +11 -0
- package/type/scalars.js +2 -2
- package/type/scalars.js.flow +4 -1
- package/type/scalars.mjs +2 -2
- package/type/schema.d.ts +108 -0
- package/type/schema.js +74 -151
- package/type/schema.js.flow +75 -73
- package/type/schema.mjs +75 -149
- package/type/validate.d.ts +19 -0
- package/type/validate.js +227 -486
- package/type/validate.js.flow +13 -8
- package/type/validate.mjs +218 -477
- package/utilities/TypeInfo.d.ts +49 -0
- package/utilities/TypeInfo.js.flow +9 -6
- package/utilities/assertValidName.d.ts +15 -0
- package/utilities/assertValidName.js +3 -3
- package/utilities/assertValidName.js.flow +3 -2
- package/utilities/assertValidName.mjs +2 -2
- package/utilities/astFromValue.d.ts +25 -0
- package/utilities/astFromValue.js +22 -38
- package/utilities/astFromValue.js.flow +7 -4
- package/utilities/astFromValue.mjs +19 -36
- package/utilities/buildASTSchema.d.ts +114 -0
- package/utilities/buildASTSchema.js +37 -68
- package/utilities/buildASTSchema.js.flow +32 -30
- package/utilities/buildASTSchema.mjs +32 -64
- package/utilities/buildClientSchema.d.ts +21 -0
- package/utilities/buildClientSchema.js +23 -15
- package/utilities/buildClientSchema.js.flow +17 -16
- package/utilities/buildClientSchema.mjs +20 -12
- package/utilities/coerceInputValue.d.ts +17 -0
- package/utilities/coerceInputValue.js +161 -0
- package/utilities/coerceInputValue.js.flow +214 -0
- package/utilities/coerceInputValue.mjs +142 -0
- package/utilities/coerceValue.d.ts +23 -0
- package/utilities/coerceValue.js +21 -199
- package/utilities/coerceValue.js.flow +31 -223
- package/utilities/coerceValue.mjs +20 -195
- package/utilities/concatAST.d.ts +8 -0
- package/utilities/concatAST.js.flow +1 -0
- package/utilities/extendSchema.d.ts +45 -0
- package/utilities/extendSchema.js +64 -131
- package/utilities/extendSchema.js.flow +27 -24
- package/utilities/extendSchema.mjs +61 -129
- package/utilities/findBreakingChanges.d.ts +64 -0
- package/utilities/findBreakingChanges.js +194 -619
- package/utilities/findBreakingChanges.js.flow +8 -5
- package/utilities/findBreakingChanges.mjs +194 -619
- package/utilities/findDeprecatedUsages.d.ts +13 -0
- package/utilities/findDeprecatedUsages.js.flow +4 -1
- package/utilities/getOperationAST.d.ts +12 -0
- package/utilities/getOperationAST.js +13 -31
- package/utilities/getOperationAST.mjs +13 -31
- package/utilities/getOperationRootType.d.ts +14 -0
- package/utilities/getOperationRootType.js.flow +2 -0
- package/utilities/index.d.ts +127 -0
- package/utilities/index.js +8 -0
- package/utilities/index.js.flow +4 -1
- package/utilities/index.mjs +3 -1
- package/utilities/introspectionFromSchema.d.ts +16 -0
- package/utilities/introspectionFromSchema.js +5 -3
- package/utilities/introspectionFromSchema.js.flow +4 -2
- package/utilities/introspectionFromSchema.mjs +4 -2
- package/utilities/introspectionQuery.d.ts +177 -0
- package/utilities/isValidJSValue.d.ts +8 -0
- package/utilities/isValidJSValue.js +1 -1
- package/utilities/isValidJSValue.js.flow +3 -2
- package/utilities/isValidJSValue.mjs +2 -2
- package/utilities/isValidLiteralValue.d.ts +15 -0
- package/utilities/isValidLiteralValue.js +4 -4
- package/utilities/isValidLiteralValue.js.flow +8 -4
- package/utilities/isValidLiteralValue.mjs +2 -2
- package/utilities/lexicographicSortSchema.d.ts +6 -0
- package/utilities/lexicographicSortSchema.js +11 -8
- package/utilities/lexicographicSortSchema.js.flow +5 -3
- package/utilities/lexicographicSortSchema.mjs +9 -7
- package/utilities/schemaPrinter.d.ts +30 -0
- package/utilities/schemaPrinter.js +15 -32
- package/utilities/schemaPrinter.js.flow +14 -10
- package/utilities/schemaPrinter.mjs +14 -32
- package/utilities/separateOperations.d.ts +11 -0
- package/utilities/separateOperations.js +6 -6
- package/utilities/separateOperations.js.flow +2 -1
- package/utilities/separateOperations.mjs +6 -6
- package/utilities/stripIgnoredCharacters.d.ts +55 -0
- package/utilities/stripIgnoredCharacters.js.flow +1 -0
- package/utilities/typeComparators.d.ts +32 -0
- package/utilities/typeComparators.js.flow +1 -1
- package/utilities/typeComparators.mjs +1 -1
- package/utilities/typeFromAST.d.ts +29 -0
- package/utilities/typeFromAST.js +5 -3
- package/utilities/typeFromAST.js.flow +5 -3
- package/utilities/typeFromAST.mjs +14 -3
- package/utilities/valueFromAST.d.ts +29 -0
- package/utilities/valueFromAST.js +40 -74
- package/utilities/valueFromAST.js.flow +7 -4
- package/utilities/valueFromAST.mjs +39 -74
- package/utilities/valueFromASTUntyped.d.ts +23 -0
- package/utilities/valueFromASTUntyped.js +4 -3
- package/utilities/valueFromASTUntyped.js.flow +3 -2
- package/utilities/valueFromASTUntyped.mjs +3 -3
- package/validation/ValidationContext.d.ts +96 -0
- package/validation/ValidationContext.js +38 -86
- package/validation/ValidationContext.js.flow +22 -7
- package/validation/ValidationContext.mjs +37 -85
- package/validation/index.d.ts +126 -0
- package/validation/rules/ExecutableDefinitions.d.ts +14 -0
- package/validation/rules/ExecutableDefinitions.js +4 -23
- package/validation/rules/ExecutableDefinitions.js.flow +4 -2
- package/validation/rules/ExecutableDefinitions.mjs +4 -23
- package/validation/rules/FieldsOnCorrectType.d.ts +17 -0
- package/validation/rules/FieldsOnCorrectType.js +21 -57
- package/validation/rules/FieldsOnCorrectType.js.flow +7 -3
- package/validation/rules/FieldsOnCorrectType.mjs +21 -57
- package/validation/rules/FragmentsOnCompositeTypes.d.ts +20 -0
- package/validation/rules/FragmentsOnCompositeTypes.js.flow +5 -1
- package/validation/rules/KnownArgumentNames.d.ts +28 -0
- package/validation/rules/KnownArgumentNames.js +26 -79
- package/validation/rules/KnownArgumentNames.js.flow +10 -6
- package/validation/rules/KnownArgumentNames.mjs +22 -75
- package/validation/rules/KnownDirectives.d.ts +19 -0
- package/validation/rules/KnownDirectives.js +12 -48
- package/validation/rules/KnownDirectives.js.flow +8 -5
- package/validation/rules/KnownDirectives.mjs +12 -48
- package/validation/rules/KnownFragmentNames.d.ts +12 -0
- package/validation/rules/KnownFragmentNames.js.flow +2 -1
- package/validation/rules/KnownTypeNames.d.ts +15 -0
- package/validation/rules/KnownTypeNames.js +6 -24
- package/validation/rules/KnownTypeNames.js.flow +10 -6
- package/validation/rules/KnownTypeNames.mjs +6 -24
- package/validation/rules/LoneAnonymousOperation.d.ts +14 -0
- package/validation/rules/LoneAnonymousOperation.js.flow +3 -1
- package/validation/rules/LoneSchemaDefinition.d.ts +13 -0
- package/validation/rules/LoneSchemaDefinition.js.flow +2 -1
- package/validation/rules/NoFragmentCycles.d.ts +9 -0
- package/validation/rules/NoFragmentCycles.js +17 -35
- package/validation/rules/NoFragmentCycles.js.flow +4 -2
- package/validation/rules/NoFragmentCycles.mjs +17 -35
- package/validation/rules/NoUndefinedVariables.d.ts +16 -0
- package/validation/rules/NoUndefinedVariables.js +6 -24
- package/validation/rules/NoUndefinedVariables.js.flow +2 -1
- package/validation/rules/NoUndefinedVariables.mjs +6 -24
- package/validation/rules/NoUnusedFragments.d.ts +12 -0
- package/validation/rules/NoUnusedFragments.js +7 -25
- package/validation/rules/NoUnusedFragments.js.flow +2 -1
- package/validation/rules/NoUnusedFragments.mjs +7 -25
- package/validation/rules/NoUnusedVariables.d.ts +16 -0
- package/validation/rules/NoUnusedVariables.js +6 -24
- package/validation/rules/NoUnusedVariables.js.flow +2 -1
- package/validation/rules/NoUnusedVariables.mjs +6 -24
- package/validation/rules/OverlappingFieldsCanBeMerged.d.ts +24 -0
- package/validation/rules/OverlappingFieldsCanBeMerged.js +27 -46
- package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +17 -8
- package/validation/rules/OverlappingFieldsCanBeMerged.mjs +25 -44
- package/validation/rules/PossibleFragmentSpreads.d.ts +22 -0
- package/validation/rules/PossibleFragmentSpreads.js +2 -2
- package/validation/rules/PossibleFragmentSpreads.js.flow +8 -3
- package/validation/rules/PossibleFragmentSpreads.mjs +2 -2
- package/validation/rules/PossibleTypeExtensions.d.ts +21 -0
- package/validation/rules/PossibleTypeExtensions.js +4 -22
- package/validation/rules/PossibleTypeExtensions.js.flow +6 -2
- package/validation/rules/PossibleTypeExtensions.mjs +4 -22
- package/validation/rules/ProvidedRequiredArguments.d.ts +29 -0
- package/validation/rules/ProvidedRequiredArguments.js +27 -79
- package/validation/rules/ProvidedRequiredArguments.js.flow +12 -8
- package/validation/rules/ProvidedRequiredArguments.mjs +25 -77
- package/validation/rules/ScalarLeafs.d.ts +20 -0
- package/validation/rules/ScalarLeafs.js.flow +6 -2
- package/validation/rules/SingleFieldSubscriptions.d.ts +14 -0
- package/validation/rules/SingleFieldSubscriptions.js.flow +4 -2
- package/validation/rules/UniqueArgumentNames.d.ts +12 -0
- package/validation/rules/UniqueArgumentNames.js.flow +2 -1
- package/validation/rules/UniqueDirectiveNames.d.ts +13 -0
- package/validation/rules/UniqueDirectiveNames.js.flow +2 -1
- package/validation/rules/UniqueDirectivesPerLocation.d.ts +14 -0
- package/validation/rules/UniqueDirectivesPerLocation.js +15 -69
- package/validation/rules/UniqueDirectivesPerLocation.js.flow +7 -4
- package/validation/rules/UniqueDirectivesPerLocation.mjs +15 -69
- package/validation/rules/UniqueEnumValueNames.d.ts +19 -0
- package/validation/rules/UniqueEnumValueNames.js +10 -28
- package/validation/rules/UniqueEnumValueNames.js.flow +2 -1
- package/validation/rules/UniqueEnumValueNames.mjs +10 -28
- package/validation/rules/UniqueFieldDefinitionNames.d.ts +21 -0
- package/validation/rules/UniqueFieldDefinitionNames.js +9 -27
- package/validation/rules/UniqueFieldDefinitionNames.js.flow +2 -1
- package/validation/rules/UniqueFieldDefinitionNames.mjs +9 -27
- package/validation/rules/UniqueFragmentNames.d.ts +11 -0
- package/validation/rules/UniqueFragmentNames.js.flow +2 -1
- package/validation/rules/UniqueInputFieldNames.d.ts +14 -0
- package/validation/rules/UniqueInputFieldNames.js.flow +2 -1
- package/validation/rules/UniqueOperationNames.d.ts +11 -0
- package/validation/rules/UniqueOperationNames.js.flow +2 -1
- package/validation/rules/UniqueOperationTypes.d.ts +13 -0
- package/validation/rules/UniqueOperationTypes.js +11 -30
- package/validation/rules/UniqueOperationTypes.js.flow +2 -1
- package/validation/rules/UniqueOperationTypes.mjs +10 -29
- package/validation/rules/UniqueTypeNames.d.ts +13 -0
- package/validation/rules/UniqueTypeNames.js.flow +3 -1
- package/validation/rules/UniqueVariableNames.d.ts +11 -0
- package/validation/rules/UniqueVariableNames.js.flow +4 -2
- package/validation/rules/ValuesOfCorrectType.d.ts +34 -0
- package/validation/rules/ValuesOfCorrectType.js +16 -34
- package/validation/rules/ValuesOfCorrectType.js.flow +11 -6
- package/validation/rules/ValuesOfCorrectType.mjs +12 -30
- package/validation/rules/VariablesAreInputTypes.d.ts +15 -0
- package/validation/rules/VariablesAreInputTypes.js.flow +6 -2
- package/validation/rules/VariablesInAllowedPosition.d.ts +15 -0
- package/validation/rules/VariablesInAllowedPosition.js +22 -40
- package/validation/rules/VariablesInAllowedPosition.js.flow +8 -3
- package/validation/rules/VariablesInAllowedPosition.mjs +18 -36
- package/validation/specifiedRules.d.ts +98 -0
- package/validation/validate.d.ts +56 -0
- package/validation/validate.js +35 -7
- package/validation/validate.js.flow +51 -9
- package/validation/validate.mjs +30 -7
- package/version.d.ts +14 -0
- package/version.js +3 -3
- package/version.js.flow +3 -3
- package/version.mjs +3 -3
package/language/parser.js
CHANGED
|
@@ -6,26 +6,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.parse = parse;
|
|
7
7
|
exports.parseValue = parseValue;
|
|
8
8
|
exports.parseType = parseType;
|
|
9
|
-
exports.parseConstValue = parseConstValue;
|
|
10
|
-
exports.parseTypeReference = parseTypeReference;
|
|
11
|
-
exports.parseNamedType = parseNamedType;
|
|
12
9
|
|
|
13
10
|
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
|
14
11
|
|
|
15
|
-
var
|
|
12
|
+
var _devAssert = _interopRequireDefault(require("../jsutils/devAssert"));
|
|
16
13
|
|
|
17
|
-
var
|
|
14
|
+
var _defineToJSON = _interopRequireDefault(require("../jsutils/defineToJSON"));
|
|
18
15
|
|
|
19
16
|
var _syntaxError = require("../error/syntaxError");
|
|
20
17
|
|
|
21
|
-
var
|
|
18
|
+
var _kinds = require("./kinds");
|
|
22
19
|
|
|
23
|
-
var
|
|
20
|
+
var _source = require("./source");
|
|
24
21
|
|
|
25
|
-
var
|
|
22
|
+
var _lexer = require("./lexer");
|
|
26
23
|
|
|
27
24
|
var _directiveLocation = require("./directiveLocation");
|
|
28
25
|
|
|
26
|
+
var _tokenKind = require("./tokenKind");
|
|
27
|
+
|
|
29
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
29
|
|
|
31
30
|
/**
|
|
@@ -33,14 +32,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
33
32
|
* Throws GraphQLError if a syntax error is encountered.
|
|
34
33
|
*/
|
|
35
34
|
function parse(source, options) {
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
if (!(sourceObj instanceof _source.Source)) {
|
|
39
|
-
throw new TypeError("Must provide Source. Received: ".concat((0, _inspect.default)(sourceObj)));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var lexer = (0, _lexer.createLexer)(sourceObj, options || {});
|
|
43
|
-
return parseDocument(lexer);
|
|
35
|
+
var parser = new Parser(source, options);
|
|
36
|
+
return parser.parseDocument();
|
|
44
37
|
}
|
|
45
38
|
/**
|
|
46
39
|
* Given a string containing a GraphQL value (ex. `[42]`), parse the AST for
|
|
@@ -55,11 +48,10 @@ function parse(source, options) {
|
|
|
55
48
|
|
|
56
49
|
|
|
57
50
|
function parseValue(source, options) {
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
expectToken(lexer, _tokenKind.TokenKind.EOF);
|
|
51
|
+
var parser = new Parser(source, options);
|
|
52
|
+
parser.expectToken(_tokenKind.TokenKind.SOF);
|
|
53
|
+
var value = parser.parseValueLiteral(false);
|
|
54
|
+
parser.expectToken(_tokenKind.TokenKind.EOF);
|
|
63
55
|
return value;
|
|
64
56
|
}
|
|
65
57
|
/**
|
|
@@ -75,1319 +67,1462 @@ function parseValue(source, options) {
|
|
|
75
67
|
|
|
76
68
|
|
|
77
69
|
function parseType(source, options) {
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
expectToken(lexer, _tokenKind.TokenKind.EOF);
|
|
70
|
+
var parser = new Parser(source, options);
|
|
71
|
+
parser.expectToken(_tokenKind.TokenKind.SOF);
|
|
72
|
+
var type = parser.parseTypeReference();
|
|
73
|
+
parser.expectToken(_tokenKind.TokenKind.EOF);
|
|
83
74
|
return type;
|
|
84
75
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Converts a name lex token into a name parse node.
|
|
87
|
-
*/
|
|
88
76
|
|
|
77
|
+
var Parser =
|
|
78
|
+
/*#__PURE__*/
|
|
79
|
+
function () {
|
|
80
|
+
function Parser(source, options) {
|
|
81
|
+
var sourceObj = typeof source === 'string' ? new _source.Source(source) : source;
|
|
82
|
+
sourceObj instanceof _source.Source || (0, _devAssert.default)(0, "Must provide Source. Received: ".concat((0, _inspect.default)(sourceObj)));
|
|
83
|
+
this._lexer = (0, _lexer.createLexer)(sourceObj);
|
|
84
|
+
this._options = options || {};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Converts a name lex token into a name parse node.
|
|
88
|
+
*/
|
|
89
89
|
|
|
90
|
-
function parseName(lexer) {
|
|
91
|
-
var token = expectToken(lexer, _tokenKind.TokenKind.NAME);
|
|
92
|
-
return {
|
|
93
|
-
kind: _kinds.Kind.NAME,
|
|
94
|
-
value: token.value,
|
|
95
|
-
loc: loc(lexer, token)
|
|
96
|
-
};
|
|
97
|
-
} // Implements the parsing rules in the Document section.
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Document : Definition+
|
|
101
|
-
*/
|
|
102
90
|
|
|
91
|
+
var _proto = Parser.prototype;
|
|
103
92
|
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Definition :
|
|
114
|
-
* - ExecutableDefinition
|
|
115
|
-
* - TypeSystemDefinition
|
|
116
|
-
* - TypeSystemExtension
|
|
117
|
-
*/
|
|
93
|
+
_proto.parseName = function parseName() {
|
|
94
|
+
var token = this.expectToken(_tokenKind.TokenKind.NAME);
|
|
95
|
+
return {
|
|
96
|
+
kind: _kinds.Kind.NAME,
|
|
97
|
+
value: token.value,
|
|
98
|
+
loc: this.loc(token)
|
|
99
|
+
};
|
|
100
|
+
} // Implements the parsing rules in the Document section.
|
|
118
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Document : Definition+
|
|
104
|
+
*/
|
|
105
|
+
;
|
|
119
106
|
|
|
120
|
-
function
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return parseExecutableDefinition(lexer);
|
|
128
|
-
|
|
129
|
-
case 'schema':
|
|
130
|
-
case 'scalar':
|
|
131
|
-
case 'type':
|
|
132
|
-
case 'interface':
|
|
133
|
-
case 'union':
|
|
134
|
-
case 'enum':
|
|
135
|
-
case 'input':
|
|
136
|
-
case 'directive':
|
|
137
|
-
return parseTypeSystemDefinition(lexer);
|
|
138
|
-
|
|
139
|
-
case 'extend':
|
|
140
|
-
return parseTypeSystemExtension(lexer);
|
|
141
|
-
}
|
|
142
|
-
} else if (peek(lexer, _tokenKind.TokenKind.BRACE_L)) {
|
|
143
|
-
return parseExecutableDefinition(lexer);
|
|
144
|
-
} else if (peekDescription(lexer)) {
|
|
145
|
-
return parseTypeSystemDefinition(lexer);
|
|
107
|
+
_proto.parseDocument = function parseDocument() {
|
|
108
|
+
var start = this._lexer.token;
|
|
109
|
+
return {
|
|
110
|
+
kind: _kinds.Kind.DOCUMENT,
|
|
111
|
+
definitions: this.many(_tokenKind.TokenKind.SOF, this.parseDefinition, _tokenKind.TokenKind.EOF),
|
|
112
|
+
loc: this.loc(start)
|
|
113
|
+
};
|
|
146
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Definition :
|
|
117
|
+
* - ExecutableDefinition
|
|
118
|
+
* - TypeSystemDefinition
|
|
119
|
+
* - TypeSystemExtension
|
|
120
|
+
*
|
|
121
|
+
* ExecutableDefinition :
|
|
122
|
+
* - OperationDefinition
|
|
123
|
+
* - FragmentDefinition
|
|
124
|
+
*/
|
|
125
|
+
;
|
|
126
|
+
|
|
127
|
+
_proto.parseDefinition = function parseDefinition() {
|
|
128
|
+
if (this.peek(_tokenKind.TokenKind.NAME)) {
|
|
129
|
+
switch (this._lexer.token.value) {
|
|
130
|
+
case 'query':
|
|
131
|
+
case 'mutation':
|
|
132
|
+
case 'subscription':
|
|
133
|
+
return this.parseOperationDefinition();
|
|
134
|
+
|
|
135
|
+
case 'fragment':
|
|
136
|
+
return this.parseFragmentDefinition();
|
|
137
|
+
|
|
138
|
+
case 'schema':
|
|
139
|
+
case 'scalar':
|
|
140
|
+
case 'type':
|
|
141
|
+
case 'interface':
|
|
142
|
+
case 'union':
|
|
143
|
+
case 'enum':
|
|
144
|
+
case 'input':
|
|
145
|
+
case 'directive':
|
|
146
|
+
return this.parseTypeSystemDefinition();
|
|
147
|
+
|
|
148
|
+
case 'extend':
|
|
149
|
+
return this.parseTypeSystemExtension();
|
|
150
|
+
}
|
|
151
|
+
} else if (this.peek(_tokenKind.TokenKind.BRACE_L)) {
|
|
152
|
+
return this.parseOperationDefinition();
|
|
153
|
+
} else if (this.peekDescription()) {
|
|
154
|
+
return this.parseTypeSystemDefinition();
|
|
155
|
+
}
|
|
147
156
|
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* ExecutableDefinition :
|
|
152
|
-
* - OperationDefinition
|
|
153
|
-
* - FragmentDefinition
|
|
154
|
-
*/
|
|
157
|
+
throw this.unexpected();
|
|
158
|
+
} // Implements the parsing rules in the Operations section.
|
|
155
159
|
|
|
160
|
+
/**
|
|
161
|
+
* OperationDefinition :
|
|
162
|
+
* - SelectionSet
|
|
163
|
+
* - OperationType Name? VariableDefinitions? Directives? SelectionSet
|
|
164
|
+
*/
|
|
165
|
+
;
|
|
156
166
|
|
|
157
|
-
function
|
|
158
|
-
|
|
159
|
-
switch (lexer.token.value) {
|
|
160
|
-
case 'query':
|
|
161
|
-
case 'mutation':
|
|
162
|
-
case 'subscription':
|
|
163
|
-
return parseOperationDefinition(lexer);
|
|
167
|
+
_proto.parseOperationDefinition = function parseOperationDefinition() {
|
|
168
|
+
var start = this._lexer.token;
|
|
164
169
|
|
|
165
|
-
|
|
166
|
-
|
|
170
|
+
if (this.peek(_tokenKind.TokenKind.BRACE_L)) {
|
|
171
|
+
return {
|
|
172
|
+
kind: _kinds.Kind.OPERATION_DEFINITION,
|
|
173
|
+
operation: 'query',
|
|
174
|
+
name: undefined,
|
|
175
|
+
variableDefinitions: [],
|
|
176
|
+
directives: [],
|
|
177
|
+
selectionSet: this.parseSelectionSet(),
|
|
178
|
+
loc: this.loc(start)
|
|
179
|
+
};
|
|
167
180
|
}
|
|
168
|
-
} else if (peek(lexer, _tokenKind.TokenKind.BRACE_L)) {
|
|
169
|
-
return parseOperationDefinition(lexer);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
throw unexpected(lexer);
|
|
173
|
-
} // Implements the parsing rules in the Operations section.
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* OperationDefinition :
|
|
177
|
-
* - SelectionSet
|
|
178
|
-
* - OperationType Name? VariableDefinitions? Directives? SelectionSet
|
|
179
|
-
*/
|
|
180
181
|
|
|
182
|
+
var operation = this.parseOperationType();
|
|
183
|
+
var name;
|
|
181
184
|
|
|
182
|
-
|
|
183
|
-
|
|
185
|
+
if (this.peek(_tokenKind.TokenKind.NAME)) {
|
|
186
|
+
name = this.parseName();
|
|
187
|
+
}
|
|
184
188
|
|
|
185
|
-
if (peek(lexer, _tokenKind.TokenKind.BRACE_L)) {
|
|
186
189
|
return {
|
|
187
190
|
kind: _kinds.Kind.OPERATION_DEFINITION,
|
|
188
|
-
operation:
|
|
189
|
-
name:
|
|
190
|
-
variableDefinitions:
|
|
191
|
-
directives:
|
|
192
|
-
selectionSet: parseSelectionSet(
|
|
193
|
-
loc: loc(
|
|
191
|
+
operation: operation,
|
|
192
|
+
name: name,
|
|
193
|
+
variableDefinitions: this.parseVariableDefinitions(),
|
|
194
|
+
directives: this.parseDirectives(false),
|
|
195
|
+
selectionSet: this.parseSelectionSet(),
|
|
196
|
+
loc: this.loc(start)
|
|
194
197
|
};
|
|
195
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* OperationType : one of query mutation subscription
|
|
201
|
+
*/
|
|
202
|
+
;
|
|
196
203
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (peek(lexer, _tokenKind.TokenKind.NAME)) {
|
|
201
|
-
name = parseName(lexer);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return {
|
|
205
|
-
kind: _kinds.Kind.OPERATION_DEFINITION,
|
|
206
|
-
operation: operation,
|
|
207
|
-
name: name,
|
|
208
|
-
variableDefinitions: parseVariableDefinitions(lexer),
|
|
209
|
-
directives: parseDirectives(lexer, false),
|
|
210
|
-
selectionSet: parseSelectionSet(lexer),
|
|
211
|
-
loc: loc(lexer, start)
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* OperationType : one of query mutation subscription
|
|
216
|
-
*/
|
|
217
|
-
|
|
204
|
+
_proto.parseOperationType = function parseOperationType() {
|
|
205
|
+
var operationToken = this.expectToken(_tokenKind.TokenKind.NAME);
|
|
218
206
|
|
|
219
|
-
|
|
220
|
-
|
|
207
|
+
switch (operationToken.value) {
|
|
208
|
+
case 'query':
|
|
209
|
+
return 'query';
|
|
221
210
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return 'query';
|
|
211
|
+
case 'mutation':
|
|
212
|
+
return 'mutation';
|
|
225
213
|
|
|
226
|
-
|
|
227
|
-
|
|
214
|
+
case 'subscription':
|
|
215
|
+
return 'subscription';
|
|
216
|
+
}
|
|
228
217
|
|
|
229
|
-
|
|
230
|
-
return 'subscription';
|
|
218
|
+
throw this.unexpected(operationToken);
|
|
231
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* VariableDefinitions : ( VariableDefinition+ )
|
|
222
|
+
*/
|
|
223
|
+
;
|
|
232
224
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
225
|
+
_proto.parseVariableDefinitions = function parseVariableDefinitions() {
|
|
226
|
+
return this.optionalMany(_tokenKind.TokenKind.PAREN_L, this.parseVariableDefinition, _tokenKind.TokenKind.PAREN_R);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* VariableDefinition : Variable : Type DefaultValue? Directives[Const]?
|
|
230
|
+
*/
|
|
231
|
+
;
|
|
239
232
|
|
|
240
|
-
function
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
233
|
+
_proto.parseVariableDefinition = function parseVariableDefinition() {
|
|
234
|
+
var start = this._lexer.token;
|
|
235
|
+
return {
|
|
236
|
+
kind: _kinds.Kind.VARIABLE_DEFINITION,
|
|
237
|
+
variable: this.parseVariable(),
|
|
238
|
+
type: (this.expectToken(_tokenKind.TokenKind.COLON), this.parseTypeReference()),
|
|
239
|
+
defaultValue: this.expectOptionalToken(_tokenKind.TokenKind.EQUALS) ? this.parseValueLiteral(true) : undefined,
|
|
240
|
+
directives: this.parseDirectives(true),
|
|
241
|
+
loc: this.loc(start)
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Variable : $ Name
|
|
246
|
+
*/
|
|
247
|
+
;
|
|
248
|
+
|
|
249
|
+
_proto.parseVariable = function parseVariable() {
|
|
250
|
+
var start = this._lexer.token;
|
|
251
|
+
this.expectToken(_tokenKind.TokenKind.DOLLAR);
|
|
252
|
+
return {
|
|
253
|
+
kind: _kinds.Kind.VARIABLE,
|
|
254
|
+
name: this.parseName(),
|
|
255
|
+
loc: this.loc(start)
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* SelectionSet : { Selection+ }
|
|
260
|
+
*/
|
|
261
|
+
;
|
|
246
262
|
|
|
263
|
+
_proto.parseSelectionSet = function parseSelectionSet() {
|
|
264
|
+
var start = this._lexer.token;
|
|
265
|
+
return {
|
|
266
|
+
kind: _kinds.Kind.SELECTION_SET,
|
|
267
|
+
selections: this.many(_tokenKind.TokenKind.BRACE_L, this.parseSelection, _tokenKind.TokenKind.BRACE_R),
|
|
268
|
+
loc: this.loc(start)
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Selection :
|
|
273
|
+
* - Field
|
|
274
|
+
* - FragmentSpread
|
|
275
|
+
* - InlineFragment
|
|
276
|
+
*/
|
|
277
|
+
;
|
|
278
|
+
|
|
279
|
+
_proto.parseSelection = function parseSelection() {
|
|
280
|
+
return this.peek(_tokenKind.TokenKind.SPREAD) ? this.parseFragment() : this.parseField();
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Field : Alias? Name Arguments? Directives? SelectionSet?
|
|
284
|
+
*
|
|
285
|
+
* Alias : Name :
|
|
286
|
+
*/
|
|
287
|
+
;
|
|
288
|
+
|
|
289
|
+
_proto.parseField = function parseField() {
|
|
290
|
+
var start = this._lexer.token;
|
|
291
|
+
var nameOrAlias = this.parseName();
|
|
292
|
+
var alias;
|
|
293
|
+
var name;
|
|
294
|
+
|
|
295
|
+
if (this.expectOptionalToken(_tokenKind.TokenKind.COLON)) {
|
|
296
|
+
alias = nameOrAlias;
|
|
297
|
+
name = this.parseName();
|
|
298
|
+
} else {
|
|
299
|
+
name = nameOrAlias;
|
|
300
|
+
}
|
|
247
301
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
302
|
+
return {
|
|
303
|
+
kind: _kinds.Kind.FIELD,
|
|
304
|
+
alias: alias,
|
|
305
|
+
name: name,
|
|
306
|
+
arguments: this.parseArguments(false),
|
|
307
|
+
directives: this.parseDirectives(false),
|
|
308
|
+
selectionSet: this.peek(_tokenKind.TokenKind.BRACE_L) ? this.parseSelectionSet() : undefined,
|
|
309
|
+
loc: this.loc(start)
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Arguments[Const] : ( Argument[?Const]+ )
|
|
314
|
+
*/
|
|
315
|
+
;
|
|
316
|
+
|
|
317
|
+
_proto.parseArguments = function parseArguments(isConst) {
|
|
318
|
+
var item = isConst ? this.parseConstArgument : this.parseArgument;
|
|
319
|
+
return this.optionalMany(_tokenKind.TokenKind.PAREN_L, item, _tokenKind.TokenKind.PAREN_R);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Argument[Const] : Name : Value[?Const]
|
|
323
|
+
*/
|
|
324
|
+
;
|
|
325
|
+
|
|
326
|
+
_proto.parseArgument = function parseArgument() {
|
|
327
|
+
var start = this._lexer.token;
|
|
328
|
+
var name = this.parseName();
|
|
329
|
+
this.expectToken(_tokenKind.TokenKind.COLON);
|
|
330
|
+
return {
|
|
331
|
+
kind: _kinds.Kind.ARGUMENT,
|
|
332
|
+
name: name,
|
|
333
|
+
value: this.parseValueLiteral(false),
|
|
334
|
+
loc: this.loc(start)
|
|
335
|
+
};
|
|
257
336
|
};
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Variable : $ Name
|
|
261
|
-
*/
|
|
262
337
|
|
|
338
|
+
_proto.parseConstArgument = function parseConstArgument() {
|
|
339
|
+
var start = this._lexer.token;
|
|
340
|
+
return {
|
|
341
|
+
kind: _kinds.Kind.ARGUMENT,
|
|
342
|
+
name: this.parseName(),
|
|
343
|
+
value: (this.expectToken(_tokenKind.TokenKind.COLON), this.parseValueLiteral(true)),
|
|
344
|
+
loc: this.loc(start)
|
|
345
|
+
};
|
|
346
|
+
} // Implements the parsing rules in the Fragments section.
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Corresponds to both FragmentSpread and InlineFragment in the spec.
|
|
350
|
+
*
|
|
351
|
+
* FragmentSpread : ... FragmentName Directives?
|
|
352
|
+
*
|
|
353
|
+
* InlineFragment : ... TypeCondition? Directives? SelectionSet
|
|
354
|
+
*/
|
|
355
|
+
;
|
|
356
|
+
|
|
357
|
+
_proto.parseFragment = function parseFragment() {
|
|
358
|
+
var start = this._lexer.token;
|
|
359
|
+
this.expectToken(_tokenKind.TokenKind.SPREAD);
|
|
360
|
+
var hasTypeCondition = this.expectOptionalKeyword('on');
|
|
361
|
+
|
|
362
|
+
if (!hasTypeCondition && this.peek(_tokenKind.TokenKind.NAME)) {
|
|
363
|
+
return {
|
|
364
|
+
kind: _kinds.Kind.FRAGMENT_SPREAD,
|
|
365
|
+
name: this.parseFragmentName(),
|
|
366
|
+
directives: this.parseDirectives(false),
|
|
367
|
+
loc: this.loc(start)
|
|
368
|
+
};
|
|
369
|
+
}
|
|
263
370
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
371
|
+
return {
|
|
372
|
+
kind: _kinds.Kind.INLINE_FRAGMENT,
|
|
373
|
+
typeCondition: hasTypeCondition ? this.parseNamedType() : undefined,
|
|
374
|
+
directives: this.parseDirectives(false),
|
|
375
|
+
selectionSet: this.parseSelectionSet(),
|
|
376
|
+
loc: this.loc(start)
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* FragmentDefinition :
|
|
381
|
+
* - fragment FragmentName on TypeCondition Directives? SelectionSet
|
|
382
|
+
*
|
|
383
|
+
* TypeCondition : NamedType
|
|
384
|
+
*/
|
|
385
|
+
;
|
|
386
|
+
|
|
387
|
+
_proto.parseFragmentDefinition = function parseFragmentDefinition() {
|
|
388
|
+
var start = this._lexer.token;
|
|
389
|
+
this.expectKeyword('fragment'); // Experimental support for defining variables within fragments changes
|
|
390
|
+
// the grammar of FragmentDefinition:
|
|
391
|
+
// - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
|
|
392
|
+
|
|
393
|
+
if (this._options.experimentalFragmentVariables) {
|
|
394
|
+
return {
|
|
395
|
+
kind: _kinds.Kind.FRAGMENT_DEFINITION,
|
|
396
|
+
name: this.parseFragmentName(),
|
|
397
|
+
variableDefinitions: this.parseVariableDefinitions(),
|
|
398
|
+
typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
|
|
399
|
+
directives: this.parseDirectives(false),
|
|
400
|
+
selectionSet: this.parseSelectionSet(),
|
|
401
|
+
loc: this.loc(start)
|
|
402
|
+
};
|
|
403
|
+
}
|
|
276
404
|
|
|
405
|
+
return {
|
|
406
|
+
kind: _kinds.Kind.FRAGMENT_DEFINITION,
|
|
407
|
+
name: this.parseFragmentName(),
|
|
408
|
+
typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
|
|
409
|
+
directives: this.parseDirectives(false),
|
|
410
|
+
selectionSet: this.parseSelectionSet(),
|
|
411
|
+
loc: this.loc(start)
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* FragmentName : Name but not `on`
|
|
416
|
+
*/
|
|
417
|
+
;
|
|
418
|
+
|
|
419
|
+
_proto.parseFragmentName = function parseFragmentName() {
|
|
420
|
+
if (this._lexer.token.value === 'on') {
|
|
421
|
+
throw this.unexpected();
|
|
422
|
+
}
|
|
277
423
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
424
|
+
return this.parseName();
|
|
425
|
+
} // Implements the parsing rules in the Values section.
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Value[Const] :
|
|
429
|
+
* - [~Const] Variable
|
|
430
|
+
* - IntValue
|
|
431
|
+
* - FloatValue
|
|
432
|
+
* - StringValue
|
|
433
|
+
* - BooleanValue
|
|
434
|
+
* - NullValue
|
|
435
|
+
* - EnumValue
|
|
436
|
+
* - ListValue[?Const]
|
|
437
|
+
* - ObjectValue[?Const]
|
|
438
|
+
*
|
|
439
|
+
* BooleanValue : one of `true` `false`
|
|
440
|
+
*
|
|
441
|
+
* NullValue : `null`
|
|
442
|
+
*
|
|
443
|
+
* EnumValue : Name but not `true`, `false` or `null`
|
|
444
|
+
*/
|
|
445
|
+
;
|
|
446
|
+
|
|
447
|
+
_proto.parseValueLiteral = function parseValueLiteral(isConst) {
|
|
448
|
+
var token = this._lexer.token;
|
|
449
|
+
|
|
450
|
+
switch (token.kind) {
|
|
451
|
+
case _tokenKind.TokenKind.BRACKET_L:
|
|
452
|
+
return this.parseList(isConst);
|
|
453
|
+
|
|
454
|
+
case _tokenKind.TokenKind.BRACE_L:
|
|
455
|
+
return this.parseObject(isConst);
|
|
456
|
+
|
|
457
|
+
case _tokenKind.TokenKind.INT:
|
|
458
|
+
this._lexer.advance();
|
|
292
459
|
|
|
460
|
+
return {
|
|
461
|
+
kind: _kinds.Kind.INT,
|
|
462
|
+
value: token.value,
|
|
463
|
+
loc: this.loc(token)
|
|
464
|
+
};
|
|
293
465
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Field : Alias? Name Arguments? Directives? SelectionSet?
|
|
299
|
-
*
|
|
300
|
-
* Alias : Name :
|
|
301
|
-
*/
|
|
466
|
+
case _tokenKind.TokenKind.FLOAT:
|
|
467
|
+
this._lexer.advance();
|
|
302
468
|
|
|
469
|
+
return {
|
|
470
|
+
kind: _kinds.Kind.FLOAT,
|
|
471
|
+
value: token.value,
|
|
472
|
+
loc: this.loc(token)
|
|
473
|
+
};
|
|
303
474
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
var alias;
|
|
308
|
-
var name;
|
|
475
|
+
case _tokenKind.TokenKind.STRING:
|
|
476
|
+
case _tokenKind.TokenKind.BLOCK_STRING:
|
|
477
|
+
return this.parseStringLiteral();
|
|
309
478
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
} else {
|
|
314
|
-
name = nameOrAlias;
|
|
315
|
-
}
|
|
479
|
+
case _tokenKind.TokenKind.NAME:
|
|
480
|
+
if (token.value === 'true' || token.value === 'false') {
|
|
481
|
+
this._lexer.advance();
|
|
316
482
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
loc: loc(lexer, start)
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Arguments[Const] : ( Argument[?Const]+ )
|
|
329
|
-
*/
|
|
483
|
+
return {
|
|
484
|
+
kind: _kinds.Kind.BOOLEAN,
|
|
485
|
+
value: token.value === 'true',
|
|
486
|
+
loc: this.loc(token)
|
|
487
|
+
};
|
|
488
|
+
} else if (token.value === 'null') {
|
|
489
|
+
this._lexer.advance();
|
|
330
490
|
|
|
491
|
+
return {
|
|
492
|
+
kind: _kinds.Kind.NULL,
|
|
493
|
+
loc: this.loc(token)
|
|
494
|
+
};
|
|
495
|
+
}
|
|
331
496
|
|
|
332
|
-
|
|
333
|
-
var item = isConst ? parseConstArgument : parseArgument;
|
|
334
|
-
return peek(lexer, _tokenKind.TokenKind.PAREN_L) ? many(lexer, _tokenKind.TokenKind.PAREN_L, item, _tokenKind.TokenKind.PAREN_R) : [];
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Argument[Const] : Name : Value[?Const]
|
|
338
|
-
*/
|
|
497
|
+
this._lexer.advance();
|
|
339
498
|
|
|
499
|
+
return {
|
|
500
|
+
kind: _kinds.Kind.ENUM,
|
|
501
|
+
value: token.value,
|
|
502
|
+
loc: this.loc(token)
|
|
503
|
+
};
|
|
340
504
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
return {
|
|
346
|
-
kind: _kinds.Kind.ARGUMENT,
|
|
347
|
-
name: name,
|
|
348
|
-
value: parseValueLiteral(lexer, false),
|
|
349
|
-
loc: loc(lexer, start)
|
|
350
|
-
};
|
|
351
|
-
}
|
|
505
|
+
case _tokenKind.TokenKind.DOLLAR:
|
|
506
|
+
if (!isConst) {
|
|
507
|
+
return this.parseVariable();
|
|
508
|
+
}
|
|
352
509
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
return {
|
|
356
|
-
kind: _kinds.Kind.ARGUMENT,
|
|
357
|
-
name: parseName(lexer),
|
|
358
|
-
value: (expectToken(lexer, _tokenKind.TokenKind.COLON), parseConstValue(lexer)),
|
|
359
|
-
loc: loc(lexer, start)
|
|
360
|
-
};
|
|
361
|
-
} // Implements the parsing rules in the Fragments section.
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
362
512
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
*
|
|
366
|
-
* FragmentSpread : ... FragmentName Directives?
|
|
367
|
-
*
|
|
368
|
-
* InlineFragment : ... TypeCondition? Directives? SelectionSet
|
|
369
|
-
*/
|
|
513
|
+
throw this.unexpected();
|
|
514
|
+
};
|
|
370
515
|
|
|
516
|
+
_proto.parseStringLiteral = function parseStringLiteral() {
|
|
517
|
+
var token = this._lexer.token;
|
|
371
518
|
|
|
372
|
-
|
|
373
|
-
var start = lexer.token;
|
|
374
|
-
expectToken(lexer, _tokenKind.TokenKind.SPREAD);
|
|
375
|
-
var hasTypeCondition = expectOptionalKeyword(lexer, 'on');
|
|
519
|
+
this._lexer.advance();
|
|
376
520
|
|
|
377
|
-
if (!hasTypeCondition && peek(lexer, _tokenKind.TokenKind.NAME)) {
|
|
378
521
|
return {
|
|
379
|
-
kind: _kinds.Kind.
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
loc: loc(
|
|
522
|
+
kind: _kinds.Kind.STRING,
|
|
523
|
+
value: token.value,
|
|
524
|
+
block: token.kind === _tokenKind.TokenKind.BLOCK_STRING,
|
|
525
|
+
loc: this.loc(token)
|
|
383
526
|
};
|
|
384
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* ListValue[Const] :
|
|
530
|
+
* - [ ]
|
|
531
|
+
* - [ Value[?Const]+ ]
|
|
532
|
+
*/
|
|
533
|
+
;
|
|
385
534
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
typeCondition: hasTypeCondition ? parseNamedType(lexer) : undefined,
|
|
389
|
-
directives: parseDirectives(lexer, false),
|
|
390
|
-
selectionSet: parseSelectionSet(lexer),
|
|
391
|
-
loc: loc(lexer, start)
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* FragmentDefinition :
|
|
396
|
-
* - fragment FragmentName on TypeCondition Directives? SelectionSet
|
|
397
|
-
*
|
|
398
|
-
* TypeCondition : NamedType
|
|
399
|
-
*/
|
|
535
|
+
_proto.parseList = function parseList(isConst) {
|
|
536
|
+
var _this = this;
|
|
400
537
|
|
|
538
|
+
var start = this._lexer.token;
|
|
401
539
|
|
|
402
|
-
function
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
// the grammar of FragmentDefinition:
|
|
406
|
-
// - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
|
|
540
|
+
var item = function item() {
|
|
541
|
+
return _this.parseValueLiteral(isConst);
|
|
542
|
+
};
|
|
407
543
|
|
|
408
|
-
if (lexer.options.experimentalFragmentVariables) {
|
|
409
544
|
return {
|
|
410
|
-
kind: _kinds.Kind.
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
typeCondition: (expectKeyword(lexer, 'on'), parseNamedType(lexer)),
|
|
414
|
-
directives: parseDirectives(lexer, false),
|
|
415
|
-
selectionSet: parseSelectionSet(lexer),
|
|
416
|
-
loc: loc(lexer, start)
|
|
545
|
+
kind: _kinds.Kind.LIST,
|
|
546
|
+
values: this.any(_tokenKind.TokenKind.BRACKET_L, item, _tokenKind.TokenKind.BRACKET_R),
|
|
547
|
+
loc: this.loc(start)
|
|
417
548
|
};
|
|
418
549
|
}
|
|
550
|
+
/**
|
|
551
|
+
* ObjectValue[Const] :
|
|
552
|
+
* - { }
|
|
553
|
+
* - { ObjectField[?Const]+ }
|
|
554
|
+
*/
|
|
555
|
+
;
|
|
419
556
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
name: parseFragmentName(lexer),
|
|
423
|
-
typeCondition: (expectKeyword(lexer, 'on'), parseNamedType(lexer)),
|
|
424
|
-
directives: parseDirectives(lexer, false),
|
|
425
|
-
selectionSet: parseSelectionSet(lexer),
|
|
426
|
-
loc: loc(lexer, start)
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* FragmentName : Name but not `on`
|
|
431
|
-
*/
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
function parseFragmentName(lexer) {
|
|
435
|
-
if (lexer.token.value === 'on') {
|
|
436
|
-
throw unexpected(lexer);
|
|
437
|
-
}
|
|
557
|
+
_proto.parseObject = function parseObject(isConst) {
|
|
558
|
+
var _this2 = this;
|
|
438
559
|
|
|
439
|
-
|
|
440
|
-
} // Implements the parsing rules in the Values section.
|
|
560
|
+
var start = this._lexer.token;
|
|
441
561
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
* - IntValue
|
|
446
|
-
* - FloatValue
|
|
447
|
-
* - StringValue
|
|
448
|
-
* - BooleanValue
|
|
449
|
-
* - NullValue
|
|
450
|
-
* - EnumValue
|
|
451
|
-
* - ListValue[?Const]
|
|
452
|
-
* - ObjectValue[?Const]
|
|
453
|
-
*
|
|
454
|
-
* BooleanValue : one of `true` `false`
|
|
455
|
-
*
|
|
456
|
-
* NullValue : `null`
|
|
457
|
-
*
|
|
458
|
-
* EnumValue : Name but not `true`, `false` or `null`
|
|
459
|
-
*/
|
|
562
|
+
var item = function item() {
|
|
563
|
+
return _this2.parseObjectField(isConst);
|
|
564
|
+
};
|
|
460
565
|
|
|
566
|
+
return {
|
|
567
|
+
kind: _kinds.Kind.OBJECT,
|
|
568
|
+
fields: this.any(_tokenKind.TokenKind.BRACE_L, item, _tokenKind.TokenKind.BRACE_R),
|
|
569
|
+
loc: this.loc(start)
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* ObjectField[Const] : Name : Value[?Const]
|
|
574
|
+
*/
|
|
575
|
+
;
|
|
576
|
+
|
|
577
|
+
_proto.parseObjectField = function parseObjectField(isConst) {
|
|
578
|
+
var start = this._lexer.token;
|
|
579
|
+
var name = this.parseName();
|
|
580
|
+
this.expectToken(_tokenKind.TokenKind.COLON);
|
|
581
|
+
return {
|
|
582
|
+
kind: _kinds.Kind.OBJECT_FIELD,
|
|
583
|
+
name: name,
|
|
584
|
+
value: this.parseValueLiteral(isConst),
|
|
585
|
+
loc: this.loc(start)
|
|
586
|
+
};
|
|
587
|
+
} // Implements the parsing rules in the Directives section.
|
|
461
588
|
|
|
462
|
-
|
|
463
|
-
|
|
589
|
+
/**
|
|
590
|
+
* Directives[Const] : Directive[?Const]+
|
|
591
|
+
*/
|
|
592
|
+
;
|
|
464
593
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
return parseList(lexer, isConst);
|
|
594
|
+
_proto.parseDirectives = function parseDirectives(isConst) {
|
|
595
|
+
var directives = [];
|
|
468
596
|
|
|
469
|
-
|
|
470
|
-
|
|
597
|
+
while (this.peek(_tokenKind.TokenKind.AT)) {
|
|
598
|
+
directives.push(this.parseDirective(isConst));
|
|
599
|
+
}
|
|
471
600
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
601
|
+
return directives;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Directive[Const] : @ Name Arguments[?Const]?
|
|
605
|
+
*/
|
|
606
|
+
;
|
|
607
|
+
|
|
608
|
+
_proto.parseDirective = function parseDirective(isConst) {
|
|
609
|
+
var start = this._lexer.token;
|
|
610
|
+
this.expectToken(_tokenKind.TokenKind.AT);
|
|
611
|
+
return {
|
|
612
|
+
kind: _kinds.Kind.DIRECTIVE,
|
|
613
|
+
name: this.parseName(),
|
|
614
|
+
arguments: this.parseArguments(isConst),
|
|
615
|
+
loc: this.loc(start)
|
|
616
|
+
};
|
|
617
|
+
} // Implements the parsing rules in the Types section.
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Type :
|
|
621
|
+
* - NamedType
|
|
622
|
+
* - ListType
|
|
623
|
+
* - NonNullType
|
|
624
|
+
*/
|
|
625
|
+
;
|
|
626
|
+
|
|
627
|
+
_proto.parseTypeReference = function parseTypeReference() {
|
|
628
|
+
var start = this._lexer.token;
|
|
629
|
+
var type;
|
|
630
|
+
|
|
631
|
+
if (this.expectOptionalToken(_tokenKind.TokenKind.BRACKET_L)) {
|
|
632
|
+
type = this.parseTypeReference();
|
|
633
|
+
this.expectToken(_tokenKind.TokenKind.BRACKET_R);
|
|
634
|
+
type = {
|
|
635
|
+
kind: _kinds.Kind.LIST_TYPE,
|
|
636
|
+
type: type,
|
|
637
|
+
loc: this.loc(start)
|
|
478
638
|
};
|
|
639
|
+
} else {
|
|
640
|
+
type = this.parseNamedType();
|
|
641
|
+
}
|
|
479
642
|
|
|
480
|
-
|
|
481
|
-
lexer.advance();
|
|
643
|
+
if (this.expectOptionalToken(_tokenKind.TokenKind.BANG)) {
|
|
482
644
|
return {
|
|
483
|
-
kind: _kinds.Kind.
|
|
484
|
-
|
|
485
|
-
loc: loc(
|
|
645
|
+
kind: _kinds.Kind.NON_NULL_TYPE,
|
|
646
|
+
type: type,
|
|
647
|
+
loc: this.loc(start)
|
|
486
648
|
};
|
|
649
|
+
}
|
|
487
650
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
651
|
+
return type;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* NamedType : Name
|
|
655
|
+
*/
|
|
656
|
+
;
|
|
491
657
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
658
|
+
_proto.parseNamedType = function parseNamedType() {
|
|
659
|
+
var start = this._lexer.token;
|
|
660
|
+
return {
|
|
661
|
+
kind: _kinds.Kind.NAMED_TYPE,
|
|
662
|
+
name: this.parseName(),
|
|
663
|
+
loc: this.loc(start)
|
|
664
|
+
};
|
|
665
|
+
} // Implements the parsing rules in the Type Definition section.
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* TypeSystemDefinition :
|
|
669
|
+
* - SchemaDefinition
|
|
670
|
+
* - TypeDefinition
|
|
671
|
+
* - DirectiveDefinition
|
|
672
|
+
*
|
|
673
|
+
* TypeDefinition :
|
|
674
|
+
* - ScalarTypeDefinition
|
|
675
|
+
* - ObjectTypeDefinition
|
|
676
|
+
* - InterfaceTypeDefinition
|
|
677
|
+
* - UnionTypeDefinition
|
|
678
|
+
* - EnumTypeDefinition
|
|
679
|
+
* - InputObjectTypeDefinition
|
|
680
|
+
*/
|
|
681
|
+
;
|
|
682
|
+
|
|
683
|
+
_proto.parseTypeSystemDefinition = function parseTypeSystemDefinition() {
|
|
684
|
+
// Many definitions begin with a description and require a lookahead.
|
|
685
|
+
var keywordToken = this.peekDescription() ? this._lexer.lookahead() : this._lexer.token;
|
|
686
|
+
|
|
687
|
+
if (keywordToken.kind === _tokenKind.TokenKind.NAME) {
|
|
688
|
+
switch (keywordToken.value) {
|
|
689
|
+
case 'schema':
|
|
690
|
+
return this.parseSchemaDefinition();
|
|
691
|
+
|
|
692
|
+
case 'scalar':
|
|
693
|
+
return this.parseScalarTypeDefinition();
|
|
694
|
+
|
|
695
|
+
case 'type':
|
|
696
|
+
return this.parseObjectTypeDefinition();
|
|
697
|
+
|
|
698
|
+
case 'interface':
|
|
699
|
+
return this.parseInterfaceTypeDefinition();
|
|
700
|
+
|
|
701
|
+
case 'union':
|
|
702
|
+
return this.parseUnionTypeDefinition();
|
|
703
|
+
|
|
704
|
+
case 'enum':
|
|
705
|
+
return this.parseEnumTypeDefinition();
|
|
706
|
+
|
|
707
|
+
case 'input':
|
|
708
|
+
return this.parseInputObjectTypeDefinition();
|
|
709
|
+
|
|
710
|
+
case 'directive':
|
|
711
|
+
return this.parseDirectiveDefinition();
|
|
506
712
|
}
|
|
713
|
+
}
|
|
507
714
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
kind: _kinds.Kind.ENUM,
|
|
511
|
-
value: token.value,
|
|
512
|
-
loc: loc(lexer, token)
|
|
513
|
-
};
|
|
715
|
+
throw this.unexpected(keywordToken);
|
|
716
|
+
};
|
|
514
717
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
718
|
+
_proto.peekDescription = function peekDescription() {
|
|
719
|
+
return this.peek(_tokenKind.TokenKind.STRING) || this.peek(_tokenKind.TokenKind.BLOCK_STRING);
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Description : StringValue
|
|
723
|
+
*/
|
|
724
|
+
;
|
|
725
|
+
|
|
726
|
+
_proto.parseDescription = function parseDescription() {
|
|
727
|
+
if (this.peekDescription()) {
|
|
728
|
+
return this.parseStringLiteral();
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* SchemaDefinition : schema Directives[Const]? { OperationTypeDefinition+ }
|
|
733
|
+
*/
|
|
734
|
+
;
|
|
735
|
+
|
|
736
|
+
_proto.parseSchemaDefinition = function parseSchemaDefinition() {
|
|
737
|
+
var start = this._lexer.token;
|
|
738
|
+
this.expectKeyword('schema');
|
|
739
|
+
var directives = this.parseDirectives(true);
|
|
740
|
+
var operationTypes = this.many(_tokenKind.TokenKind.BRACE_L, this.parseOperationTypeDefinition, _tokenKind.TokenKind.BRACE_R);
|
|
741
|
+
return {
|
|
742
|
+
kind: _kinds.Kind.SCHEMA_DEFINITION,
|
|
743
|
+
directives: directives,
|
|
744
|
+
operationTypes: operationTypes,
|
|
745
|
+
loc: this.loc(start)
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* OperationTypeDefinition : OperationType : NamedType
|
|
750
|
+
*/
|
|
751
|
+
;
|
|
752
|
+
|
|
753
|
+
_proto.parseOperationTypeDefinition = function parseOperationTypeDefinition() {
|
|
754
|
+
var start = this._lexer.token;
|
|
755
|
+
var operation = this.parseOperationType();
|
|
756
|
+
this.expectToken(_tokenKind.TokenKind.COLON);
|
|
757
|
+
var type = this.parseNamedType();
|
|
758
|
+
return {
|
|
759
|
+
kind: _kinds.Kind.OPERATION_TYPE_DEFINITION,
|
|
760
|
+
operation: operation,
|
|
761
|
+
type: type,
|
|
762
|
+
loc: this.loc(start)
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* ScalarTypeDefinition : Description? scalar Name Directives[Const]?
|
|
767
|
+
*/
|
|
768
|
+
;
|
|
769
|
+
|
|
770
|
+
_proto.parseScalarTypeDefinition = function parseScalarTypeDefinition() {
|
|
771
|
+
var start = this._lexer.token;
|
|
772
|
+
var description = this.parseDescription();
|
|
773
|
+
this.expectKeyword('scalar');
|
|
774
|
+
var name = this.parseName();
|
|
775
|
+
var directives = this.parseDirectives(true);
|
|
776
|
+
return {
|
|
777
|
+
kind: _kinds.Kind.SCALAR_TYPE_DEFINITION,
|
|
778
|
+
description: description,
|
|
779
|
+
name: name,
|
|
780
|
+
directives: directives,
|
|
781
|
+
loc: this.loc(start)
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* ObjectTypeDefinition :
|
|
786
|
+
* Description?
|
|
787
|
+
* type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition?
|
|
788
|
+
*/
|
|
789
|
+
;
|
|
790
|
+
|
|
791
|
+
_proto.parseObjectTypeDefinition = function parseObjectTypeDefinition() {
|
|
792
|
+
var start = this._lexer.token;
|
|
793
|
+
var description = this.parseDescription();
|
|
794
|
+
this.expectKeyword('type');
|
|
795
|
+
var name = this.parseName();
|
|
796
|
+
var interfaces = this.parseImplementsInterfaces();
|
|
797
|
+
var directives = this.parseDirectives(true);
|
|
798
|
+
var fields = this.parseFieldsDefinition();
|
|
799
|
+
return {
|
|
800
|
+
kind: _kinds.Kind.OBJECT_TYPE_DEFINITION,
|
|
801
|
+
description: description,
|
|
802
|
+
name: name,
|
|
803
|
+
interfaces: interfaces,
|
|
804
|
+
directives: directives,
|
|
805
|
+
fields: fields,
|
|
806
|
+
loc: this.loc(start)
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* ImplementsInterfaces :
|
|
811
|
+
* - implements `&`? NamedType
|
|
812
|
+
* - ImplementsInterfaces & NamedType
|
|
813
|
+
*/
|
|
814
|
+
;
|
|
815
|
+
|
|
816
|
+
_proto.parseImplementsInterfaces = function parseImplementsInterfaces() {
|
|
817
|
+
var types = [];
|
|
818
|
+
|
|
819
|
+
if (this.expectOptionalKeyword('implements')) {
|
|
820
|
+
// Optional leading ampersand
|
|
821
|
+
this.expectOptionalToken(_tokenKind.TokenKind.AMP);
|
|
822
|
+
|
|
823
|
+
do {
|
|
824
|
+
types.push(this.parseNamedType());
|
|
825
|
+
} while (this.expectOptionalToken(_tokenKind.TokenKind.AMP) || // Legacy support for the SDL?
|
|
826
|
+
this._options.allowLegacySDLImplementsInterfaces && this.peek(_tokenKind.TokenKind.NAME));
|
|
827
|
+
}
|
|
519
828
|
|
|
520
|
-
|
|
829
|
+
return types;
|
|
521
830
|
}
|
|
831
|
+
/**
|
|
832
|
+
* FieldsDefinition : { FieldDefinition+ }
|
|
833
|
+
*/
|
|
834
|
+
;
|
|
522
835
|
|
|
523
|
-
|
|
524
|
-
|
|
836
|
+
_proto.parseFieldsDefinition = function parseFieldsDefinition() {
|
|
837
|
+
// Legacy support for the SDL?
|
|
838
|
+
if (this._options.allowLegacySDLEmptyFields && this.peek(_tokenKind.TokenKind.BRACE_L) && this._lexer.lookahead().kind === _tokenKind.TokenKind.BRACE_R) {
|
|
839
|
+
this._lexer.advance();
|
|
525
840
|
|
|
526
|
-
|
|
527
|
-
var token = lexer.token;
|
|
528
|
-
lexer.advance();
|
|
529
|
-
return {
|
|
530
|
-
kind: _kinds.Kind.STRING,
|
|
531
|
-
value: token.value,
|
|
532
|
-
block: token.kind === _tokenKind.TokenKind.BLOCK_STRING,
|
|
533
|
-
loc: loc(lexer, token)
|
|
534
|
-
};
|
|
535
|
-
}
|
|
841
|
+
this._lexer.advance();
|
|
536
842
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
}
|
|
843
|
+
return [];
|
|
844
|
+
}
|
|
540
845
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
846
|
+
return this.optionalMany(_tokenKind.TokenKind.BRACE_L, this.parseFieldDefinition, _tokenKind.TokenKind.BRACE_R);
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* FieldDefinition :
|
|
850
|
+
* - Description? Name ArgumentsDefinition? : Type Directives[Const]?
|
|
851
|
+
*/
|
|
852
|
+
;
|
|
853
|
+
|
|
854
|
+
_proto.parseFieldDefinition = function parseFieldDefinition() {
|
|
855
|
+
var start = this._lexer.token;
|
|
856
|
+
var description = this.parseDescription();
|
|
857
|
+
var name = this.parseName();
|
|
858
|
+
var args = this.parseArgumentDefs();
|
|
859
|
+
this.expectToken(_tokenKind.TokenKind.COLON);
|
|
860
|
+
var type = this.parseTypeReference();
|
|
861
|
+
var directives = this.parseDirectives(true);
|
|
862
|
+
return {
|
|
863
|
+
kind: _kinds.Kind.FIELD_DEFINITION,
|
|
864
|
+
description: description,
|
|
865
|
+
name: name,
|
|
866
|
+
arguments: args,
|
|
867
|
+
type: type,
|
|
868
|
+
directives: directives,
|
|
869
|
+
loc: this.loc(start)
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* ArgumentsDefinition : ( InputValueDefinition+ )
|
|
874
|
+
*/
|
|
875
|
+
;
|
|
549
876
|
|
|
877
|
+
_proto.parseArgumentDefs = function parseArgumentDefs() {
|
|
878
|
+
return this.optionalMany(_tokenKind.TokenKind.PAREN_L, this.parseInputValueDef, _tokenKind.TokenKind.PAREN_R);
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* InputValueDefinition :
|
|
882
|
+
* - Description? Name : Type DefaultValue? Directives[Const]?
|
|
883
|
+
*/
|
|
884
|
+
;
|
|
885
|
+
|
|
886
|
+
_proto.parseInputValueDef = function parseInputValueDef() {
|
|
887
|
+
var start = this._lexer.token;
|
|
888
|
+
var description = this.parseDescription();
|
|
889
|
+
var name = this.parseName();
|
|
890
|
+
this.expectToken(_tokenKind.TokenKind.COLON);
|
|
891
|
+
var type = this.parseTypeReference();
|
|
892
|
+
var defaultValue;
|
|
893
|
+
|
|
894
|
+
if (this.expectOptionalToken(_tokenKind.TokenKind.EQUALS)) {
|
|
895
|
+
defaultValue = this.parseValueLiteral(true);
|
|
896
|
+
}
|
|
550
897
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
898
|
+
var directives = this.parseDirectives(true);
|
|
899
|
+
return {
|
|
900
|
+
kind: _kinds.Kind.INPUT_VALUE_DEFINITION,
|
|
901
|
+
description: description,
|
|
902
|
+
name: name,
|
|
903
|
+
type: type,
|
|
904
|
+
defaultValue: defaultValue,
|
|
905
|
+
directives: directives,
|
|
906
|
+
loc: this.loc(start)
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* InterfaceTypeDefinition :
|
|
911
|
+
* - Description? interface Name Directives[Const]? FieldsDefinition?
|
|
912
|
+
*/
|
|
913
|
+
;
|
|
914
|
+
|
|
915
|
+
_proto.parseInterfaceTypeDefinition = function parseInterfaceTypeDefinition() {
|
|
916
|
+
var start = this._lexer.token;
|
|
917
|
+
var description = this.parseDescription();
|
|
918
|
+
this.expectKeyword('interface');
|
|
919
|
+
var name = this.parseName();
|
|
920
|
+
var directives = this.parseDirectives(true);
|
|
921
|
+
var fields = this.parseFieldsDefinition();
|
|
922
|
+
return {
|
|
923
|
+
kind: _kinds.Kind.INTERFACE_TYPE_DEFINITION,
|
|
924
|
+
description: description,
|
|
925
|
+
name: name,
|
|
926
|
+
directives: directives,
|
|
927
|
+
fields: fields,
|
|
928
|
+
loc: this.loc(start)
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* UnionTypeDefinition :
|
|
933
|
+
* - Description? union Name Directives[Const]? UnionMemberTypes?
|
|
934
|
+
*/
|
|
935
|
+
;
|
|
936
|
+
|
|
937
|
+
_proto.parseUnionTypeDefinition = function parseUnionTypeDefinition() {
|
|
938
|
+
var start = this._lexer.token;
|
|
939
|
+
var description = this.parseDescription();
|
|
940
|
+
this.expectKeyword('union');
|
|
941
|
+
var name = this.parseName();
|
|
942
|
+
var directives = this.parseDirectives(true);
|
|
943
|
+
var types = this.parseUnionMemberTypes();
|
|
944
|
+
return {
|
|
945
|
+
kind: _kinds.Kind.UNION_TYPE_DEFINITION,
|
|
946
|
+
description: description,
|
|
947
|
+
name: name,
|
|
948
|
+
directives: directives,
|
|
949
|
+
types: types,
|
|
950
|
+
loc: this.loc(start)
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* UnionMemberTypes :
|
|
955
|
+
* - = `|`? NamedType
|
|
956
|
+
* - UnionMemberTypes | NamedType
|
|
957
|
+
*/
|
|
958
|
+
;
|
|
959
|
+
|
|
960
|
+
_proto.parseUnionMemberTypes = function parseUnionMemberTypes() {
|
|
961
|
+
var types = [];
|
|
962
|
+
|
|
963
|
+
if (this.expectOptionalToken(_tokenKind.TokenKind.EQUALS)) {
|
|
964
|
+
// Optional leading pipe
|
|
965
|
+
this.expectOptionalToken(_tokenKind.TokenKind.PIPE);
|
|
966
|
+
|
|
967
|
+
do {
|
|
968
|
+
types.push(this.parseNamedType());
|
|
969
|
+
} while (this.expectOptionalToken(_tokenKind.TokenKind.PIPE));
|
|
970
|
+
}
|
|
565
971
|
|
|
972
|
+
return types;
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* EnumTypeDefinition :
|
|
976
|
+
* - Description? enum Name Directives[Const]? EnumValuesDefinition?
|
|
977
|
+
*/
|
|
978
|
+
;
|
|
979
|
+
|
|
980
|
+
_proto.parseEnumTypeDefinition = function parseEnumTypeDefinition() {
|
|
981
|
+
var start = this._lexer.token;
|
|
982
|
+
var description = this.parseDescription();
|
|
983
|
+
this.expectKeyword('enum');
|
|
984
|
+
var name = this.parseName();
|
|
985
|
+
var directives = this.parseDirectives(true);
|
|
986
|
+
var values = this.parseEnumValuesDefinition();
|
|
987
|
+
return {
|
|
988
|
+
kind: _kinds.Kind.ENUM_TYPE_DEFINITION,
|
|
989
|
+
description: description,
|
|
990
|
+
name: name,
|
|
991
|
+
directives: directives,
|
|
992
|
+
values: values,
|
|
993
|
+
loc: this.loc(start)
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* EnumValuesDefinition : { EnumValueDefinition+ }
|
|
998
|
+
*/
|
|
999
|
+
;
|
|
566
1000
|
|
|
567
|
-
function
|
|
568
|
-
|
|
1001
|
+
_proto.parseEnumValuesDefinition = function parseEnumValuesDefinition() {
|
|
1002
|
+
return this.optionalMany(_tokenKind.TokenKind.BRACE_L, this.parseEnumValueDefinition, _tokenKind.TokenKind.BRACE_R);
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* EnumValueDefinition : Description? EnumValue Directives[Const]?
|
|
1006
|
+
*
|
|
1007
|
+
* EnumValue : Name
|
|
1008
|
+
*/
|
|
1009
|
+
;
|
|
1010
|
+
|
|
1011
|
+
_proto.parseEnumValueDefinition = function parseEnumValueDefinition() {
|
|
1012
|
+
var start = this._lexer.token;
|
|
1013
|
+
var description = this.parseDescription();
|
|
1014
|
+
var name = this.parseName();
|
|
1015
|
+
var directives = this.parseDirectives(true);
|
|
1016
|
+
return {
|
|
1017
|
+
kind: _kinds.Kind.ENUM_VALUE_DEFINITION,
|
|
1018
|
+
description: description,
|
|
1019
|
+
name: name,
|
|
1020
|
+
directives: directives,
|
|
1021
|
+
loc: this.loc(start)
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* InputObjectTypeDefinition :
|
|
1026
|
+
* - Description? input Name Directives[Const]? InputFieldsDefinition?
|
|
1027
|
+
*/
|
|
1028
|
+
;
|
|
1029
|
+
|
|
1030
|
+
_proto.parseInputObjectTypeDefinition = function parseInputObjectTypeDefinition() {
|
|
1031
|
+
var start = this._lexer.token;
|
|
1032
|
+
var description = this.parseDescription();
|
|
1033
|
+
this.expectKeyword('input');
|
|
1034
|
+
var name = this.parseName();
|
|
1035
|
+
var directives = this.parseDirectives(true);
|
|
1036
|
+
var fields = this.parseInputFieldsDefinition();
|
|
1037
|
+
return {
|
|
1038
|
+
kind: _kinds.Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
1039
|
+
description: description,
|
|
1040
|
+
name: name,
|
|
1041
|
+
directives: directives,
|
|
1042
|
+
fields: fields,
|
|
1043
|
+
loc: this.loc(start)
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* InputFieldsDefinition : { InputValueDefinition+ }
|
|
1048
|
+
*/
|
|
1049
|
+
;
|
|
569
1050
|
|
|
570
|
-
|
|
571
|
-
return
|
|
572
|
-
};
|
|
573
|
-
|
|
574
|
-
return {
|
|
575
|
-
kind: _kinds.Kind.OBJECT,
|
|
576
|
-
fields: any(lexer, _tokenKind.TokenKind.BRACE_L, item, _tokenKind.TokenKind.BRACE_R),
|
|
577
|
-
loc: loc(lexer, start)
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
/**
|
|
581
|
-
* ObjectField[Const] : Name : Value[?Const]
|
|
582
|
-
*/
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
function parseObjectField(lexer, isConst) {
|
|
586
|
-
var start = lexer.token;
|
|
587
|
-
var name = parseName(lexer);
|
|
588
|
-
expectToken(lexer, _tokenKind.TokenKind.COLON);
|
|
589
|
-
return {
|
|
590
|
-
kind: _kinds.Kind.OBJECT_FIELD,
|
|
591
|
-
name: name,
|
|
592
|
-
value: parseValueLiteral(lexer, isConst),
|
|
593
|
-
loc: loc(lexer, start)
|
|
594
|
-
};
|
|
595
|
-
} // Implements the parsing rules in the Directives section.
|
|
596
|
-
|
|
597
|
-
/**
|
|
598
|
-
* Directives[Const] : Directive[?Const]+
|
|
599
|
-
*/
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
function parseDirectives(lexer, isConst) {
|
|
603
|
-
var directives = [];
|
|
604
|
-
|
|
605
|
-
while (peek(lexer, _tokenKind.TokenKind.AT)) {
|
|
606
|
-
directives.push(parseDirective(lexer, isConst));
|
|
1051
|
+
_proto.parseInputFieldsDefinition = function parseInputFieldsDefinition() {
|
|
1052
|
+
return this.optionalMany(_tokenKind.TokenKind.BRACE_L, this.parseInputValueDef, _tokenKind.TokenKind.BRACE_R);
|
|
607
1053
|
}
|
|
1054
|
+
/**
|
|
1055
|
+
* TypeSystemExtension :
|
|
1056
|
+
* - SchemaExtension
|
|
1057
|
+
* - TypeExtension
|
|
1058
|
+
*
|
|
1059
|
+
* TypeExtension :
|
|
1060
|
+
* - ScalarTypeExtension
|
|
1061
|
+
* - ObjectTypeExtension
|
|
1062
|
+
* - InterfaceTypeExtension
|
|
1063
|
+
* - UnionTypeExtension
|
|
1064
|
+
* - EnumTypeExtension
|
|
1065
|
+
* - InputObjectTypeDefinition
|
|
1066
|
+
*/
|
|
1067
|
+
;
|
|
1068
|
+
|
|
1069
|
+
_proto.parseTypeSystemExtension = function parseTypeSystemExtension() {
|
|
1070
|
+
var keywordToken = this._lexer.lookahead();
|
|
1071
|
+
|
|
1072
|
+
if (keywordToken.kind === _tokenKind.TokenKind.NAME) {
|
|
1073
|
+
switch (keywordToken.value) {
|
|
1074
|
+
case 'schema':
|
|
1075
|
+
return this.parseSchemaExtension();
|
|
1076
|
+
|
|
1077
|
+
case 'scalar':
|
|
1078
|
+
return this.parseScalarTypeExtension();
|
|
1079
|
+
|
|
1080
|
+
case 'type':
|
|
1081
|
+
return this.parseObjectTypeExtension();
|
|
1082
|
+
|
|
1083
|
+
case 'interface':
|
|
1084
|
+
return this.parseInterfaceTypeExtension();
|
|
1085
|
+
|
|
1086
|
+
case 'union':
|
|
1087
|
+
return this.parseUnionTypeExtension();
|
|
1088
|
+
|
|
1089
|
+
case 'enum':
|
|
1090
|
+
return this.parseEnumTypeExtension();
|
|
1091
|
+
|
|
1092
|
+
case 'input':
|
|
1093
|
+
return this.parseInputObjectTypeExtension();
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
608
1096
|
|
|
609
|
-
|
|
610
|
-
}
|
|
611
|
-
/**
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
* Type :
|
|
629
|
-
* - NamedType
|
|
630
|
-
* - ListType
|
|
631
|
-
* - NonNullType
|
|
632
|
-
*/
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
function parseTypeReference(lexer) {
|
|
636
|
-
var start = lexer.token;
|
|
637
|
-
var type;
|
|
1097
|
+
throw this.unexpected(keywordToken);
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* SchemaExtension :
|
|
1101
|
+
* - extend schema Directives[Const]? { OperationTypeDefinition+ }
|
|
1102
|
+
* - extend schema Directives[Const]
|
|
1103
|
+
*/
|
|
1104
|
+
;
|
|
1105
|
+
|
|
1106
|
+
_proto.parseSchemaExtension = function parseSchemaExtension() {
|
|
1107
|
+
var start = this._lexer.token;
|
|
1108
|
+
this.expectKeyword('extend');
|
|
1109
|
+
this.expectKeyword('schema');
|
|
1110
|
+
var directives = this.parseDirectives(true);
|
|
1111
|
+
var operationTypes = this.optionalMany(_tokenKind.TokenKind.BRACE_L, this.parseOperationTypeDefinition, _tokenKind.TokenKind.BRACE_R);
|
|
1112
|
+
|
|
1113
|
+
if (directives.length === 0 && operationTypes.length === 0) {
|
|
1114
|
+
throw this.unexpected();
|
|
1115
|
+
}
|
|
638
1116
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
type: type,
|
|
645
|
-
loc: loc(lexer, start)
|
|
1117
|
+
return {
|
|
1118
|
+
kind: _kinds.Kind.SCHEMA_EXTENSION,
|
|
1119
|
+
directives: directives,
|
|
1120
|
+
operationTypes: operationTypes,
|
|
1121
|
+
loc: this.loc(start)
|
|
646
1122
|
};
|
|
647
|
-
} else {
|
|
648
|
-
type = parseNamedType(lexer);
|
|
649
1123
|
}
|
|
1124
|
+
/**
|
|
1125
|
+
* ScalarTypeExtension :
|
|
1126
|
+
* - extend scalar Name Directives[Const]
|
|
1127
|
+
*/
|
|
1128
|
+
;
|
|
1129
|
+
|
|
1130
|
+
_proto.parseScalarTypeExtension = function parseScalarTypeExtension() {
|
|
1131
|
+
var start = this._lexer.token;
|
|
1132
|
+
this.expectKeyword('extend');
|
|
1133
|
+
this.expectKeyword('scalar');
|
|
1134
|
+
var name = this.parseName();
|
|
1135
|
+
var directives = this.parseDirectives(true);
|
|
1136
|
+
|
|
1137
|
+
if (directives.length === 0) {
|
|
1138
|
+
throw this.unexpected();
|
|
1139
|
+
}
|
|
650
1140
|
|
|
651
|
-
if (expectOptionalToken(lexer, _tokenKind.TokenKind.BANG)) {
|
|
652
1141
|
return {
|
|
653
|
-
kind: _kinds.Kind.
|
|
654
|
-
|
|
655
|
-
|
|
1142
|
+
kind: _kinds.Kind.SCALAR_TYPE_EXTENSION,
|
|
1143
|
+
name: name,
|
|
1144
|
+
directives: directives,
|
|
1145
|
+
loc: this.loc(start)
|
|
656
1146
|
};
|
|
657
1147
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
function
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
name
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
* - SchemaDefinition
|
|
678
|
-
* - TypeDefinition
|
|
679
|
-
* - DirectiveDefinition
|
|
680
|
-
*
|
|
681
|
-
* TypeDefinition :
|
|
682
|
-
* - ScalarTypeDefinition
|
|
683
|
-
* - ObjectTypeDefinition
|
|
684
|
-
* - InterfaceTypeDefinition
|
|
685
|
-
* - UnionTypeDefinition
|
|
686
|
-
* - EnumTypeDefinition
|
|
687
|
-
* - InputObjectTypeDefinition
|
|
688
|
-
*/
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
function parseTypeSystemDefinition(lexer) {
|
|
692
|
-
// Many definitions begin with a description and require a lookahead.
|
|
693
|
-
var keywordToken = peekDescription(lexer) ? lexer.lookahead() : lexer.token;
|
|
694
|
-
|
|
695
|
-
if (keywordToken.kind === _tokenKind.TokenKind.NAME) {
|
|
696
|
-
switch (keywordToken.value) {
|
|
697
|
-
case 'schema':
|
|
698
|
-
return parseSchemaDefinition(lexer);
|
|
699
|
-
|
|
700
|
-
case 'scalar':
|
|
701
|
-
return parseScalarTypeDefinition(lexer);
|
|
702
|
-
|
|
703
|
-
case 'type':
|
|
704
|
-
return parseObjectTypeDefinition(lexer);
|
|
705
|
-
|
|
706
|
-
case 'interface':
|
|
707
|
-
return parseInterfaceTypeDefinition(lexer);
|
|
708
|
-
|
|
709
|
-
case 'union':
|
|
710
|
-
return parseUnionTypeDefinition(lexer);
|
|
711
|
-
|
|
712
|
-
case 'enum':
|
|
713
|
-
return parseEnumTypeDefinition(lexer);
|
|
714
|
-
|
|
715
|
-
case 'input':
|
|
716
|
-
return parseInputObjectTypeDefinition(lexer);
|
|
717
|
-
|
|
718
|
-
case 'directive':
|
|
719
|
-
return parseDirectiveDefinition(lexer);
|
|
1148
|
+
/**
|
|
1149
|
+
* ObjectTypeExtension :
|
|
1150
|
+
* - extend type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition
|
|
1151
|
+
* - extend type Name ImplementsInterfaces? Directives[Const]
|
|
1152
|
+
* - extend type Name ImplementsInterfaces
|
|
1153
|
+
*/
|
|
1154
|
+
;
|
|
1155
|
+
|
|
1156
|
+
_proto.parseObjectTypeExtension = function parseObjectTypeExtension() {
|
|
1157
|
+
var start = this._lexer.token;
|
|
1158
|
+
this.expectKeyword('extend');
|
|
1159
|
+
this.expectKeyword('type');
|
|
1160
|
+
var name = this.parseName();
|
|
1161
|
+
var interfaces = this.parseImplementsInterfaces();
|
|
1162
|
+
var directives = this.parseDirectives(true);
|
|
1163
|
+
var fields = this.parseFieldsDefinition();
|
|
1164
|
+
|
|
1165
|
+
if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) {
|
|
1166
|
+
throw this.unexpected();
|
|
720
1167
|
}
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
throw unexpected(lexer, keywordToken);
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
function peekDescription(lexer) {
|
|
727
|
-
return peek(lexer, _tokenKind.TokenKind.STRING) || peek(lexer, _tokenKind.TokenKind.BLOCK_STRING);
|
|
728
|
-
}
|
|
729
|
-
/**
|
|
730
|
-
* Description : StringValue
|
|
731
|
-
*/
|
|
732
1168
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
1169
|
+
return {
|
|
1170
|
+
kind: _kinds.Kind.OBJECT_TYPE_EXTENSION,
|
|
1171
|
+
name: name,
|
|
1172
|
+
interfaces: interfaces,
|
|
1173
|
+
directives: directives,
|
|
1174
|
+
fields: fields,
|
|
1175
|
+
loc: this.loc(start)
|
|
1176
|
+
};
|
|
737
1177
|
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
}
|
|
756
|
-
/**
|
|
757
|
-
* OperationTypeDefinition : OperationType : NamedType
|
|
758
|
-
*/
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
function parseOperationTypeDefinition(lexer) {
|
|
762
|
-
var start = lexer.token;
|
|
763
|
-
var operation = parseOperationType(lexer);
|
|
764
|
-
expectToken(lexer, _tokenKind.TokenKind.COLON);
|
|
765
|
-
var type = parseNamedType(lexer);
|
|
766
|
-
return {
|
|
767
|
-
kind: _kinds.Kind.OPERATION_TYPE_DEFINITION,
|
|
768
|
-
operation: operation,
|
|
769
|
-
type: type,
|
|
770
|
-
loc: loc(lexer, start)
|
|
771
|
-
};
|
|
772
|
-
}
|
|
773
|
-
/**
|
|
774
|
-
* ScalarTypeDefinition : Description? scalar Name Directives[Const]?
|
|
775
|
-
*/
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
function parseScalarTypeDefinition(lexer) {
|
|
779
|
-
var start = lexer.token;
|
|
780
|
-
var description = parseDescription(lexer);
|
|
781
|
-
expectKeyword(lexer, 'scalar');
|
|
782
|
-
var name = parseName(lexer);
|
|
783
|
-
var directives = parseDirectives(lexer, true);
|
|
784
|
-
return {
|
|
785
|
-
kind: _kinds.Kind.SCALAR_TYPE_DEFINITION,
|
|
786
|
-
description: description,
|
|
787
|
-
name: name,
|
|
788
|
-
directives: directives,
|
|
789
|
-
loc: loc(lexer, start)
|
|
790
|
-
};
|
|
791
|
-
}
|
|
792
|
-
/**
|
|
793
|
-
* ObjectTypeDefinition :
|
|
794
|
-
* Description?
|
|
795
|
-
* type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition?
|
|
796
|
-
*/
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
function parseObjectTypeDefinition(lexer) {
|
|
800
|
-
var start = lexer.token;
|
|
801
|
-
var description = parseDescription(lexer);
|
|
802
|
-
expectKeyword(lexer, 'type');
|
|
803
|
-
var name = parseName(lexer);
|
|
804
|
-
var interfaces = parseImplementsInterfaces(lexer);
|
|
805
|
-
var directives = parseDirectives(lexer, true);
|
|
806
|
-
var fields = parseFieldsDefinition(lexer);
|
|
807
|
-
return {
|
|
808
|
-
kind: _kinds.Kind.OBJECT_TYPE_DEFINITION,
|
|
809
|
-
description: description,
|
|
810
|
-
name: name,
|
|
811
|
-
interfaces: interfaces,
|
|
812
|
-
directives: directives,
|
|
813
|
-
fields: fields,
|
|
814
|
-
loc: loc(lexer, start)
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
/**
|
|
818
|
-
* ImplementsInterfaces :
|
|
819
|
-
* - implements `&`? NamedType
|
|
820
|
-
* - ImplementsInterfaces & NamedType
|
|
821
|
-
*/
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
function parseImplementsInterfaces(lexer) {
|
|
825
|
-
var types = [];
|
|
826
|
-
|
|
827
|
-
if (expectOptionalKeyword(lexer, 'implements')) {
|
|
828
|
-
// Optional leading ampersand
|
|
829
|
-
expectOptionalToken(lexer, _tokenKind.TokenKind.AMP);
|
|
1178
|
+
/**
|
|
1179
|
+
* InterfaceTypeExtension :
|
|
1180
|
+
* - extend interface Name Directives[Const]? FieldsDefinition
|
|
1181
|
+
* - extend interface Name Directives[Const]
|
|
1182
|
+
*/
|
|
1183
|
+
;
|
|
1184
|
+
|
|
1185
|
+
_proto.parseInterfaceTypeExtension = function parseInterfaceTypeExtension() {
|
|
1186
|
+
var start = this._lexer.token;
|
|
1187
|
+
this.expectKeyword('extend');
|
|
1188
|
+
this.expectKeyword('interface');
|
|
1189
|
+
var name = this.parseName();
|
|
1190
|
+
var directives = this.parseDirectives(true);
|
|
1191
|
+
var fields = this.parseFieldsDefinition();
|
|
1192
|
+
|
|
1193
|
+
if (directives.length === 0 && fields.length === 0) {
|
|
1194
|
+
throw this.unexpected();
|
|
1195
|
+
}
|
|
830
1196
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
1197
|
+
return {
|
|
1198
|
+
kind: _kinds.Kind.INTERFACE_TYPE_EXTENSION,
|
|
1199
|
+
name: name,
|
|
1200
|
+
directives: directives,
|
|
1201
|
+
fields: fields,
|
|
1202
|
+
loc: this.loc(start)
|
|
1203
|
+
};
|
|
835
1204
|
}
|
|
1205
|
+
/**
|
|
1206
|
+
* UnionTypeExtension :
|
|
1207
|
+
* - extend union Name Directives[Const]? UnionMemberTypes
|
|
1208
|
+
* - extend union Name Directives[Const]
|
|
1209
|
+
*/
|
|
1210
|
+
;
|
|
1211
|
+
|
|
1212
|
+
_proto.parseUnionTypeExtension = function parseUnionTypeExtension() {
|
|
1213
|
+
var start = this._lexer.token;
|
|
1214
|
+
this.expectKeyword('extend');
|
|
1215
|
+
this.expectKeyword('union');
|
|
1216
|
+
var name = this.parseName();
|
|
1217
|
+
var directives = this.parseDirectives(true);
|
|
1218
|
+
var types = this.parseUnionMemberTypes();
|
|
1219
|
+
|
|
1220
|
+
if (directives.length === 0 && types.length === 0) {
|
|
1221
|
+
throw this.unexpected();
|
|
1222
|
+
}
|
|
836
1223
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
function parseFieldsDefinition(lexer) {
|
|
845
|
-
// Legacy support for the SDL?
|
|
846
|
-
if (lexer.options.allowLegacySDLEmptyFields && peek(lexer, _tokenKind.TokenKind.BRACE_L) && lexer.lookahead().kind === _tokenKind.TokenKind.BRACE_R) {
|
|
847
|
-
lexer.advance();
|
|
848
|
-
lexer.advance();
|
|
849
|
-
return [];
|
|
1224
|
+
return {
|
|
1225
|
+
kind: _kinds.Kind.UNION_TYPE_EXTENSION,
|
|
1226
|
+
name: name,
|
|
1227
|
+
directives: directives,
|
|
1228
|
+
types: types,
|
|
1229
|
+
loc: this.loc(start)
|
|
1230
|
+
};
|
|
850
1231
|
}
|
|
1232
|
+
/**
|
|
1233
|
+
* EnumTypeExtension :
|
|
1234
|
+
* - extend enum Name Directives[Const]? EnumValuesDefinition
|
|
1235
|
+
* - extend enum Name Directives[Const]
|
|
1236
|
+
*/
|
|
1237
|
+
;
|
|
1238
|
+
|
|
1239
|
+
_proto.parseEnumTypeExtension = function parseEnumTypeExtension() {
|
|
1240
|
+
var start = this._lexer.token;
|
|
1241
|
+
this.expectKeyword('extend');
|
|
1242
|
+
this.expectKeyword('enum');
|
|
1243
|
+
var name = this.parseName();
|
|
1244
|
+
var directives = this.parseDirectives(true);
|
|
1245
|
+
var values = this.parseEnumValuesDefinition();
|
|
1246
|
+
|
|
1247
|
+
if (directives.length === 0 && values.length === 0) {
|
|
1248
|
+
throw this.unexpected();
|
|
1249
|
+
}
|
|
851
1250
|
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
function parseFieldDefinition(lexer) {
|
|
861
|
-
var start = lexer.token;
|
|
862
|
-
var description = parseDescription(lexer);
|
|
863
|
-
var name = parseName(lexer);
|
|
864
|
-
var args = parseArgumentDefs(lexer);
|
|
865
|
-
expectToken(lexer, _tokenKind.TokenKind.COLON);
|
|
866
|
-
var type = parseTypeReference(lexer);
|
|
867
|
-
var directives = parseDirectives(lexer, true);
|
|
868
|
-
return {
|
|
869
|
-
kind: _kinds.Kind.FIELD_DEFINITION,
|
|
870
|
-
description: description,
|
|
871
|
-
name: name,
|
|
872
|
-
arguments: args,
|
|
873
|
-
type: type,
|
|
874
|
-
directives: directives,
|
|
875
|
-
loc: loc(lexer, start)
|
|
876
|
-
};
|
|
877
|
-
}
|
|
878
|
-
/**
|
|
879
|
-
* ArgumentsDefinition : ( InputValueDefinition+ )
|
|
880
|
-
*/
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
function parseArgumentDefs(lexer) {
|
|
884
|
-
if (!peek(lexer, _tokenKind.TokenKind.PAREN_L)) {
|
|
885
|
-
return [];
|
|
1251
|
+
return {
|
|
1252
|
+
kind: _kinds.Kind.ENUM_TYPE_EXTENSION,
|
|
1253
|
+
name: name,
|
|
1254
|
+
directives: directives,
|
|
1255
|
+
values: values,
|
|
1256
|
+
loc: this.loc(start)
|
|
1257
|
+
};
|
|
886
1258
|
}
|
|
1259
|
+
/**
|
|
1260
|
+
* InputObjectTypeExtension :
|
|
1261
|
+
* - extend input Name Directives[Const]? InputFieldsDefinition
|
|
1262
|
+
* - extend input Name Directives[Const]
|
|
1263
|
+
*/
|
|
1264
|
+
;
|
|
1265
|
+
|
|
1266
|
+
_proto.parseInputObjectTypeExtension = function parseInputObjectTypeExtension() {
|
|
1267
|
+
var start = this._lexer.token;
|
|
1268
|
+
this.expectKeyword('extend');
|
|
1269
|
+
this.expectKeyword('input');
|
|
1270
|
+
var name = this.parseName();
|
|
1271
|
+
var directives = this.parseDirectives(true);
|
|
1272
|
+
var fields = this.parseInputFieldsDefinition();
|
|
1273
|
+
|
|
1274
|
+
if (directives.length === 0 && fields.length === 0) {
|
|
1275
|
+
throw this.unexpected();
|
|
1276
|
+
}
|
|
887
1277
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
function parseInputValueDef(lexer) {
|
|
897
|
-
var start = lexer.token;
|
|
898
|
-
var description = parseDescription(lexer);
|
|
899
|
-
var name = parseName(lexer);
|
|
900
|
-
expectToken(lexer, _tokenKind.TokenKind.COLON);
|
|
901
|
-
var type = parseTypeReference(lexer);
|
|
902
|
-
var defaultValue;
|
|
903
|
-
|
|
904
|
-
if (expectOptionalToken(lexer, _tokenKind.TokenKind.EQUALS)) {
|
|
905
|
-
defaultValue = parseConstValue(lexer);
|
|
1278
|
+
return {
|
|
1279
|
+
kind: _kinds.Kind.INPUT_OBJECT_TYPE_EXTENSION,
|
|
1280
|
+
name: name,
|
|
1281
|
+
directives: directives,
|
|
1282
|
+
fields: fields,
|
|
1283
|
+
loc: this.loc(start)
|
|
1284
|
+
};
|
|
906
1285
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
/**
|
|
942
|
-
* UnionTypeDefinition :
|
|
943
|
-
* - Description? union Name Directives[Const]? UnionMemberTypes?
|
|
944
|
-
*/
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
function parseUnionTypeDefinition(lexer) {
|
|
948
|
-
var start = lexer.token;
|
|
949
|
-
var description = parseDescription(lexer);
|
|
950
|
-
expectKeyword(lexer, 'union');
|
|
951
|
-
var name = parseName(lexer);
|
|
952
|
-
var directives = parseDirectives(lexer, true);
|
|
953
|
-
var types = parseUnionMemberTypes(lexer);
|
|
954
|
-
return {
|
|
955
|
-
kind: _kinds.Kind.UNION_TYPE_DEFINITION,
|
|
956
|
-
description: description,
|
|
957
|
-
name: name,
|
|
958
|
-
directives: directives,
|
|
959
|
-
types: types,
|
|
960
|
-
loc: loc(lexer, start)
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
|
-
/**
|
|
964
|
-
* UnionMemberTypes :
|
|
965
|
-
* - = `|`? NamedType
|
|
966
|
-
* - UnionMemberTypes | NamedType
|
|
967
|
-
*/
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
function parseUnionMemberTypes(lexer) {
|
|
971
|
-
var types = [];
|
|
972
|
-
|
|
973
|
-
if (expectOptionalToken(lexer, _tokenKind.TokenKind.EQUALS)) {
|
|
1286
|
+
/**
|
|
1287
|
+
* DirectiveDefinition :
|
|
1288
|
+
* - Description? directive @ Name ArgumentsDefinition? `repeatable`? on DirectiveLocations
|
|
1289
|
+
*/
|
|
1290
|
+
;
|
|
1291
|
+
|
|
1292
|
+
_proto.parseDirectiveDefinition = function parseDirectiveDefinition() {
|
|
1293
|
+
var start = this._lexer.token;
|
|
1294
|
+
var description = this.parseDescription();
|
|
1295
|
+
this.expectKeyword('directive');
|
|
1296
|
+
this.expectToken(_tokenKind.TokenKind.AT);
|
|
1297
|
+
var name = this.parseName();
|
|
1298
|
+
var args = this.parseArgumentDefs();
|
|
1299
|
+
var repeatable = this.expectOptionalKeyword('repeatable');
|
|
1300
|
+
this.expectKeyword('on');
|
|
1301
|
+
var locations = this.parseDirectiveLocations();
|
|
1302
|
+
return {
|
|
1303
|
+
kind: _kinds.Kind.DIRECTIVE_DEFINITION,
|
|
1304
|
+
description: description,
|
|
1305
|
+
name: name,
|
|
1306
|
+
arguments: args,
|
|
1307
|
+
repeatable: repeatable,
|
|
1308
|
+
locations: locations,
|
|
1309
|
+
loc: this.loc(start)
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1313
|
+
* DirectiveLocations :
|
|
1314
|
+
* - `|`? DirectiveLocation
|
|
1315
|
+
* - DirectiveLocations | DirectiveLocation
|
|
1316
|
+
*/
|
|
1317
|
+
;
|
|
1318
|
+
|
|
1319
|
+
_proto.parseDirectiveLocations = function parseDirectiveLocations() {
|
|
974
1320
|
// Optional leading pipe
|
|
975
|
-
expectOptionalToken(
|
|
1321
|
+
this.expectOptionalToken(_tokenKind.TokenKind.PIPE);
|
|
1322
|
+
var locations = [];
|
|
976
1323
|
|
|
977
1324
|
do {
|
|
978
|
-
|
|
979
|
-
} while (expectOptionalToken(
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
return types;
|
|
983
|
-
}
|
|
984
|
-
/**
|
|
985
|
-
* EnumTypeDefinition :
|
|
986
|
-
* - Description? enum Name Directives[Const]? EnumValuesDefinition?
|
|
987
|
-
*/
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
function parseEnumTypeDefinition(lexer) {
|
|
991
|
-
var start = lexer.token;
|
|
992
|
-
var description = parseDescription(lexer);
|
|
993
|
-
expectKeyword(lexer, 'enum');
|
|
994
|
-
var name = parseName(lexer);
|
|
995
|
-
var directives = parseDirectives(lexer, true);
|
|
996
|
-
var values = parseEnumValuesDefinition(lexer);
|
|
997
|
-
return {
|
|
998
|
-
kind: _kinds.Kind.ENUM_TYPE_DEFINITION,
|
|
999
|
-
description: description,
|
|
1000
|
-
name: name,
|
|
1001
|
-
directives: directives,
|
|
1002
|
-
values: values,
|
|
1003
|
-
loc: loc(lexer, start)
|
|
1004
|
-
};
|
|
1005
|
-
}
|
|
1006
|
-
/**
|
|
1007
|
-
* EnumValuesDefinition : { EnumValueDefinition+ }
|
|
1008
|
-
*/
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
function parseEnumValuesDefinition(lexer) {
|
|
1012
|
-
return peek(lexer, _tokenKind.TokenKind.BRACE_L) ? many(lexer, _tokenKind.TokenKind.BRACE_L, parseEnumValueDefinition, _tokenKind.TokenKind.BRACE_R) : [];
|
|
1013
|
-
}
|
|
1014
|
-
/**
|
|
1015
|
-
* EnumValueDefinition : Description? EnumValue Directives[Const]?
|
|
1016
|
-
*
|
|
1017
|
-
* EnumValue : Name
|
|
1018
|
-
*/
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
function parseEnumValueDefinition(lexer) {
|
|
1022
|
-
var start = lexer.token;
|
|
1023
|
-
var description = parseDescription(lexer);
|
|
1024
|
-
var name = parseName(lexer);
|
|
1025
|
-
var directives = parseDirectives(lexer, true);
|
|
1026
|
-
return {
|
|
1027
|
-
kind: _kinds.Kind.ENUM_VALUE_DEFINITION,
|
|
1028
|
-
description: description,
|
|
1029
|
-
name: name,
|
|
1030
|
-
directives: directives,
|
|
1031
|
-
loc: loc(lexer, start)
|
|
1032
|
-
};
|
|
1033
|
-
}
|
|
1034
|
-
/**
|
|
1035
|
-
* InputObjectTypeDefinition :
|
|
1036
|
-
* - Description? input Name Directives[Const]? InputFieldsDefinition?
|
|
1037
|
-
*/
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
function parseInputObjectTypeDefinition(lexer) {
|
|
1041
|
-
var start = lexer.token;
|
|
1042
|
-
var description = parseDescription(lexer);
|
|
1043
|
-
expectKeyword(lexer, 'input');
|
|
1044
|
-
var name = parseName(lexer);
|
|
1045
|
-
var directives = parseDirectives(lexer, true);
|
|
1046
|
-
var fields = parseInputFieldsDefinition(lexer);
|
|
1047
|
-
return {
|
|
1048
|
-
kind: _kinds.Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
1049
|
-
description: description,
|
|
1050
|
-
name: name,
|
|
1051
|
-
directives: directives,
|
|
1052
|
-
fields: fields,
|
|
1053
|
-
loc: loc(lexer, start)
|
|
1054
|
-
};
|
|
1055
|
-
}
|
|
1056
|
-
/**
|
|
1057
|
-
* InputFieldsDefinition : { InputValueDefinition+ }
|
|
1058
|
-
*/
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
function parseInputFieldsDefinition(lexer) {
|
|
1062
|
-
return peek(lexer, _tokenKind.TokenKind.BRACE_L) ? many(lexer, _tokenKind.TokenKind.BRACE_L, parseInputValueDef, _tokenKind.TokenKind.BRACE_R) : [];
|
|
1063
|
-
}
|
|
1064
|
-
/**
|
|
1065
|
-
* TypeSystemExtension :
|
|
1066
|
-
* - SchemaExtension
|
|
1067
|
-
* - TypeExtension
|
|
1068
|
-
*
|
|
1069
|
-
* TypeExtension :
|
|
1070
|
-
* - ScalarTypeExtension
|
|
1071
|
-
* - ObjectTypeExtension
|
|
1072
|
-
* - InterfaceTypeExtension
|
|
1073
|
-
* - UnionTypeExtension
|
|
1074
|
-
* - EnumTypeExtension
|
|
1075
|
-
* - InputObjectTypeDefinition
|
|
1076
|
-
*/
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
function parseTypeSystemExtension(lexer) {
|
|
1080
|
-
var keywordToken = lexer.lookahead();
|
|
1325
|
+
locations.push(this.parseDirectiveLocation());
|
|
1326
|
+
} while (this.expectOptionalToken(_tokenKind.TokenKind.PIPE));
|
|
1081
1327
|
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1328
|
+
return locations;
|
|
1329
|
+
}
|
|
1330
|
+
/*
|
|
1331
|
+
* DirectiveLocation :
|
|
1332
|
+
* - ExecutableDirectiveLocation
|
|
1333
|
+
* - TypeSystemDirectiveLocation
|
|
1334
|
+
*
|
|
1335
|
+
* ExecutableDirectiveLocation : one of
|
|
1336
|
+
* `QUERY`
|
|
1337
|
+
* `MUTATION`
|
|
1338
|
+
* `SUBSCRIPTION`
|
|
1339
|
+
* `FIELD`
|
|
1340
|
+
* `FRAGMENT_DEFINITION`
|
|
1341
|
+
* `FRAGMENT_SPREAD`
|
|
1342
|
+
* `INLINE_FRAGMENT`
|
|
1343
|
+
*
|
|
1344
|
+
* TypeSystemDirectiveLocation : one of
|
|
1345
|
+
* `SCHEMA`
|
|
1346
|
+
* `SCALAR`
|
|
1347
|
+
* `OBJECT`
|
|
1348
|
+
* `FIELD_DEFINITION`
|
|
1349
|
+
* `ARGUMENT_DEFINITION`
|
|
1350
|
+
* `INTERFACE`
|
|
1351
|
+
* `UNION`
|
|
1352
|
+
* `ENUM`
|
|
1353
|
+
* `ENUM_VALUE`
|
|
1354
|
+
* `INPUT_OBJECT`
|
|
1355
|
+
* `INPUT_FIELD_DEFINITION`
|
|
1356
|
+
*/
|
|
1357
|
+
;
|
|
1358
|
+
|
|
1359
|
+
_proto.parseDirectiveLocation = function parseDirectiveLocation() {
|
|
1360
|
+
var start = this._lexer.token;
|
|
1361
|
+
var name = this.parseName();
|
|
1362
|
+
|
|
1363
|
+
if (_directiveLocation.DirectiveLocation[name.value] !== undefined) {
|
|
1364
|
+
return name;
|
|
1365
|
+
}
|
|
1095
1366
|
|
|
1096
|
-
|
|
1097
|
-
|
|
1367
|
+
throw this.unexpected(start);
|
|
1368
|
+
} // Core parsing utility functions
|
|
1098
1369
|
|
|
1099
|
-
|
|
1100
|
-
|
|
1370
|
+
/**
|
|
1371
|
+
* Returns a location object, used to identify the place in
|
|
1372
|
+
* the source that created a given parsed object.
|
|
1373
|
+
*/
|
|
1374
|
+
;
|
|
1101
1375
|
|
|
1102
|
-
|
|
1103
|
-
|
|
1376
|
+
_proto.loc = function loc(startToken) {
|
|
1377
|
+
if (!this._options.noLocation) {
|
|
1378
|
+
return new Loc(startToken, this._lexer.lastToken, this._lexer.source);
|
|
1104
1379
|
}
|
|
1105
1380
|
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Determines if the next token is of a given kind
|
|
1383
|
+
*/
|
|
1384
|
+
;
|
|
1106
1385
|
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
/**
|
|
1110
|
-
* SchemaExtension :
|
|
1111
|
-
* - extend schema Directives[Const]? { OperationTypeDefinition+ }
|
|
1112
|
-
* - extend schema Directives[Const]
|
|
1113
|
-
*/
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
function parseSchemaExtension(lexer) {
|
|
1117
|
-
var start = lexer.token;
|
|
1118
|
-
expectKeyword(lexer, 'extend');
|
|
1119
|
-
expectKeyword(lexer, 'schema');
|
|
1120
|
-
var directives = parseDirectives(lexer, true);
|
|
1121
|
-
var operationTypes = peek(lexer, _tokenKind.TokenKind.BRACE_L) ? many(lexer, _tokenKind.TokenKind.BRACE_L, parseOperationTypeDefinition, _tokenKind.TokenKind.BRACE_R) : [];
|
|
1122
|
-
|
|
1123
|
-
if (directives.length === 0 && operationTypes.length === 0) {
|
|
1124
|
-
throw unexpected(lexer);
|
|
1386
|
+
_proto.peek = function peek(kind) {
|
|
1387
|
+
return this._lexer.token.kind === kind;
|
|
1125
1388
|
}
|
|
1389
|
+
/**
|
|
1390
|
+
* If the next token is of the given kind, return that token after advancing
|
|
1391
|
+
* the lexer. Otherwise, do not change the parser state and throw an error.
|
|
1392
|
+
*/
|
|
1393
|
+
;
|
|
1126
1394
|
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
directives: directives,
|
|
1130
|
-
operationTypes: operationTypes,
|
|
1131
|
-
loc: loc(lexer, start)
|
|
1132
|
-
};
|
|
1133
|
-
}
|
|
1134
|
-
/**
|
|
1135
|
-
* ScalarTypeExtension :
|
|
1136
|
-
* - extend scalar Name Directives[Const]
|
|
1137
|
-
*/
|
|
1395
|
+
_proto.expectToken = function expectToken(kind) {
|
|
1396
|
+
var token = this._lexer.token;
|
|
1138
1397
|
|
|
1398
|
+
if (token.kind === kind) {
|
|
1399
|
+
this._lexer.advance();
|
|
1139
1400
|
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
expectKeyword(lexer, 'extend');
|
|
1143
|
-
expectKeyword(lexer, 'scalar');
|
|
1144
|
-
var name = parseName(lexer);
|
|
1145
|
-
var directives = parseDirectives(lexer, true);
|
|
1401
|
+
return token;
|
|
1402
|
+
}
|
|
1146
1403
|
|
|
1147
|
-
|
|
1148
|
-
throw unexpected(lexer);
|
|
1404
|
+
throw (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Expected ".concat(kind, ", found ").concat(getTokenDesc(token)));
|
|
1149
1405
|
}
|
|
1406
|
+
/**
|
|
1407
|
+
* If the next token is of the given kind, return that token after advancing
|
|
1408
|
+
* the lexer. Otherwise, do not change the parser state and return undefined.
|
|
1409
|
+
*/
|
|
1410
|
+
;
|
|
1150
1411
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
name: name,
|
|
1154
|
-
directives: directives,
|
|
1155
|
-
loc: loc(lexer, start)
|
|
1156
|
-
};
|
|
1157
|
-
}
|
|
1158
|
-
/**
|
|
1159
|
-
* ObjectTypeExtension :
|
|
1160
|
-
* - extend type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition
|
|
1161
|
-
* - extend type Name ImplementsInterfaces? Directives[Const]
|
|
1162
|
-
* - extend type Name ImplementsInterfaces
|
|
1163
|
-
*/
|
|
1412
|
+
_proto.expectOptionalToken = function expectOptionalToken(kind) {
|
|
1413
|
+
var token = this._lexer.token;
|
|
1164
1414
|
|
|
1415
|
+
if (token.kind === kind) {
|
|
1416
|
+
this._lexer.advance();
|
|
1165
1417
|
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
expectKeyword(lexer, 'extend');
|
|
1169
|
-
expectKeyword(lexer, 'type');
|
|
1170
|
-
var name = parseName(lexer);
|
|
1171
|
-
var interfaces = parseImplementsInterfaces(lexer);
|
|
1172
|
-
var directives = parseDirectives(lexer, true);
|
|
1173
|
-
var fields = parseFieldsDefinition(lexer);
|
|
1418
|
+
return token;
|
|
1419
|
+
}
|
|
1174
1420
|
|
|
1175
|
-
|
|
1176
|
-
throw unexpected(lexer);
|
|
1421
|
+
return undefined;
|
|
1177
1422
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
*/
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
function parseInterfaceTypeExtension(lexer) {
|
|
1196
|
-
var start = lexer.token;
|
|
1197
|
-
expectKeyword(lexer, 'extend');
|
|
1198
|
-
expectKeyword(lexer, 'interface');
|
|
1199
|
-
var name = parseName(lexer);
|
|
1200
|
-
var directives = parseDirectives(lexer, true);
|
|
1201
|
-
var fields = parseFieldsDefinition(lexer);
|
|
1202
|
-
|
|
1203
|
-
if (directives.length === 0 && fields.length === 0) {
|
|
1204
|
-
throw unexpected(lexer);
|
|
1423
|
+
/**
|
|
1424
|
+
* If the next token is a given keyword, advance the lexer.
|
|
1425
|
+
* Otherwise, do not change the parser state and throw an error.
|
|
1426
|
+
*/
|
|
1427
|
+
;
|
|
1428
|
+
|
|
1429
|
+
_proto.expectKeyword = function expectKeyword(value) {
|
|
1430
|
+
var token = this._lexer.token;
|
|
1431
|
+
|
|
1432
|
+
if (token.kind === _tokenKind.TokenKind.NAME && token.value === value) {
|
|
1433
|
+
this._lexer.advance();
|
|
1434
|
+
} else {
|
|
1435
|
+
throw (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Expected \"".concat(value, "\", found ").concat(getTokenDesc(token)));
|
|
1436
|
+
}
|
|
1205
1437
|
}
|
|
1438
|
+
/**
|
|
1439
|
+
* If the next token is a given keyword, return "true" after advancing
|
|
1440
|
+
* the lexer. Otherwise, do not change the parser state and return "false".
|
|
1441
|
+
*/
|
|
1442
|
+
;
|
|
1206
1443
|
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
name: name,
|
|
1210
|
-
directives: directives,
|
|
1211
|
-
fields: fields,
|
|
1212
|
-
loc: loc(lexer, start)
|
|
1213
|
-
};
|
|
1214
|
-
}
|
|
1215
|
-
/**
|
|
1216
|
-
* UnionTypeExtension :
|
|
1217
|
-
* - extend union Name Directives[Const]? UnionMemberTypes
|
|
1218
|
-
* - extend union Name Directives[Const]
|
|
1219
|
-
*/
|
|
1444
|
+
_proto.expectOptionalKeyword = function expectOptionalKeyword(value) {
|
|
1445
|
+
var token = this._lexer.token;
|
|
1220
1446
|
|
|
1447
|
+
if (token.kind === _tokenKind.TokenKind.NAME && token.value === value) {
|
|
1448
|
+
this._lexer.advance();
|
|
1221
1449
|
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
expectKeyword(lexer, 'extend');
|
|
1225
|
-
expectKeyword(lexer, 'union');
|
|
1226
|
-
var name = parseName(lexer);
|
|
1227
|
-
var directives = parseDirectives(lexer, true);
|
|
1228
|
-
var types = parseUnionMemberTypes(lexer);
|
|
1450
|
+
return true;
|
|
1451
|
+
}
|
|
1229
1452
|
|
|
1230
|
-
|
|
1231
|
-
throw unexpected(lexer);
|
|
1453
|
+
return false;
|
|
1232
1454
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
/**
|
|
1243
|
-
* EnumTypeExtension :
|
|
1244
|
-
* - extend enum Name Directives[Const]? EnumValuesDefinition
|
|
1245
|
-
* - extend enum Name Directives[Const]
|
|
1246
|
-
*/
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
function parseEnumTypeExtension(lexer) {
|
|
1250
|
-
var start = lexer.token;
|
|
1251
|
-
expectKeyword(lexer, 'extend');
|
|
1252
|
-
expectKeyword(lexer, 'enum');
|
|
1253
|
-
var name = parseName(lexer);
|
|
1254
|
-
var directives = parseDirectives(lexer, true);
|
|
1255
|
-
var values = parseEnumValuesDefinition(lexer);
|
|
1256
|
-
|
|
1257
|
-
if (directives.length === 0 && values.length === 0) {
|
|
1258
|
-
throw unexpected(lexer);
|
|
1455
|
+
/**
|
|
1456
|
+
* Helper function for creating an error when an unexpected lexed token
|
|
1457
|
+
* is encountered.
|
|
1458
|
+
*/
|
|
1459
|
+
;
|
|
1460
|
+
|
|
1461
|
+
_proto.unexpected = function unexpected(atToken) {
|
|
1462
|
+
var token = atToken || this._lexer.token;
|
|
1463
|
+
return (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Unexpected ".concat(getTokenDesc(token)));
|
|
1259
1464
|
}
|
|
1465
|
+
/**
|
|
1466
|
+
* Returns a possibly empty list of parse nodes, determined by
|
|
1467
|
+
* the parseFn. This list begins with a lex token of openKind
|
|
1468
|
+
* and ends with a lex token of closeKind. Advances the parser
|
|
1469
|
+
* to the next lex token after the closing token.
|
|
1470
|
+
*/
|
|
1471
|
+
;
|
|
1472
|
+
|
|
1473
|
+
_proto.any = function any(openKind, parseFn, closeKind) {
|
|
1474
|
+
this.expectToken(openKind);
|
|
1475
|
+
var nodes = [];
|
|
1476
|
+
|
|
1477
|
+
while (!this.expectOptionalToken(closeKind)) {
|
|
1478
|
+
nodes.push(parseFn.call(this));
|
|
1479
|
+
}
|
|
1260
1480
|
|
|
1261
|
-
|
|
1262
|
-
kind: _kinds.Kind.ENUM_TYPE_EXTENSION,
|
|
1263
|
-
name: name,
|
|
1264
|
-
directives: directives,
|
|
1265
|
-
values: values,
|
|
1266
|
-
loc: loc(lexer, start)
|
|
1267
|
-
};
|
|
1268
|
-
}
|
|
1269
|
-
/**
|
|
1270
|
-
* InputObjectTypeExtension :
|
|
1271
|
-
* - extend input Name Directives[Const]? InputFieldsDefinition
|
|
1272
|
-
* - extend input Name Directives[Const]
|
|
1273
|
-
*/
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
function parseInputObjectTypeExtension(lexer) {
|
|
1277
|
-
var start = lexer.token;
|
|
1278
|
-
expectKeyword(lexer, 'extend');
|
|
1279
|
-
expectKeyword(lexer, 'input');
|
|
1280
|
-
var name = parseName(lexer);
|
|
1281
|
-
var directives = parseDirectives(lexer, true);
|
|
1282
|
-
var fields = parseInputFieldsDefinition(lexer);
|
|
1283
|
-
|
|
1284
|
-
if (directives.length === 0 && fields.length === 0) {
|
|
1285
|
-
throw unexpected(lexer);
|
|
1481
|
+
return nodes;
|
|
1286
1482
|
}
|
|
1483
|
+
/**
|
|
1484
|
+
* Returns a list of parse nodes, determined by the parseFn.
|
|
1485
|
+
* It can be empty only if open token is missing otherwise it will always
|
|
1486
|
+
* return non-empty list that begins with a lex token of openKind and ends
|
|
1487
|
+
* with a lex token of closeKind. Advances the parser to the next lex token
|
|
1488
|
+
* after the closing token.
|
|
1489
|
+
*/
|
|
1490
|
+
;
|
|
1491
|
+
|
|
1492
|
+
_proto.optionalMany = function optionalMany(openKind, parseFn, closeKind) {
|
|
1493
|
+
if (this.expectOptionalToken(openKind)) {
|
|
1494
|
+
var nodes = [];
|
|
1495
|
+
|
|
1496
|
+
do {
|
|
1497
|
+
nodes.push(parseFn.call(this));
|
|
1498
|
+
} while (!this.expectOptionalToken(closeKind));
|
|
1499
|
+
|
|
1500
|
+
return nodes;
|
|
1501
|
+
}
|
|
1287
1502
|
|
|
1288
|
-
|
|
1289
|
-
kind: _kinds.Kind.INPUT_OBJECT_TYPE_EXTENSION,
|
|
1290
|
-
name: name,
|
|
1291
|
-
directives: directives,
|
|
1292
|
-
fields: fields,
|
|
1293
|
-
loc: loc(lexer, start)
|
|
1294
|
-
};
|
|
1295
|
-
}
|
|
1296
|
-
/**
|
|
1297
|
-
* DirectiveDefinition :
|
|
1298
|
-
* - Description? directive @ Name ArgumentsDefinition? `repeatable`? on DirectiveLocations
|
|
1299
|
-
*/
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
function parseDirectiveDefinition(lexer) {
|
|
1303
|
-
var start = lexer.token;
|
|
1304
|
-
var description = parseDescription(lexer);
|
|
1305
|
-
expectKeyword(lexer, 'directive');
|
|
1306
|
-
expectToken(lexer, _tokenKind.TokenKind.AT);
|
|
1307
|
-
var name = parseName(lexer);
|
|
1308
|
-
var args = parseArgumentDefs(lexer);
|
|
1309
|
-
var repeatable = expectOptionalKeyword(lexer, 'repeatable');
|
|
1310
|
-
expectKeyword(lexer, 'on');
|
|
1311
|
-
var locations = parseDirectiveLocations(lexer);
|
|
1312
|
-
return {
|
|
1313
|
-
kind: _kinds.Kind.DIRECTIVE_DEFINITION,
|
|
1314
|
-
description: description,
|
|
1315
|
-
name: name,
|
|
1316
|
-
arguments: args,
|
|
1317
|
-
repeatable: repeatable,
|
|
1318
|
-
locations: locations,
|
|
1319
|
-
loc: loc(lexer, start)
|
|
1320
|
-
};
|
|
1321
|
-
}
|
|
1322
|
-
/**
|
|
1323
|
-
* DirectiveLocations :
|
|
1324
|
-
* - `|`? DirectiveLocation
|
|
1325
|
-
* - DirectiveLocations | DirectiveLocation
|
|
1326
|
-
*/
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
function parseDirectiveLocations(lexer) {
|
|
1330
|
-
// Optional leading pipe
|
|
1331
|
-
expectOptionalToken(lexer, _tokenKind.TokenKind.PIPE);
|
|
1332
|
-
var locations = [];
|
|
1333
|
-
|
|
1334
|
-
do {
|
|
1335
|
-
locations.push(parseDirectiveLocation(lexer));
|
|
1336
|
-
} while (expectOptionalToken(lexer, _tokenKind.TokenKind.PIPE));
|
|
1337
|
-
|
|
1338
|
-
return locations;
|
|
1339
|
-
}
|
|
1340
|
-
/*
|
|
1341
|
-
* DirectiveLocation :
|
|
1342
|
-
* - ExecutableDirectiveLocation
|
|
1343
|
-
* - TypeSystemDirectiveLocation
|
|
1344
|
-
*
|
|
1345
|
-
* ExecutableDirectiveLocation : one of
|
|
1346
|
-
* `QUERY`
|
|
1347
|
-
* `MUTATION`
|
|
1348
|
-
* `SUBSCRIPTION`
|
|
1349
|
-
* `FIELD`
|
|
1350
|
-
* `FRAGMENT_DEFINITION`
|
|
1351
|
-
* `FRAGMENT_SPREAD`
|
|
1352
|
-
* `INLINE_FRAGMENT`
|
|
1353
|
-
*
|
|
1354
|
-
* TypeSystemDirectiveLocation : one of
|
|
1355
|
-
* `SCHEMA`
|
|
1356
|
-
* `SCALAR`
|
|
1357
|
-
* `OBJECT`
|
|
1358
|
-
* `FIELD_DEFINITION`
|
|
1359
|
-
* `ARGUMENT_DEFINITION`
|
|
1360
|
-
* `INTERFACE`
|
|
1361
|
-
* `UNION`
|
|
1362
|
-
* `ENUM`
|
|
1363
|
-
* `ENUM_VALUE`
|
|
1364
|
-
* `INPUT_OBJECT`
|
|
1365
|
-
* `INPUT_FIELD_DEFINITION`
|
|
1366
|
-
*/
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
function parseDirectiveLocation(lexer) {
|
|
1370
|
-
var start = lexer.token;
|
|
1371
|
-
var name = parseName(lexer);
|
|
1372
|
-
|
|
1373
|
-
if (_directiveLocation.DirectiveLocation[name.value] !== undefined) {
|
|
1374
|
-
return name;
|
|
1503
|
+
return [];
|
|
1375
1504
|
}
|
|
1505
|
+
/**
|
|
1506
|
+
* Returns a non-empty list of parse nodes, determined by
|
|
1507
|
+
* the parseFn. This list begins with a lex token of openKind
|
|
1508
|
+
* and ends with a lex token of closeKind. Advances the parser
|
|
1509
|
+
* to the next lex token after the closing token.
|
|
1510
|
+
*/
|
|
1511
|
+
;
|
|
1512
|
+
|
|
1513
|
+
_proto.many = function many(openKind, parseFn, closeKind) {
|
|
1514
|
+
this.expectToken(openKind);
|
|
1515
|
+
var nodes = [];
|
|
1376
1516
|
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
/**
|
|
1381
|
-
* Returns a location object, used to identify the place in
|
|
1382
|
-
* the source that created a given parsed object.
|
|
1383
|
-
*/
|
|
1517
|
+
do {
|
|
1518
|
+
nodes.push(parseFn.call(this));
|
|
1519
|
+
} while (!this.expectOptionalToken(closeKind));
|
|
1384
1520
|
|
|
1521
|
+
return nodes;
|
|
1522
|
+
};
|
|
1385
1523
|
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
return new Loc(startToken, lexer.lastToken, lexer.source);
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1524
|
+
return Parser;
|
|
1525
|
+
}();
|
|
1391
1526
|
|
|
1392
1527
|
function Loc(startToken, endToken, source) {
|
|
1393
1528
|
this.start = startToken.start;
|
|
@@ -1405,118 +1540,10 @@ function Loc(startToken, endToken, source) {
|
|
|
1405
1540
|
};
|
|
1406
1541
|
});
|
|
1407
1542
|
/**
|
|
1408
|
-
*
|
|
1409
|
-
*/
|
|
1410
|
-
|
|
1411
|
-
function peek(lexer, kind) {
|
|
1412
|
-
return lexer.token.kind === kind;
|
|
1413
|
-
}
|
|
1414
|
-
/**
|
|
1415
|
-
* If the next token is of the given kind, return that token after advancing
|
|
1416
|
-
* the lexer. Otherwise, do not change the parser state and throw an error.
|
|
1543
|
+
* A helper function to describe a token as a string for debugging
|
|
1417
1544
|
*/
|
|
1418
1545
|
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
if (token.kind === kind) {
|
|
1424
|
-
lexer.advance();
|
|
1425
|
-
return token;
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
throw (0, _syntaxError.syntaxError)(lexer.source, token.start, "Expected ".concat(kind, ", found ").concat((0, _lexer.getTokenDesc)(token)));
|
|
1429
|
-
}
|
|
1430
|
-
/**
|
|
1431
|
-
* If the next token is of the given kind, return that token after advancing
|
|
1432
|
-
* the lexer. Otherwise, do not change the parser state and return undefined.
|
|
1433
|
-
*/
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
function expectOptionalToken(lexer, kind) {
|
|
1437
|
-
var token = lexer.token;
|
|
1438
|
-
|
|
1439
|
-
if (token.kind === kind) {
|
|
1440
|
-
lexer.advance();
|
|
1441
|
-
return token;
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
return undefined;
|
|
1445
|
-
}
|
|
1446
|
-
/**
|
|
1447
|
-
* If the next token is a given keyword, advance the lexer.
|
|
1448
|
-
* Otherwise, do not change the parser state and throw an error.
|
|
1449
|
-
*/
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
function expectKeyword(lexer, value) {
|
|
1453
|
-
var token = lexer.token;
|
|
1454
|
-
|
|
1455
|
-
if (token.kind === _tokenKind.TokenKind.NAME && token.value === value) {
|
|
1456
|
-
lexer.advance();
|
|
1457
|
-
} else {
|
|
1458
|
-
throw (0, _syntaxError.syntaxError)(lexer.source, token.start, "Expected \"".concat(value, "\", found ").concat((0, _lexer.getTokenDesc)(token)));
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
/**
|
|
1462
|
-
* If the next token is a given keyword, return "true" after advancing
|
|
1463
|
-
* the lexer. Otherwise, do not change the parser state and return "false".
|
|
1464
|
-
*/
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
function expectOptionalKeyword(lexer, value) {
|
|
1468
|
-
var token = lexer.token;
|
|
1469
|
-
|
|
1470
|
-
if (token.kind === _tokenKind.TokenKind.NAME && token.value === value) {
|
|
1471
|
-
lexer.advance();
|
|
1472
|
-
return true;
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
|
-
return false;
|
|
1476
|
-
}
|
|
1477
|
-
/**
|
|
1478
|
-
* Helper function for creating an error when an unexpected lexed token
|
|
1479
|
-
* is encountered.
|
|
1480
|
-
*/
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
function unexpected(lexer, atToken) {
|
|
1484
|
-
var token = atToken || lexer.token;
|
|
1485
|
-
return (0, _syntaxError.syntaxError)(lexer.source, token.start, "Unexpected ".concat((0, _lexer.getTokenDesc)(token)));
|
|
1486
|
-
}
|
|
1487
|
-
/**
|
|
1488
|
-
* Returns a possibly empty list of parse nodes, determined by
|
|
1489
|
-
* the parseFn. This list begins with a lex token of openKind
|
|
1490
|
-
* and ends with a lex token of closeKind. Advances the parser
|
|
1491
|
-
* to the next lex token after the closing token.
|
|
1492
|
-
*/
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
function any(lexer, openKind, parseFn, closeKind) {
|
|
1496
|
-
expectToken(lexer, openKind);
|
|
1497
|
-
var nodes = [];
|
|
1498
|
-
|
|
1499
|
-
while (!expectOptionalToken(lexer, closeKind)) {
|
|
1500
|
-
nodes.push(parseFn(lexer));
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
return nodes;
|
|
1504
|
-
}
|
|
1505
|
-
/**
|
|
1506
|
-
* Returns a non-empty list of parse nodes, determined by
|
|
1507
|
-
* the parseFn. This list begins with a lex token of openKind
|
|
1508
|
-
* and ends with a lex token of closeKind. Advances the parser
|
|
1509
|
-
* to the next lex token after the closing token.
|
|
1510
|
-
*/
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
function many(lexer, openKind, parseFn, closeKind) {
|
|
1514
|
-
expectToken(lexer, openKind);
|
|
1515
|
-
var nodes = [parseFn(lexer)];
|
|
1516
|
-
|
|
1517
|
-
while (!expectOptionalToken(lexer, closeKind)) {
|
|
1518
|
-
nodes.push(parseFn(lexer));
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
return nodes;
|
|
1546
|
+
function getTokenDesc(token) {
|
|
1547
|
+
var value = token.value;
|
|
1548
|
+
return value ? "".concat(token.kind, " \"").concat(value, "\"") : token.kind;
|
|
1522
1549
|
}
|