graphql 15.3.0 → 15.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +10 -0
- package/error/GraphQLError.js +8 -8
- package/error/GraphQLError.js.flow +2 -3
- package/error/GraphQLError.mjs +2 -2
- package/error/formatError.js +1 -1
- package/error/formatError.js.flow +0 -1
- package/error/index.js +4 -4
- package/error/index.js.flow +0 -1
- package/error/locatedError.d.ts +2 -2
- package/error/locatedError.js +10 -5
- package/error/locatedError.js.flow +10 -4
- package/error/locatedError.mjs +6 -4
- package/error/syntaxError.js +1 -1
- package/error/syntaxError.js.flow +0 -1
- package/execution/execute.d.ts +0 -15
- package/execution/execute.js +104 -104
- package/execution/execute.js.flow +119 -133
- package/execution/execute.mjs +86 -82
- package/execution/index.js +3 -3
- package/execution/index.js.flow +0 -1
- package/execution/values.js +11 -11
- package/execution/values.js.flow +0 -1
- package/graphql.js +5 -5
- package/graphql.js.flow +0 -1
- package/index.d.ts +1 -0
- package/index.js +9 -9
- package/index.js.flow +0 -1
- package/jsutils/ObjMap.js.flow +0 -1
- package/jsutils/Path.js.flow +0 -1
- package/jsutils/PromiseOrValue.js.flow +0 -1
- package/jsutils/defineInspect.js +2 -2
- package/jsutils/defineInspect.js.flow +0 -1
- package/jsutils/devAssert.js.flow +0 -1
- package/jsutils/didYouMean.js.flow +0 -1
- package/jsutils/identityFunc.js.flow +0 -1
- package/jsutils/inspect.js +1 -2
- package/jsutils/inspect.js.flow +10 -8
- package/jsutils/inspect.mjs +1 -1
- package/jsutils/instanceOf.js +15 -9
- package/jsutils/instanceOf.js.flow +13 -7
- package/jsutils/instanceOf.mjs +13 -5
- package/jsutils/invariant.js.flow +0 -1
- package/jsutils/isAsyncIterable.js +13 -0
- package/jsutils/isAsyncIterable.js.flow +14 -0
- package/jsutils/isAsyncIterable.mjs +10 -0
- package/jsutils/isObjectLike.js.flow +0 -1
- package/jsutils/isPromise.js.flow +0 -1
- package/jsutils/keyMap.js.flow +0 -1
- package/jsutils/keyValMap.js.flow +0 -1
- package/jsutils/mapValue.js +1 -1
- package/jsutils/mapValue.js.flow +0 -1
- package/jsutils/memoize3.js +2 -5
- package/jsutils/memoize3.js.flow +2 -5
- package/jsutils/memoize3.mjs +2 -5
- package/jsutils/naturalCompare.js +69 -0
- package/jsutils/naturalCompare.js.flow +59 -0
- package/jsutils/naturalCompare.mjs +61 -0
- package/jsutils/nodejsCustomInspectSymbol.js.flow +0 -1
- package/jsutils/printPathArray.js.flow +0 -1
- package/jsutils/promiseForObject.js.flow +0 -1
- package/jsutils/promiseReduce.js +1 -1
- package/jsutils/promiseReduce.js.flow +0 -1
- package/jsutils/safeArrayFrom.js +73 -0
- package/jsutils/safeArrayFrom.js.flow +59 -0
- package/jsutils/safeArrayFrom.mjs +66 -0
- package/jsutils/suggestionList.js +5 -1
- package/jsutils/suggestionList.js.flow +3 -2
- package/jsutils/suggestionList.mjs +3 -1
- package/jsutils/toObjMap.js +1 -1
- package/jsutils/toObjMap.js.flow +0 -1
- package/language/ast.js +1 -1
- package/language/ast.js.flow +0 -1
- package/language/blockString.d.ts +1 -1
- package/language/blockString.js +53 -32
- package/language/blockString.js.flow +51 -36
- package/language/blockString.mjs +54 -33
- package/language/directiveLocation.js.flow +0 -1
- package/language/experimentalOnlineParser/grammar.d.ts +1006 -0
- package/language/experimentalOnlineParser/grammar.js +987 -0
- package/language/experimentalOnlineParser/grammar.js.flow +1000 -0
- package/language/experimentalOnlineParser/grammar.mjs +980 -0
- package/language/experimentalOnlineParser/index.d.ts +6 -0
- package/language/experimentalOnlineParser/index.js +31 -0
- package/language/experimentalOnlineParser/index.js.flow +7 -0
- package/language/experimentalOnlineParser/index.mjs +1 -0
- package/language/experimentalOnlineParser/onlineParser.d.ts +125 -0
- package/language/experimentalOnlineParser/onlineParser.js +604 -0
- package/language/experimentalOnlineParser/onlineParser.js.flow +723 -0
- package/language/experimentalOnlineParser/onlineParser.mjs +587 -0
- package/language/index.js +12 -12
- package/language/index.js.flow +0 -1
- package/language/kinds.js.flow +0 -1
- package/language/lexer.js +242 -183
- package/language/lexer.js.flow +188 -184
- package/language/lexer.mjs +238 -179
- package/language/location.js.flow +0 -1
- package/language/parser.js +73 -68
- package/language/parser.js.flow +62 -57
- package/language/parser.mjs +64 -60
- package/language/predicates.js +1 -1
- package/language/predicates.js.flow +0 -1
- package/language/printLocation.js +1 -1
- package/language/printLocation.js.flow +0 -1
- package/language/printer.js +20 -13
- package/language/printer.js.flow +26 -25
- package/language/printer.mjs +18 -11
- package/language/source.d.ts +7 -0
- package/language/source.js +20 -3
- package/language/source.js.flow +21 -3
- package/language/source.mjs +14 -1
- package/language/tokenKind.js.flow +0 -1
- package/language/visitor.js +2 -2
- package/language/visitor.js.flow +0 -1
- package/package.json +2 -3
- package/polyfills/arrayFrom.js +2 -2
- package/polyfills/arrayFrom.js.flow +1 -2
- package/polyfills/arrayFrom.mjs +1 -1
- package/polyfills/find.js +1 -1
- package/polyfills/find.js.flow +1 -2
- package/polyfills/find.mjs +1 -1
- package/polyfills/isFinite.js +1 -1
- package/polyfills/isFinite.js.flow +1 -2
- package/polyfills/isFinite.mjs +1 -1
- package/polyfills/isInteger.js +1 -1
- package/polyfills/isInteger.js.flow +1 -2
- package/polyfills/isInteger.mjs +1 -1
- package/polyfills/objectEntries.js +1 -1
- package/polyfills/objectEntries.js.flow +1 -2
- package/polyfills/objectEntries.mjs +1 -1
- package/polyfills/objectValues.js +1 -1
- package/polyfills/objectValues.js.flow +1 -2
- package/polyfills/objectValues.mjs +1 -1
- package/polyfills/symbols.js +3 -5
- package/polyfills/symbols.js.flow +9 -6
- package/polyfills/symbols.mjs +3 -5
- package/subscription/index.js +1 -1
- package/subscription/index.js.flow +0 -1
- package/subscription/mapAsyncIterator.js +2 -2
- package/subscription/mapAsyncIterator.js.flow +8 -9
- package/subscription/mapAsyncIterator.mjs +1 -1
- package/subscription/subscribe.js +61 -73
- package/subscription/subscribe.js.flow +71 -85
- package/subscription/subscribe.mjs +53 -65
- package/type/definition.d.ts +16 -6
- package/type/definition.js +37 -32
- package/type/definition.js.flow +93 -63
- package/type/definition.mjs +19 -14
- package/type/directives.js +17 -16
- package/type/directives.js.flow +20 -13
- package/type/directives.mjs +6 -5
- package/type/index.js +6 -6
- package/type/index.js.flow +0 -1
- package/type/introspection.js +86 -65
- package/type/introspection.js.flow +75 -43
- package/type/introspection.mjs +79 -58
- package/type/scalars.js +9 -9
- package/type/scalars.js.flow +1 -2
- package/type/scalars.mjs +1 -1
- package/type/schema.js +13 -13
- package/type/schema.js.flow +2 -3
- package/type/schema.mjs +1 -1
- package/type/validate.js +52 -19
- package/type/validate.js.flow +54 -8
- package/type/validate.mjs +43 -9
- package/utilities/TypeInfo.js +7 -7
- package/utilities/TypeInfo.js.flow +1 -2
- package/utilities/assertValidName.js +2 -2
- package/utilities/assertValidName.js.flow +0 -1
- package/utilities/astFromValue.js +14 -16
- package/utilities/astFromValue.js.flow +6 -7
- package/utilities/astFromValue.mjs +6 -7
- package/utilities/buildASTSchema.js +17 -27
- package/utilities/buildASTSchema.js.flow +5 -21
- package/utilities/buildASTSchema.mjs +11 -21
- package/utilities/buildClientSchema.js +16 -15
- package/utilities/buildClientSchema.js.flow +28 -12
- package/utilities/buildClientSchema.mjs +5 -4
- package/utilities/coerceInputValue.js +17 -18
- package/utilities/coerceInputValue.js.flow +12 -10
- package/utilities/coerceInputValue.mjs +7 -7
- package/utilities/concatAST.js +9 -8
- package/utilities/concatAST.js.flow +8 -8
- package/utilities/concatAST.mjs +9 -6
- package/utilities/extendSchema.js +26 -19
- package/utilities/extendSchema.js.flow +19 -7
- package/utilities/extendSchema.mjs +8 -1
- package/utilities/findBreakingChanges.js +15 -11
- package/utilities/findBreakingChanges.js.flow +6 -3
- package/utilities/findBreakingChanges.mjs +5 -2
- package/utilities/findDeprecatedUsages.js +2 -2
- package/utilities/findDeprecatedUsages.js.flow +0 -1
- package/utilities/getIntrospectionQuery.d.ts +6 -0
- package/utilities/getIntrospectionQuery.js +8 -2
- package/utilities/getIntrospectionQuery.js.flow +17 -5
- package/utilities/getIntrospectionQuery.mjs +8 -2
- package/utilities/getOperationAST.js +1 -1
- package/utilities/getOperationAST.js.flow +0 -1
- package/utilities/getOperationRootType.js +1 -1
- package/utilities/getOperationRootType.js.flow +0 -1
- package/utilities/index.d.ts +3 -0
- package/utilities/index.js +22 -22
- package/utilities/index.js.flow +0 -1
- package/utilities/introspectionFromSchema.js +7 -5
- package/utilities/introspectionFromSchema.js.flow +2 -1
- package/utilities/introspectionFromSchema.mjs +3 -1
- package/utilities/lexicographicSortSchema.js +13 -9
- package/utilities/lexicographicSortSchema.js.flow +21 -13
- package/utilities/lexicographicSortSchema.mjs +5 -2
- package/utilities/printSchema.js +15 -16
- package/utilities/printSchema.js.flow +23 -16
- package/utilities/printSchema.mjs +5 -6
- package/utilities/separateOperations.js +46 -42
- package/utilities/separateOperations.js.flow +46 -37
- package/utilities/separateOperations.mjs +44 -40
- package/utilities/stripIgnoredCharacters.js +6 -16
- package/utilities/stripIgnoredCharacters.js.flow +4 -13
- package/utilities/stripIgnoredCharacters.mjs +3 -10
- package/utilities/typeComparators.js +1 -1
- package/utilities/typeComparators.js.flow +0 -1
- package/utilities/typeFromAST.js +6 -6
- package/utilities/typeFromAST.js.flow +2 -3
- package/utilities/typeFromAST.mjs +2 -2
- package/utilities/typedQueryDocumentNode.d.ts +20 -0
- package/utilities/valueFromAST.js +6 -6
- package/utilities/valueFromAST.js.flow +4 -2
- package/utilities/valueFromASTUntyped.js +4 -4
- package/utilities/valueFromASTUntyped.js.flow +0 -1
- package/validation/ValidationContext.js +3 -3
- package/validation/ValidationContext.js.flow +3 -4
- package/validation/index.js +38 -38
- package/validation/index.js.flow +0 -1
- package/validation/rules/ExecutableDefinitions.js +1 -1
- package/validation/rules/ExecutableDefinitions.js.flow +0 -1
- package/validation/rules/ExecutableDefinitionsRule.js +3 -3
- package/validation/rules/ExecutableDefinitionsRule.js.flow +0 -1
- package/validation/rules/FieldsOnCorrectTypeRule.js +8 -6
- package/validation/rules/FieldsOnCorrectTypeRule.js.flow +2 -2
- package/validation/rules/FieldsOnCorrectTypeRule.mjs +2 -1
- package/validation/rules/FragmentsOnCompositeTypesRule.js +4 -4
- package/validation/rules/FragmentsOnCompositeTypesRule.js.flow +0 -1
- package/validation/rules/KnownArgumentNamesRule.js +5 -5
- package/validation/rules/KnownArgumentNamesRule.js.flow +1 -1
- package/validation/rules/KnownDirectivesRule.js +6 -6
- package/validation/rules/KnownDirectivesRule.js.flow +4 -3
- package/validation/rules/KnownFragmentNamesRule.js +1 -1
- package/validation/rules/KnownFragmentNamesRule.js.flow +0 -1
- package/validation/rules/KnownTypeNamesRule.js +6 -6
- package/validation/rules/KnownTypeNamesRule.js.flow +1 -2
- package/validation/rules/LoneAnonymousOperationRule.js +2 -2
- package/validation/rules/LoneAnonymousOperationRule.js.flow +0 -1
- package/validation/rules/LoneSchemaDefinition.js +1 -1
- package/validation/rules/LoneSchemaDefinition.js.flow +0 -1
- package/validation/rules/LoneSchemaDefinitionRule.js +1 -1
- package/validation/rules/LoneSchemaDefinitionRule.js.flow +0 -1
- package/validation/rules/NoFragmentCyclesRule.js +1 -1
- package/validation/rules/NoFragmentCyclesRule.js.flow +1 -2
- package/validation/rules/NoUndefinedVariablesRule.js +1 -1
- package/validation/rules/NoUndefinedVariablesRule.js.flow +0 -1
- package/validation/rules/NoUnusedFragmentsRule.js +1 -1
- package/validation/rules/NoUnusedFragmentsRule.js.flow +0 -1
- package/validation/rules/NoUnusedVariablesRule.js +1 -1
- package/validation/rules/NoUnusedVariablesRule.js.flow +0 -1
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +20 -20
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js.flow +14 -14
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +12 -12
- package/validation/rules/PossibleFragmentSpreadsRule.js +5 -5
- package/validation/rules/PossibleFragmentSpreadsRule.js.flow +5 -2
- package/validation/rules/PossibleTypeExtensions.js +1 -1
- package/validation/rules/PossibleTypeExtensions.js.flow +0 -1
- package/validation/rules/PossibleTypeExtensionsRule.js +8 -8
- package/validation/rules/PossibleTypeExtensionsRule.js.flow +6 -4
- package/validation/rules/ProvidedRequiredArgumentsRule.js +7 -7
- package/validation/rules/ProvidedRequiredArgumentsRule.js.flow +4 -3
- package/validation/rules/ScalarLeafsRule.js +3 -3
- package/validation/rules/ScalarLeafsRule.js.flow +0 -1
- package/validation/rules/SingleFieldSubscriptionsRule.js +1 -1
- package/validation/rules/SingleFieldSubscriptionsRule.js.flow +0 -1
- package/validation/rules/UniqueArgumentNamesRule.js +1 -1
- package/validation/rules/UniqueArgumentNamesRule.js.flow +0 -1
- package/validation/rules/UniqueDirectiveNames.js +1 -1
- package/validation/rules/UniqueDirectiveNames.js.flow +0 -1
- package/validation/rules/UniqueDirectiveNamesRule.js +2 -2
- package/validation/rules/UniqueDirectiveNamesRule.js.flow +0 -1
- package/validation/rules/UniqueDirectiveNamesRule.mjs +1 -1
- package/validation/rules/UniqueDirectivesPerLocationRule.js +4 -4
- package/validation/rules/UniqueDirectivesPerLocationRule.js.flow +0 -1
- package/validation/rules/UniqueEnumValueNames.js +1 -1
- package/validation/rules/UniqueEnumValueNames.js.flow +0 -1
- package/validation/rules/UniqueEnumValueNamesRule.js +2 -2
- package/validation/rules/UniqueEnumValueNamesRule.js.flow +7 -2
- package/validation/rules/UniqueFieldDefinitionNames.js +1 -1
- package/validation/rules/UniqueFieldDefinitionNames.js.flow +0 -1
- package/validation/rules/UniqueFieldDefinitionNamesRule.js +3 -3
- package/validation/rules/UniqueFieldDefinitionNamesRule.js.flow +13 -4
- package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +1 -1
- package/validation/rules/UniqueFragmentNamesRule.js +1 -1
- package/validation/rules/UniqueFragmentNamesRule.js.flow +0 -1
- package/validation/rules/UniqueInputFieldNamesRule.js +1 -1
- package/validation/rules/UniqueInputFieldNamesRule.js.flow +0 -1
- package/validation/rules/UniqueOperationNamesRule.js +1 -1
- package/validation/rules/UniqueOperationNamesRule.js.flow +0 -1
- package/validation/rules/UniqueOperationTypes.js +1 -1
- package/validation/rules/UniqueOperationTypes.js.flow +0 -1
- package/validation/rules/UniqueOperationTypesRule.js +1 -1
- package/validation/rules/UniqueOperationTypesRule.js.flow +7 -2
- package/validation/rules/UniqueTypeNames.js +1 -1
- package/validation/rules/UniqueTypeNames.js.flow +0 -1
- package/validation/rules/UniqueTypeNamesRule.js +2 -2
- package/validation/rules/UniqueTypeNamesRule.js.flow +0 -1
- package/validation/rules/UniqueTypeNamesRule.mjs +1 -1
- package/validation/rules/UniqueVariableNamesRule.js +1 -1
- package/validation/rules/UniqueVariableNamesRule.js.flow +0 -1
- package/validation/rules/ValuesOfCorrectTypeRule.js +8 -8
- package/validation/rules/ValuesOfCorrectTypeRule.js.flow +0 -1
- package/validation/rules/VariablesAreInputTypesRule.js +4 -4
- package/validation/rules/VariablesAreInputTypesRule.js.flow +0 -1
- package/validation/rules/VariablesInAllowedPositionRule.js +6 -6
- package/validation/rules/VariablesInAllowedPositionRule.js.flow +0 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.js +47 -9
- package/validation/rules/custom/NoDeprecatedCustomRule.js.flow +56 -13
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs +43 -8
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +3 -3
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.flow +0 -1
- package/validation/specifiedRules.js +33 -33
- package/validation/specifiedRules.js.flow +0 -1
- package/validation/validate.js +7 -7
- package/validation/validate.js.flow +4 -5
- package/version.js +3 -3
- package/version.js.flow +3 -4
- package/version.mjs +3 -3
- package/jsutils/isCollection.js +0 -47
- package/jsutils/isCollection.js.flow +0 -39
- package/jsutils/isCollection.mjs +0 -40
- package/polyfills/flatMap.js +0 -30
- package/polyfills/flatMap.js.flow +0 -28
- package/polyfills/flatMap.mjs +0 -23
package/language/parser.js
CHANGED
|
@@ -6,26 +6,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.parse = parse;
|
|
7
7
|
exports.parseValue = parseValue;
|
|
8
8
|
exports.parseType = parseType;
|
|
9
|
+
exports.Parser = void 0;
|
|
9
10
|
|
|
10
|
-
var
|
|
11
|
+
var _syntaxError = require("../error/syntaxError.js");
|
|
11
12
|
|
|
12
|
-
var
|
|
13
|
+
var _kinds = require("./kinds.js");
|
|
13
14
|
|
|
14
|
-
var
|
|
15
|
+
var _ast = require("./ast.js");
|
|
15
16
|
|
|
16
|
-
var
|
|
17
|
+
var _tokenKind = require("./tokenKind.js");
|
|
17
18
|
|
|
18
|
-
var
|
|
19
|
+
var _source = require("./source.js");
|
|
19
20
|
|
|
20
|
-
var
|
|
21
|
+
var _directiveLocation = require("./directiveLocation.js");
|
|
21
22
|
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
var _directiveLocation = require("./directiveLocation");
|
|
25
|
-
|
|
26
|
-
var _lexer = require("./lexer");
|
|
27
|
-
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
var _lexer = require("./lexer.js");
|
|
29
24
|
|
|
30
25
|
/**
|
|
31
26
|
* Given a GraphQL source, parses it into a Document.
|
|
@@ -73,11 +68,22 @@ function parseType(source, options) {
|
|
|
73
68
|
parser.expectToken(_tokenKind.TokenKind.EOF);
|
|
74
69
|
return type;
|
|
75
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* This class is exported only to assist people in implementing their own parsers
|
|
73
|
+
* without duplicating too much code and should be used only as last resort for cases
|
|
74
|
+
* such as experimental syntax or if certain features could not be contributed upstream.
|
|
75
|
+
*
|
|
76
|
+
* It is still part of the internal API and is versioned, so any changes to it are never
|
|
77
|
+
* considered breaking changes. If you still need to support multiple versions of the
|
|
78
|
+
* library, please use the `versionInfo` variable for version detection.
|
|
79
|
+
*
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
|
|
76
83
|
|
|
77
84
|
var Parser = /*#__PURE__*/function () {
|
|
78
85
|
function Parser(source, options) {
|
|
79
|
-
var sourceObj =
|
|
80
|
-
sourceObj instanceof _source.Source || (0, _devAssert.default)(0, "Must provide Source. Received: ".concat((0, _inspect.default)(sourceObj), "."));
|
|
86
|
+
var sourceObj = (0, _source.isSource)(source) ? source : new _source.Source(source);
|
|
81
87
|
this._lexer = new _lexer.Lexer(sourceObj);
|
|
82
88
|
this._options = options;
|
|
83
89
|
}
|
|
@@ -822,21 +828,25 @@ var Parser = /*#__PURE__*/function () {
|
|
|
822
828
|
;
|
|
823
829
|
|
|
824
830
|
_proto.parseImplementsInterfaces = function parseImplementsInterfaces() {
|
|
825
|
-
var
|
|
831
|
+
var _this$_options2;
|
|
832
|
+
|
|
833
|
+
if (!this.expectOptionalKeyword('implements')) {
|
|
834
|
+
return [];
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
if (((_this$_options2 = this._options) === null || _this$_options2 === void 0 ? void 0 : _this$_options2.allowLegacySDLImplementsInterfaces) === true) {
|
|
838
|
+
var types = []; // Optional leading ampersand
|
|
826
839
|
|
|
827
|
-
if (this.expectOptionalKeyword('implements')) {
|
|
828
|
-
// Optional leading ampersand
|
|
829
840
|
this.expectOptionalToken(_tokenKind.TokenKind.AMP);
|
|
830
841
|
|
|
831
842
|
do {
|
|
832
|
-
var _this$_options2;
|
|
833
|
-
|
|
834
843
|
types.push(this.parseNamedType());
|
|
835
|
-
} while (this.expectOptionalToken(_tokenKind.TokenKind.AMP) ||
|
|
836
|
-
|
|
844
|
+
} while (this.expectOptionalToken(_tokenKind.TokenKind.AMP) || this.peek(_tokenKind.TokenKind.NAME));
|
|
845
|
+
|
|
846
|
+
return types;
|
|
837
847
|
}
|
|
838
848
|
|
|
839
|
-
return
|
|
849
|
+
return this.delimitedMany(_tokenKind.TokenKind.AMP, this.parseNamedType);
|
|
840
850
|
}
|
|
841
851
|
/**
|
|
842
852
|
* FieldsDefinition : { FieldDefinition+ }
|
|
@@ -972,18 +982,7 @@ var Parser = /*#__PURE__*/function () {
|
|
|
972
982
|
;
|
|
973
983
|
|
|
974
984
|
_proto.parseUnionMemberTypes = function parseUnionMemberTypes() {
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
if (this.expectOptionalToken(_tokenKind.TokenKind.EQUALS)) {
|
|
978
|
-
// Optional leading pipe
|
|
979
|
-
this.expectOptionalToken(_tokenKind.TokenKind.PIPE);
|
|
980
|
-
|
|
981
|
-
do {
|
|
982
|
-
types.push(this.parseNamedType());
|
|
983
|
-
} while (this.expectOptionalToken(_tokenKind.TokenKind.PIPE));
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
return types;
|
|
985
|
+
return this.expectOptionalToken(_tokenKind.TokenKind.EQUALS) ? this.delimitedMany(_tokenKind.TokenKind.PIPE, this.parseNamedType) : [];
|
|
987
986
|
}
|
|
988
987
|
/**
|
|
989
988
|
* EnumTypeDefinition :
|
|
@@ -1334,15 +1333,7 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1334
1333
|
;
|
|
1335
1334
|
|
|
1336
1335
|
_proto.parseDirectiveLocations = function parseDirectiveLocations() {
|
|
1337
|
-
|
|
1338
|
-
this.expectOptionalToken(_tokenKind.TokenKind.PIPE);
|
|
1339
|
-
var locations = [];
|
|
1340
|
-
|
|
1341
|
-
do {
|
|
1342
|
-
locations.push(this.parseDirectiveLocation());
|
|
1343
|
-
} while (this.expectOptionalToken(_tokenKind.TokenKind.PIPE));
|
|
1344
|
-
|
|
1345
|
-
return locations;
|
|
1336
|
+
return this.delimitedMany(_tokenKind.TokenKind.PIPE, this.parseDirectiveLocation);
|
|
1346
1337
|
}
|
|
1347
1338
|
/*
|
|
1348
1339
|
* DirectiveLocation :
|
|
@@ -1385,8 +1376,7 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1385
1376
|
} // Core parsing utility functions
|
|
1386
1377
|
|
|
1387
1378
|
/**
|
|
1388
|
-
* Returns a location object, used to identify the place in
|
|
1389
|
-
* the source that created a given parsed object.
|
|
1379
|
+
* Returns a location object, used to identify the place in the source that created a given parsed object.
|
|
1390
1380
|
*/
|
|
1391
1381
|
;
|
|
1392
1382
|
|
|
@@ -1406,8 +1396,8 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1406
1396
|
return this._lexer.token.kind === kind;
|
|
1407
1397
|
}
|
|
1408
1398
|
/**
|
|
1409
|
-
* If the next token is of the given kind, return that token after advancing
|
|
1410
|
-
*
|
|
1399
|
+
* If the next token is of the given kind, return that token after advancing the lexer.
|
|
1400
|
+
* Otherwise, do not change the parser state and throw an error.
|
|
1411
1401
|
*/
|
|
1412
1402
|
;
|
|
1413
1403
|
|
|
@@ -1423,8 +1413,8 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1423
1413
|
throw (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Expected ".concat(getTokenKindDesc(kind), ", found ").concat(getTokenDesc(token), "."));
|
|
1424
1414
|
}
|
|
1425
1415
|
/**
|
|
1426
|
-
* If the next token is of the given kind, return that token after advancing
|
|
1427
|
-
*
|
|
1416
|
+
* If the next token is of the given kind, return that token after advancing the lexer.
|
|
1417
|
+
* Otherwise, do not change the parser state and return undefined.
|
|
1428
1418
|
*/
|
|
1429
1419
|
;
|
|
1430
1420
|
|
|
@@ -1455,8 +1445,8 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1455
1445
|
}
|
|
1456
1446
|
}
|
|
1457
1447
|
/**
|
|
1458
|
-
* If the next token is a given keyword, return "true" after advancing
|
|
1459
|
-
*
|
|
1448
|
+
* If the next token is a given keyword, return "true" after advancing the lexer.
|
|
1449
|
+
* Otherwise, do not change the parser state and return "false".
|
|
1460
1450
|
*/
|
|
1461
1451
|
;
|
|
1462
1452
|
|
|
@@ -1472,8 +1462,7 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1472
1462
|
return false;
|
|
1473
1463
|
}
|
|
1474
1464
|
/**
|
|
1475
|
-
* Helper function for creating an error when an unexpected lexed token
|
|
1476
|
-
* is encountered.
|
|
1465
|
+
* Helper function for creating an error when an unexpected lexed token is encountered.
|
|
1477
1466
|
*/
|
|
1478
1467
|
;
|
|
1479
1468
|
|
|
@@ -1482,10 +1471,9 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1482
1471
|
return (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Unexpected ".concat(getTokenDesc(token), "."));
|
|
1483
1472
|
}
|
|
1484
1473
|
/**
|
|
1485
|
-
* Returns a possibly empty list of parse nodes, determined by
|
|
1486
|
-
*
|
|
1487
|
-
*
|
|
1488
|
-
* to the next lex token after the closing token.
|
|
1474
|
+
* Returns a possibly empty list of parse nodes, determined by the parseFn.
|
|
1475
|
+
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1476
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1489
1477
|
*/
|
|
1490
1478
|
;
|
|
1491
1479
|
|
|
@@ -1501,10 +1489,9 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1501
1489
|
}
|
|
1502
1490
|
/**
|
|
1503
1491
|
* Returns a list of parse nodes, determined by the parseFn.
|
|
1504
|
-
* It can be empty only if open token is missing otherwise it will always
|
|
1505
|
-
*
|
|
1506
|
-
*
|
|
1507
|
-
* after the closing token.
|
|
1492
|
+
* It can be empty only if open token is missing otherwise it will always return non-empty list
|
|
1493
|
+
* that begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1494
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1508
1495
|
*/
|
|
1509
1496
|
;
|
|
1510
1497
|
|
|
@@ -1522,10 +1509,9 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1522
1509
|
return [];
|
|
1523
1510
|
}
|
|
1524
1511
|
/**
|
|
1525
|
-
* Returns a non-empty list of parse nodes, determined by
|
|
1526
|
-
*
|
|
1527
|
-
*
|
|
1528
|
-
* to the next lex token after the closing token.
|
|
1512
|
+
* Returns a non-empty list of parse nodes, determined by the parseFn.
|
|
1513
|
+
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1514
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1529
1515
|
*/
|
|
1530
1516
|
;
|
|
1531
1517
|
|
|
@@ -1537,22 +1523,41 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1537
1523
|
nodes.push(parseFn.call(this));
|
|
1538
1524
|
} while (!this.expectOptionalToken(closeKind));
|
|
1539
1525
|
|
|
1526
|
+
return nodes;
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Returns a non-empty list of parse nodes, determined by the parseFn.
|
|
1530
|
+
* This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
|
|
1531
|
+
* Advances the parser to the next lex token after last item in the list.
|
|
1532
|
+
*/
|
|
1533
|
+
;
|
|
1534
|
+
|
|
1535
|
+
_proto.delimitedMany = function delimitedMany(delimiterKind, parseFn) {
|
|
1536
|
+
this.expectOptionalToken(delimiterKind);
|
|
1537
|
+
var nodes = [];
|
|
1538
|
+
|
|
1539
|
+
do {
|
|
1540
|
+
nodes.push(parseFn.call(this));
|
|
1541
|
+
} while (this.expectOptionalToken(delimiterKind));
|
|
1542
|
+
|
|
1540
1543
|
return nodes;
|
|
1541
1544
|
};
|
|
1542
1545
|
|
|
1543
1546
|
return Parser;
|
|
1544
1547
|
}();
|
|
1545
1548
|
/**
|
|
1546
|
-
* A helper function to describe a token as a string for debugging
|
|
1549
|
+
* A helper function to describe a token as a string for debugging.
|
|
1547
1550
|
*/
|
|
1548
1551
|
|
|
1549
1552
|
|
|
1553
|
+
exports.Parser = Parser;
|
|
1554
|
+
|
|
1550
1555
|
function getTokenDesc(token) {
|
|
1551
1556
|
var value = token.value;
|
|
1552
1557
|
return getTokenKindDesc(token.kind) + (value != null ? " \"".concat(value, "\"") : '');
|
|
1553
1558
|
}
|
|
1554
1559
|
/**
|
|
1555
|
-
* A helper function to describe a token kind as a string for debugging
|
|
1560
|
+
* A helper function to describe a token kind as a string for debugging.
|
|
1556
1561
|
*/
|
|
1557
1562
|
|
|
1558
1563
|
|
package/language/parser.js.flow
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
// @flow strict
|
|
2
|
-
|
|
3
|
-
import inspect from '../jsutils/inspect';
|
|
4
|
-
import devAssert from '../jsutils/devAssert';
|
|
5
|
-
|
|
6
2
|
import type { GraphQLError } from '../error/GraphQLError';
|
|
7
3
|
import { syntaxError } from '../error/syntaxError';
|
|
8
4
|
|
|
@@ -55,8 +51,8 @@ import type {
|
|
|
55
51
|
} from './ast';
|
|
56
52
|
import { Kind } from './kinds';
|
|
57
53
|
import { Location } from './ast';
|
|
58
|
-
import { Source } from './source';
|
|
59
54
|
import { TokenKind } from './tokenKind';
|
|
55
|
+
import { Source, isSource } from './source';
|
|
60
56
|
import { DirectiveLocation } from './directiveLocation';
|
|
61
57
|
import { Lexer, isPunctuatorTokenKind } from './lexer';
|
|
62
58
|
|
|
@@ -164,16 +160,23 @@ export function parseType(
|
|
|
164
160
|
return type;
|
|
165
161
|
}
|
|
166
162
|
|
|
167
|
-
|
|
163
|
+
/**
|
|
164
|
+
* This class is exported only to assist people in implementing their own parsers
|
|
165
|
+
* without duplicating too much code and should be used only as last resort for cases
|
|
166
|
+
* such as experimental syntax or if certain features could not be contributed upstream.
|
|
167
|
+
*
|
|
168
|
+
* It is still part of the internal API and is versioned, so any changes to it are never
|
|
169
|
+
* considered breaking changes. If you still need to support multiple versions of the
|
|
170
|
+
* library, please use the `versionInfo` variable for version detection.
|
|
171
|
+
*
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
174
|
+
export class Parser {
|
|
168
175
|
_options: ?ParseOptions;
|
|
169
176
|
_lexer: Lexer;
|
|
170
177
|
|
|
171
178
|
constructor(source: string | Source, options?: ParseOptions) {
|
|
172
|
-
const sourceObj =
|
|
173
|
-
devAssert(
|
|
174
|
-
sourceObj instanceof Source,
|
|
175
|
-
`Must provide Source. Received: ${inspect(sourceObj)}.`,
|
|
176
|
-
);
|
|
179
|
+
const sourceObj = isSource(source) ? source : new Source(source);
|
|
177
180
|
|
|
178
181
|
this._lexer = new Lexer(sourceObj);
|
|
179
182
|
this._options = options;
|
|
@@ -853,20 +856,24 @@ class Parser {
|
|
|
853
856
|
* - ImplementsInterfaces & NamedType
|
|
854
857
|
*/
|
|
855
858
|
parseImplementsInterfaces(): Array<NamedTypeNode> {
|
|
856
|
-
|
|
857
|
-
|
|
859
|
+
if (!this.expectOptionalKeyword('implements')) {
|
|
860
|
+
return [];
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
if (this._options?.allowLegacySDLImplementsInterfaces === true) {
|
|
864
|
+
const types = [];
|
|
858
865
|
// Optional leading ampersand
|
|
859
866
|
this.expectOptionalToken(TokenKind.AMP);
|
|
860
867
|
do {
|
|
861
868
|
types.push(this.parseNamedType());
|
|
862
869
|
} while (
|
|
863
870
|
this.expectOptionalToken(TokenKind.AMP) ||
|
|
864
|
-
|
|
865
|
-
(this._options?.allowLegacySDLImplementsInterfaces === true &&
|
|
866
|
-
this.peek(TokenKind.NAME))
|
|
871
|
+
this.peek(TokenKind.NAME)
|
|
867
872
|
);
|
|
873
|
+
return types;
|
|
868
874
|
}
|
|
869
|
-
|
|
875
|
+
|
|
876
|
+
return this.delimitedMany(TokenKind.AMP, this.parseNamedType);
|
|
870
877
|
}
|
|
871
878
|
|
|
872
879
|
/**
|
|
@@ -1000,15 +1007,9 @@ class Parser {
|
|
|
1000
1007
|
* - UnionMemberTypes | NamedType
|
|
1001
1008
|
*/
|
|
1002
1009
|
parseUnionMemberTypes(): Array<NamedTypeNode> {
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
this.expectOptionalToken(TokenKind.PIPE);
|
|
1007
|
-
do {
|
|
1008
|
-
types.push(this.parseNamedType());
|
|
1009
|
-
} while (this.expectOptionalToken(TokenKind.PIPE));
|
|
1010
|
-
}
|
|
1011
|
-
return types;
|
|
1010
|
+
return this.expectOptionalToken(TokenKind.EQUALS)
|
|
1011
|
+
? this.delimitedMany(TokenKind.PIPE, this.parseNamedType)
|
|
1012
|
+
: [];
|
|
1012
1013
|
}
|
|
1013
1014
|
|
|
1014
1015
|
/**
|
|
@@ -1344,13 +1345,7 @@ class Parser {
|
|
|
1344
1345
|
* - DirectiveLocations | DirectiveLocation
|
|
1345
1346
|
*/
|
|
1346
1347
|
parseDirectiveLocations(): Array<NameNode> {
|
|
1347
|
-
|
|
1348
|
-
this.expectOptionalToken(TokenKind.PIPE);
|
|
1349
|
-
const locations = [];
|
|
1350
|
-
do {
|
|
1351
|
-
locations.push(this.parseDirectiveLocation());
|
|
1352
|
-
} while (this.expectOptionalToken(TokenKind.PIPE));
|
|
1353
|
-
return locations;
|
|
1348
|
+
return this.delimitedMany(TokenKind.PIPE, this.parseDirectiveLocation);
|
|
1354
1349
|
}
|
|
1355
1350
|
|
|
1356
1351
|
/*
|
|
@@ -1392,8 +1387,7 @@ class Parser {
|
|
|
1392
1387
|
// Core parsing utility functions
|
|
1393
1388
|
|
|
1394
1389
|
/**
|
|
1395
|
-
* Returns a location object, used to identify the place in
|
|
1396
|
-
* the source that created a given parsed object.
|
|
1390
|
+
* Returns a location object, used to identify the place in the source that created a given parsed object.
|
|
1397
1391
|
*/
|
|
1398
1392
|
loc(startToken: Token): Location | void {
|
|
1399
1393
|
if (this._options?.noLocation !== true) {
|
|
@@ -1413,8 +1407,8 @@ class Parser {
|
|
|
1413
1407
|
}
|
|
1414
1408
|
|
|
1415
1409
|
/**
|
|
1416
|
-
* If the next token is of the given kind, return that token after advancing
|
|
1417
|
-
*
|
|
1410
|
+
* If the next token is of the given kind, return that token after advancing the lexer.
|
|
1411
|
+
* Otherwise, do not change the parser state and throw an error.
|
|
1418
1412
|
*/
|
|
1419
1413
|
expectToken(kind: TokenKindEnum): Token {
|
|
1420
1414
|
const token = this._lexer.token;
|
|
@@ -1431,8 +1425,8 @@ class Parser {
|
|
|
1431
1425
|
}
|
|
1432
1426
|
|
|
1433
1427
|
/**
|
|
1434
|
-
* If the next token is of the given kind, return that token after advancing
|
|
1435
|
-
*
|
|
1428
|
+
* If the next token is of the given kind, return that token after advancing the lexer.
|
|
1429
|
+
* Otherwise, do not change the parser state and return undefined.
|
|
1436
1430
|
*/
|
|
1437
1431
|
expectOptionalToken(kind: TokenKindEnum): ?Token {
|
|
1438
1432
|
const token = this._lexer.token;
|
|
@@ -1461,8 +1455,8 @@ class Parser {
|
|
|
1461
1455
|
}
|
|
1462
1456
|
|
|
1463
1457
|
/**
|
|
1464
|
-
* If the next token is a given keyword, return "true" after advancing
|
|
1465
|
-
*
|
|
1458
|
+
* If the next token is a given keyword, return "true" after advancing the lexer.
|
|
1459
|
+
* Otherwise, do not change the parser state and return "false".
|
|
1466
1460
|
*/
|
|
1467
1461
|
expectOptionalKeyword(value: string): boolean {
|
|
1468
1462
|
const token = this._lexer.token;
|
|
@@ -1474,8 +1468,7 @@ class Parser {
|
|
|
1474
1468
|
}
|
|
1475
1469
|
|
|
1476
1470
|
/**
|
|
1477
|
-
* Helper function for creating an error when an unexpected lexed token
|
|
1478
|
-
* is encountered.
|
|
1471
|
+
* Helper function for creating an error when an unexpected lexed token is encountered.
|
|
1479
1472
|
*/
|
|
1480
1473
|
unexpected(atToken?: ?Token): GraphQLError {
|
|
1481
1474
|
const token = atToken ?? this._lexer.token;
|
|
@@ -1487,10 +1480,9 @@ class Parser {
|
|
|
1487
1480
|
}
|
|
1488
1481
|
|
|
1489
1482
|
/**
|
|
1490
|
-
* Returns a possibly empty list of parse nodes, determined by
|
|
1491
|
-
*
|
|
1492
|
-
*
|
|
1493
|
-
* to the next lex token after the closing token.
|
|
1483
|
+
* Returns a possibly empty list of parse nodes, determined by the parseFn.
|
|
1484
|
+
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1485
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1494
1486
|
*/
|
|
1495
1487
|
any<T>(
|
|
1496
1488
|
openKind: TokenKindEnum,
|
|
@@ -1507,10 +1499,9 @@ class Parser {
|
|
|
1507
1499
|
|
|
1508
1500
|
/**
|
|
1509
1501
|
* Returns a list of parse nodes, determined by the parseFn.
|
|
1510
|
-
* It can be empty only if open token is missing otherwise it will always
|
|
1511
|
-
*
|
|
1512
|
-
*
|
|
1513
|
-
* after the closing token.
|
|
1502
|
+
* It can be empty only if open token is missing otherwise it will always return non-empty list
|
|
1503
|
+
* that begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1504
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1514
1505
|
*/
|
|
1515
1506
|
optionalMany<T>(
|
|
1516
1507
|
openKind: TokenKindEnum,
|
|
@@ -1528,10 +1519,9 @@ class Parser {
|
|
|
1528
1519
|
}
|
|
1529
1520
|
|
|
1530
1521
|
/**
|
|
1531
|
-
* Returns a non-empty list of parse nodes, determined by
|
|
1532
|
-
*
|
|
1533
|
-
*
|
|
1534
|
-
* to the next lex token after the closing token.
|
|
1522
|
+
* Returns a non-empty list of parse nodes, determined by the parseFn.
|
|
1523
|
+
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1524
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1535
1525
|
*/
|
|
1536
1526
|
many<T>(
|
|
1537
1527
|
openKind: TokenKindEnum,
|
|
@@ -1545,10 +1535,25 @@ class Parser {
|
|
|
1545
1535
|
} while (!this.expectOptionalToken(closeKind));
|
|
1546
1536
|
return nodes;
|
|
1547
1537
|
}
|
|
1538
|
+
|
|
1539
|
+
/**
|
|
1540
|
+
* Returns a non-empty list of parse nodes, determined by the parseFn.
|
|
1541
|
+
* This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
|
|
1542
|
+
* Advances the parser to the next lex token after last item in the list.
|
|
1543
|
+
*/
|
|
1544
|
+
delimitedMany<T>(delimiterKind: TokenKindEnum, parseFn: () => T): Array<T> {
|
|
1545
|
+
this.expectOptionalToken(delimiterKind);
|
|
1546
|
+
|
|
1547
|
+
const nodes = [];
|
|
1548
|
+
do {
|
|
1549
|
+
nodes.push(parseFn.call(this));
|
|
1550
|
+
} while (this.expectOptionalToken(delimiterKind));
|
|
1551
|
+
return nodes;
|
|
1552
|
+
}
|
|
1548
1553
|
}
|
|
1549
1554
|
|
|
1550
1555
|
/**
|
|
1551
|
-
* A helper function to describe a token as a string for debugging
|
|
1556
|
+
* A helper function to describe a token as a string for debugging.
|
|
1552
1557
|
*/
|
|
1553
1558
|
function getTokenDesc(token: Token): string {
|
|
1554
1559
|
const value = token.value;
|
|
@@ -1556,7 +1561,7 @@ function getTokenDesc(token: Token): string {
|
|
|
1556
1561
|
}
|
|
1557
1562
|
|
|
1558
1563
|
/**
|
|
1559
|
-
* A helper function to describe a token kind as a string for debugging
|
|
1564
|
+
* A helper function to describe a token kind as a string for debugging.
|
|
1560
1565
|
*/
|
|
1561
1566
|
function getTokenKindDesc(kind: TokenKindEnum): string {
|
|
1562
1567
|
return isPunctuatorTokenKind(kind) ? `"${kind}"` : kind;
|