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/execution/values.js
CHANGED
|
@@ -9,19 +9,13 @@ exports.getDirectiveValues = getDirectiveValues;
|
|
|
9
9
|
|
|
10
10
|
var _find = _interopRequireDefault(require("../polyfills/find"));
|
|
11
11
|
|
|
12
|
-
var _GraphQLError = require("../error/GraphQLError");
|
|
13
|
-
|
|
14
|
-
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
|
15
|
-
|
|
16
|
-
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
|
17
|
-
|
|
18
12
|
var _keyMap = _interopRequireDefault(require("../jsutils/keyMap"));
|
|
19
13
|
|
|
20
|
-
var
|
|
14
|
+
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
|
21
15
|
|
|
22
|
-
var
|
|
16
|
+
var _printPathArray = _interopRequireDefault(require("../jsutils/printPathArray"));
|
|
23
17
|
|
|
24
|
-
var
|
|
18
|
+
var _GraphQLError = require("../error/GraphQLError");
|
|
25
19
|
|
|
26
20
|
var _kinds = require("../language/kinds");
|
|
27
21
|
|
|
@@ -29,6 +23,12 @@ var _printer = require("../language/printer");
|
|
|
29
23
|
|
|
30
24
|
var _definition = require("../type/definition");
|
|
31
25
|
|
|
26
|
+
var _typeFromAST = require("../utilities/typeFromAST");
|
|
27
|
+
|
|
28
|
+
var _valueFromAST = require("../utilities/valueFromAST");
|
|
29
|
+
|
|
30
|
+
var _coerceInputValue = require("../utilities/coerceInputValue");
|
|
31
|
+
|
|
32
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -40,83 +40,90 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
40
40
|
* exposed to user code. Care should be taken to not pull values from the
|
|
41
41
|
* Object prototype.
|
|
42
42
|
*/
|
|
43
|
-
function getVariableValues(schema, varDefNodes, inputs) {
|
|
43
|
+
function getVariableValues(schema, varDefNodes, inputs, options) {
|
|
44
|
+
var maxErrors = options && options.maxErrors;
|
|
44
45
|
var errors = [];
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
var coerced = coerceVariableValues(schema, varDefNodes, inputs, function (error) {
|
|
49
|
+
if (maxErrors != null && errors.length >= maxErrors) {
|
|
50
|
+
throw new _GraphQLError.GraphQLError('Too many errors processing variables, error limit reached. Execution aborted.');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
errors.push(error);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (errors.length === 0) {
|
|
57
|
+
return {
|
|
58
|
+
coerced: coerced
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
errors.push(error);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
errors: errors
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function coerceVariableValues(schema, varDefNodes, inputs, onError) {
|
|
45
71
|
var coercedValues = {};
|
|
46
72
|
|
|
47
|
-
|
|
48
|
-
var varDefNode = varDefNodes[
|
|
73
|
+
var _loop = function _loop(_i2) {
|
|
74
|
+
var varDefNode = varDefNodes[_i2];
|
|
49
75
|
var varName = varDefNode.variable.name.value;
|
|
50
76
|
var varType = (0, _typeFromAST.typeFromAST)(schema, varDefNode.type);
|
|
51
77
|
|
|
52
78
|
if (!(0, _definition.isInputType)(varType)) {
|
|
53
79
|
// Must use input types for variables. This should be caught during
|
|
54
80
|
// validation, however is checked again here for safety.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// use the default value.
|
|
81
|
+
var varTypeStr = (0, _printer.print)(varDefNode.type);
|
|
82
|
+
onError(new _GraphQLError.GraphQLError("Variable \"$".concat(varName, "\" expected value of type \"").concat(varTypeStr, "\" which cannot be used as an input type."), varDefNode.type));
|
|
83
|
+
return "continue";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!hasOwnProperty(inputs, varName)) {
|
|
87
|
+
if (varDefNode.defaultValue) {
|
|
63
88
|
coercedValues[varName] = (0, _valueFromAST.valueFromAST)(varDefNode.defaultValue, varType);
|
|
64
|
-
} else if ((!hasValue || value === null) && (0, _definition.isNonNullType)(varType)) {
|
|
65
|
-
// If no value or a nullish value was provided to a variable with a
|
|
66
|
-
// non-null type (required), produce an error.
|
|
67
|
-
errors.push(new _GraphQLError.GraphQLError(hasValue ? "Variable \"$".concat(varName, "\" of non-null type ") + "\"".concat((0, _inspect.default)(varType), "\" must not be null.") : "Variable \"$".concat(varName, "\" of required type ") + "\"".concat((0, _inspect.default)(varType), "\" was not provided."), varDefNode));
|
|
68
|
-
} else if (hasValue) {
|
|
69
|
-
if (value === null) {
|
|
70
|
-
// If the explicit value `null` was provided, an entry in the coerced
|
|
71
|
-
// values must exist as the value `null`.
|
|
72
|
-
coercedValues[varName] = null;
|
|
73
|
-
} else {
|
|
74
|
-
// Otherwise, a non-null value was provided, coerce it to the expected
|
|
75
|
-
// type or report an error if coercion fails.
|
|
76
|
-
var coerced = (0, _coerceValue.coerceValue)(value, varType, varDefNode);
|
|
77
|
-
var coercionErrors = coerced.errors;
|
|
78
|
-
|
|
79
|
-
if (coercionErrors) {
|
|
80
|
-
var _iteratorNormalCompletion = true;
|
|
81
|
-
var _didIteratorError = false;
|
|
82
|
-
var _iteratorError = undefined;
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
for (var _iterator = coercionErrors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
86
|
-
var error = _step.value;
|
|
87
|
-
error.message = "Variable \"$".concat(varName, "\" got invalid value ").concat((0, _inspect.default)(value), "; ") + error.message;
|
|
88
|
-
}
|
|
89
|
-
} catch (err) {
|
|
90
|
-
_didIteratorError = true;
|
|
91
|
-
_iteratorError = err;
|
|
92
|
-
} finally {
|
|
93
|
-
try {
|
|
94
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
95
|
-
_iterator.return();
|
|
96
|
-
}
|
|
97
|
-
} finally {
|
|
98
|
-
if (_didIteratorError) {
|
|
99
|
-
throw _iteratorError;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
errors.push.apply(errors, coercionErrors);
|
|
105
|
-
} else {
|
|
106
|
-
coercedValues[varName] = coerced.value;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
89
|
}
|
|
90
|
+
|
|
91
|
+
if ((0, _definition.isNonNullType)(varType)) {
|
|
92
|
+
var _varTypeStr = (0, _inspect.default)(varType);
|
|
93
|
+
|
|
94
|
+
onError(new _GraphQLError.GraphQLError("Variable \"$".concat(varName, "\" of required type \"").concat(_varTypeStr, "\" was not provided."), varDefNode));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return "continue";
|
|
110
98
|
}
|
|
111
|
-
}
|
|
112
99
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
100
|
+
var value = inputs[varName];
|
|
101
|
+
|
|
102
|
+
if (value === null && (0, _definition.isNonNullType)(varType)) {
|
|
103
|
+
var _varTypeStr2 = (0, _inspect.default)(varType);
|
|
104
|
+
|
|
105
|
+
onError(new _GraphQLError.GraphQLError("Variable \"$".concat(varName, "\" of non-null type \"").concat(_varTypeStr2, "\" must not be null."), varDefNode));
|
|
106
|
+
return "continue";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
coercedValues[varName] = (0, _coerceInputValue.coerceInputValue)(value, varType, function (path, invalidValue, error) {
|
|
110
|
+
var prefix = "Variable \"$".concat(varName, "\" got invalid value ") + (0, _inspect.default)(invalidValue);
|
|
111
|
+
|
|
112
|
+
if (path.length > 0) {
|
|
113
|
+
prefix += " at \"".concat(varName).concat((0, _printPathArray.default)(path), "\"");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
onError(new _GraphQLError.GraphQLError(prefix + '; ' + error.message, varDefNode, undefined, undefined, undefined, error.originalError));
|
|
117
|
+
});
|
|
119
118
|
};
|
|
119
|
+
|
|
120
|
+
for (var _i2 = 0; _i2 < varDefNodes.length; _i2++) {
|
|
121
|
+
var _ret = _loop(_i2);
|
|
122
|
+
|
|
123
|
+
if (_ret === "continue") continue;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return coercedValues;
|
|
120
127
|
}
|
|
121
128
|
/**
|
|
122
129
|
* Prepares an object map of argument values given a list of argument
|
|
@@ -130,75 +137,59 @@ function getVariableValues(schema, varDefNodes, inputs) {
|
|
|
130
137
|
|
|
131
138
|
function getArgumentValues(def, node, variableValues) {
|
|
132
139
|
var coercedValues = {};
|
|
133
|
-
var
|
|
134
|
-
var argNodes = node.arguments;
|
|
135
|
-
|
|
136
|
-
if (!argDefs || !argNodes) {
|
|
137
|
-
return coercedValues;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
var argNodeMap = (0, _keyMap.default)(argNodes, function (arg) {
|
|
140
|
+
var argNodeMap = (0, _keyMap.default)(node.arguments || [], function (arg) {
|
|
141
141
|
return arg.name.value;
|
|
142
142
|
});
|
|
143
143
|
|
|
144
|
-
for (var
|
|
145
|
-
var argDef =
|
|
144
|
+
for (var _i4 = 0, _def$args2 = def.args; _i4 < _def$args2.length; _i4++) {
|
|
145
|
+
var argDef = _def$args2[_i4];
|
|
146
146
|
var name = argDef.name;
|
|
147
147
|
var argType = argDef.type;
|
|
148
148
|
var argumentNode = argNodeMap[name];
|
|
149
|
-
var hasValue = void 0;
|
|
150
|
-
var isNull = void 0;
|
|
151
|
-
|
|
152
|
-
if (argumentNode && argumentNode.value.kind === _kinds.Kind.VARIABLE) {
|
|
153
|
-
var variableName = argumentNode.value.name.value;
|
|
154
|
-
hasValue = variableValues != null && hasOwnProperty(variableValues, variableName);
|
|
155
|
-
isNull = variableValues != null && variableValues[variableName] === null;
|
|
156
|
-
} else {
|
|
157
|
-
hasValue = argumentNode != null;
|
|
158
|
-
isNull = argumentNode != null && argumentNode.value.kind === _kinds.Kind.NULL;
|
|
159
|
-
}
|
|
160
149
|
|
|
161
|
-
if (!
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
} else if ((!hasValue || isNull) && (0, _definition.isNonNullType)(argType)) {
|
|
166
|
-
// If no argument or a null value was provided to an argument with a
|
|
167
|
-
// non-null type (required), produce a field error.
|
|
168
|
-
if (isNull) {
|
|
169
|
-
throw new _GraphQLError.GraphQLError("Argument \"".concat(name, "\" of non-null type \"").concat((0, _inspect.default)(argType), "\" ") + 'must not be null.', argumentNode.value);
|
|
170
|
-
} else if (argumentNode && argumentNode.value.kind === _kinds.Kind.VARIABLE) {
|
|
171
|
-
var _variableName = argumentNode.value.name.value;
|
|
172
|
-
throw new _GraphQLError.GraphQLError("Argument \"".concat(name, "\" of required type \"").concat((0, _inspect.default)(argType), "\" ") + "was provided the variable \"$".concat(_variableName, "\" which was not provided a runtime value."), argumentNode.value);
|
|
173
|
-
} else {
|
|
150
|
+
if (!argumentNode) {
|
|
151
|
+
if (argDef.defaultValue !== undefined) {
|
|
152
|
+
coercedValues[name] = argDef.defaultValue;
|
|
153
|
+
} else if ((0, _definition.isNonNullType)(argType)) {
|
|
174
154
|
throw new _GraphQLError.GraphQLError("Argument \"".concat(name, "\" of required type \"").concat((0, _inspect.default)(argType), "\" ") + 'was not provided.', node);
|
|
175
155
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (coercedValue === undefined) {
|
|
193
|
-
// Note: ValuesOfCorrectType validation should catch this before
|
|
194
|
-
// execution. This is a runtime check to ensure execution does not
|
|
195
|
-
// continue with an invalid argument value.
|
|
196
|
-
throw new _GraphQLError.GraphQLError("Argument \"".concat(name, "\" has invalid value ").concat((0, _printer.print)(valueNode), "."), argumentNode.value);
|
|
156
|
+
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
var valueNode = argumentNode.value;
|
|
161
|
+
var isNull = valueNode.kind === _kinds.Kind.NULL;
|
|
162
|
+
|
|
163
|
+
if (valueNode.kind === _kinds.Kind.VARIABLE) {
|
|
164
|
+
var variableName = valueNode.name.value;
|
|
165
|
+
|
|
166
|
+
if (variableValues == null || !hasOwnProperty(variableValues, variableName)) {
|
|
167
|
+
if (argDef.defaultValue !== undefined) {
|
|
168
|
+
coercedValues[name] = argDef.defaultValue;
|
|
169
|
+
} else if ((0, _definition.isNonNullType)(argType)) {
|
|
170
|
+
throw new _GraphQLError.GraphQLError("Argument \"".concat(name, "\" of required type \"").concat((0, _inspect.default)(argType), "\" ") + "was provided the variable \"$".concat(variableName, "\" which was not provided a runtime value."), valueNode);
|
|
197
171
|
}
|
|
198
172
|
|
|
199
|
-
|
|
173
|
+
continue;
|
|
200
174
|
}
|
|
175
|
+
|
|
176
|
+
isNull = variableValues[variableName] == null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (isNull && (0, _definition.isNonNullType)(argType)) {
|
|
180
|
+
throw new _GraphQLError.GraphQLError("Argument \"".concat(name, "\" of non-null type \"").concat((0, _inspect.default)(argType), "\" ") + 'must not be null.', valueNode);
|
|
201
181
|
}
|
|
182
|
+
|
|
183
|
+
var coercedValue = (0, _valueFromAST.valueFromAST)(valueNode, argType, variableValues);
|
|
184
|
+
|
|
185
|
+
if (coercedValue === undefined) {
|
|
186
|
+
// Note: ValuesOfCorrectType validation should catch this before
|
|
187
|
+
// execution. This is a runtime check to ensure execution does not
|
|
188
|
+
// continue with an invalid argument value.
|
|
189
|
+
throw new _GraphQLError.GraphQLError("Argument \"".concat(name, "\" has invalid value ").concat((0, _printer.print)(valueNode), "."), valueNode);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
coercedValues[name] = coercedValue;
|
|
202
193
|
}
|
|
203
194
|
|
|
204
195
|
return coercedValues;
|
package/execution/values.js.flow
CHANGED
|
@@ -1,33 +1,37 @@
|
|
|
1
1
|
// @flow strict
|
|
2
2
|
|
|
3
3
|
import find from '../polyfills/find';
|
|
4
|
-
|
|
5
|
-
import inspect from '../jsutils/inspect';
|
|
6
|
-
import invariant from '../jsutils/invariant';
|
|
4
|
+
|
|
7
5
|
import keyMap from '../jsutils/keyMap';
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
6
|
+
import inspect from '../jsutils/inspect';
|
|
7
|
+
import { type ObjMap } from '../jsutils/ObjMap';
|
|
8
|
+
import printPathArray from '../jsutils/printPathArray';
|
|
9
|
+
|
|
10
|
+
import { GraphQLError } from '../error/GraphQLError';
|
|
11
|
+
|
|
11
12
|
import { Kind } from '../language/kinds';
|
|
12
13
|
import { print } from '../language/printer';
|
|
13
|
-
import {
|
|
14
|
-
type GraphQLField,
|
|
15
|
-
isInputType,
|
|
16
|
-
isNonNullType,
|
|
17
|
-
} from '../type/definition';
|
|
18
|
-
import { type GraphQLDirective } from '../type/directives';
|
|
19
|
-
import { type ObjMap } from '../jsutils/ObjMap';
|
|
20
|
-
import { type GraphQLSchema } from '../type/schema';
|
|
21
14
|
import {
|
|
22
15
|
type FieldNode,
|
|
23
16
|
type DirectiveNode,
|
|
24
17
|
type VariableDefinitionNode,
|
|
25
18
|
} from '../language/ast';
|
|
26
19
|
|
|
27
|
-
type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
import { type GraphQLSchema } from '../type/schema';
|
|
21
|
+
import { type GraphQLDirective } from '../type/directives';
|
|
22
|
+
import {
|
|
23
|
+
type GraphQLField,
|
|
24
|
+
isInputType,
|
|
25
|
+
isNonNullType,
|
|
26
|
+
} from '../type/definition';
|
|
27
|
+
|
|
28
|
+
import { typeFromAST } from '../utilities/typeFromAST';
|
|
29
|
+
import { valueFromAST } from '../utilities/valueFromAST';
|
|
30
|
+
import { coerceInputValue } from '../utilities/coerceInputValue';
|
|
31
|
+
|
|
32
|
+
type CoercedVariableValues =
|
|
33
|
+
| {| errors: $ReadOnlyArray<GraphQLError> |}
|
|
34
|
+
| {| coerced: { [variable: string]: mixed, ... } |};
|
|
31
35
|
|
|
32
36
|
/**
|
|
33
37
|
* Prepares an object map of variableValues of the correct type based on the
|
|
@@ -42,72 +46,106 @@ export function getVariableValues(
|
|
|
42
46
|
schema: GraphQLSchema,
|
|
43
47
|
varDefNodes: $ReadOnlyArray<VariableDefinitionNode>,
|
|
44
48
|
inputs: { +[variable: string]: mixed, ... },
|
|
49
|
+
options?: {| maxErrors?: number |},
|
|
45
50
|
): CoercedVariableValues {
|
|
51
|
+
const maxErrors = options && options.maxErrors;
|
|
46
52
|
const errors = [];
|
|
53
|
+
try {
|
|
54
|
+
const coerced = coerceVariableValues(schema, varDefNodes, inputs, error => {
|
|
55
|
+
if (maxErrors != null && errors.length >= maxErrors) {
|
|
56
|
+
throw new GraphQLError(
|
|
57
|
+
'Too many errors processing variables, error limit reached. Execution aborted.',
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
errors.push(error);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (errors.length === 0) {
|
|
64
|
+
return { coerced };
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
errors.push(error);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return { errors };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function coerceVariableValues(
|
|
74
|
+
schema: GraphQLSchema,
|
|
75
|
+
varDefNodes: $ReadOnlyArray<VariableDefinitionNode>,
|
|
76
|
+
inputs: { +[variable: string]: mixed, ... },
|
|
77
|
+
onError: GraphQLError => void,
|
|
78
|
+
): { [variable: string]: mixed, ... } {
|
|
47
79
|
const coercedValues = {};
|
|
48
|
-
for (
|
|
49
|
-
const varDefNode = varDefNodes[i];
|
|
80
|
+
for (const varDefNode of varDefNodes) {
|
|
50
81
|
const varName = varDefNode.variable.name.value;
|
|
51
82
|
const varType = typeFromAST(schema, varDefNode.type);
|
|
52
83
|
if (!isInputType(varType)) {
|
|
53
84
|
// Must use input types for variables. This should be caught during
|
|
54
85
|
// validation, however is checked again here for safety.
|
|
55
|
-
|
|
86
|
+
const varTypeStr = print(varDefNode.type);
|
|
87
|
+
onError(
|
|
56
88
|
new GraphQLError(
|
|
57
|
-
`Variable "$${varName}" expected value of type
|
|
58
|
-
`"${print(
|
|
59
|
-
varDefNode.type,
|
|
60
|
-
)}" which cannot be used as an input type.`,
|
|
89
|
+
`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`,
|
|
61
90
|
varDefNode.type,
|
|
62
91
|
),
|
|
63
92
|
);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// use the default value.
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!hasOwnProperty(inputs, varName)) {
|
|
97
|
+
if (varDefNode.defaultValue) {
|
|
70
98
|
coercedValues[varName] = valueFromAST(varDefNode.defaultValue, varType);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (isNonNullType(varType)) {
|
|
102
|
+
const varTypeStr = inspect(varType);
|
|
103
|
+
onError(
|
|
75
104
|
new GraphQLError(
|
|
76
|
-
|
|
77
|
-
? `Variable "$${varName}" of non-null type ` +
|
|
78
|
-
`"${inspect(varType)}" must not be null.`
|
|
79
|
-
: `Variable "$${varName}" of required type ` +
|
|
80
|
-
`"${inspect(varType)}" was not provided.`,
|
|
105
|
+
`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`,
|
|
81
106
|
varDefNode,
|
|
82
107
|
),
|
|
83
108
|
);
|
|
84
|
-
} else if (hasValue) {
|
|
85
|
-
if (value === null) {
|
|
86
|
-
// If the explicit value `null` was provided, an entry in the coerced
|
|
87
|
-
// values must exist as the value `null`.
|
|
88
|
-
coercedValues[varName] = null;
|
|
89
|
-
} else {
|
|
90
|
-
// Otherwise, a non-null value was provided, coerce it to the expected
|
|
91
|
-
// type or report an error if coercion fails.
|
|
92
|
-
const coerced = coerceValue(value, varType, varDefNode);
|
|
93
|
-
const coercionErrors = coerced.errors;
|
|
94
|
-
if (coercionErrors) {
|
|
95
|
-
for (const error of coercionErrors) {
|
|
96
|
-
error.message =
|
|
97
|
-
`Variable "$${varName}" got invalid value ${inspect(value)}; ` +
|
|
98
|
-
error.message;
|
|
99
|
-
}
|
|
100
|
-
errors.push(...coercionErrors);
|
|
101
|
-
} else {
|
|
102
|
-
coercedValues[varName] = coerced.value;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
109
|
}
|
|
110
|
+
continue;
|
|
106
111
|
}
|
|
112
|
+
|
|
113
|
+
const value = inputs[varName];
|
|
114
|
+
if (value === null && isNonNullType(varType)) {
|
|
115
|
+
const varTypeStr = inspect(varType);
|
|
116
|
+
onError(
|
|
117
|
+
new GraphQLError(
|
|
118
|
+
`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`,
|
|
119
|
+
varDefNode,
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
coercedValues[varName] = coerceInputValue(
|
|
126
|
+
value,
|
|
127
|
+
varType,
|
|
128
|
+
(path, invalidValue, error) => {
|
|
129
|
+
let prefix =
|
|
130
|
+
`Variable "$${varName}" got invalid value ` + inspect(invalidValue);
|
|
131
|
+
if (path.length > 0) {
|
|
132
|
+
prefix += ` at "${varName}${printPathArray(path)}"`;
|
|
133
|
+
}
|
|
134
|
+
onError(
|
|
135
|
+
new GraphQLError(
|
|
136
|
+
prefix + '; ' + error.message,
|
|
137
|
+
varDefNode,
|
|
138
|
+
undefined,
|
|
139
|
+
undefined,
|
|
140
|
+
undefined,
|
|
141
|
+
error.originalError,
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
},
|
|
145
|
+
);
|
|
107
146
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
: { errors, coerced: undefined };
|
|
147
|
+
|
|
148
|
+
return coercedValues;
|
|
111
149
|
}
|
|
112
150
|
|
|
113
151
|
/**
|
|
@@ -119,88 +157,73 @@ export function getVariableValues(
|
|
|
119
157
|
* Object prototype.
|
|
120
158
|
*/
|
|
121
159
|
export function getArgumentValues(
|
|
122
|
-
def: GraphQLField
|
|
160
|
+
def: GraphQLField<mixed, mixed> | GraphQLDirective,
|
|
123
161
|
node: FieldNode | DirectiveNode,
|
|
124
162
|
variableValues?: ?ObjMap<mixed>,
|
|
125
163
|
): { [argument: string]: mixed, ... } {
|
|
126
164
|
const coercedValues = {};
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return coercedValues;
|
|
131
|
-
}
|
|
132
|
-
const argNodeMap = keyMap(argNodes, arg => arg.name.value);
|
|
133
|
-
for (let i = 0; i < argDefs.length; i++) {
|
|
134
|
-
const argDef = argDefs[i];
|
|
165
|
+
const argNodeMap = keyMap(node.arguments || [], arg => arg.name.value);
|
|
166
|
+
|
|
167
|
+
for (const argDef of def.args) {
|
|
135
168
|
const name = argDef.name;
|
|
136
169
|
const argType = argDef.type;
|
|
137
170
|
const argumentNode = argNodeMap[name];
|
|
138
|
-
let hasValue;
|
|
139
|
-
let isNull;
|
|
140
|
-
if (argumentNode && argumentNode.value.kind === Kind.VARIABLE) {
|
|
141
|
-
const variableName = argumentNode.value.name.value;
|
|
142
|
-
hasValue =
|
|
143
|
-
variableValues != null && hasOwnProperty(variableValues, variableName);
|
|
144
|
-
isNull = variableValues != null && variableValues[variableName] === null;
|
|
145
|
-
} else {
|
|
146
|
-
hasValue = argumentNode != null;
|
|
147
|
-
isNull = argumentNode != null && argumentNode.value.kind === Kind.NULL;
|
|
148
|
-
}
|
|
149
171
|
|
|
150
|
-
if (!
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
} else if ((!hasValue || isNull) && isNonNullType(argType)) {
|
|
155
|
-
// If no argument or a null value was provided to an argument with a
|
|
156
|
-
// non-null type (required), produce a field error.
|
|
157
|
-
if (isNull) {
|
|
158
|
-
throw new GraphQLError(
|
|
159
|
-
`Argument "${name}" of non-null type "${inspect(argType)}" ` +
|
|
160
|
-
'must not be null.',
|
|
161
|
-
argumentNode.value,
|
|
162
|
-
);
|
|
163
|
-
} else if (argumentNode && argumentNode.value.kind === Kind.VARIABLE) {
|
|
164
|
-
const variableName = argumentNode.value.name.value;
|
|
165
|
-
throw new GraphQLError(
|
|
166
|
-
`Argument "${name}" of required type "${inspect(argType)}" ` +
|
|
167
|
-
`was provided the variable "$${variableName}" which was not provided a runtime value.`,
|
|
168
|
-
argumentNode.value,
|
|
169
|
-
);
|
|
170
|
-
} else {
|
|
172
|
+
if (!argumentNode) {
|
|
173
|
+
if (argDef.defaultValue !== undefined) {
|
|
174
|
+
coercedValues[name] = argDef.defaultValue;
|
|
175
|
+
} else if (isNonNullType(argType)) {
|
|
171
176
|
throw new GraphQLError(
|
|
172
177
|
`Argument "${name}" of required type "${inspect(argType)}" ` +
|
|
173
178
|
'was not provided.',
|
|
174
179
|
node,
|
|
175
180
|
);
|
|
176
181
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (coercedValue === undefined) {
|
|
193
|
-
// Note: ValuesOfCorrectType validation should catch this before
|
|
194
|
-
// execution. This is a runtime check to ensure execution does not
|
|
195
|
-
// continue with an invalid argument value.
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const valueNode = argumentNode.value;
|
|
186
|
+
let isNull = valueNode.kind === Kind.NULL;
|
|
187
|
+
|
|
188
|
+
if (valueNode.kind === Kind.VARIABLE) {
|
|
189
|
+
const variableName = valueNode.name.value;
|
|
190
|
+
if (
|
|
191
|
+
variableValues == null ||
|
|
192
|
+
!hasOwnProperty(variableValues, variableName)
|
|
193
|
+
) {
|
|
194
|
+
if (argDef.defaultValue !== undefined) {
|
|
195
|
+
coercedValues[name] = argDef.defaultValue;
|
|
196
|
+
} else if (isNonNullType(argType)) {
|
|
196
197
|
throw new GraphQLError(
|
|
197
|
-
`Argument "${name}"
|
|
198
|
-
|
|
198
|
+
`Argument "${name}" of required type "${inspect(argType)}" ` +
|
|
199
|
+
`was provided the variable "$${variableName}" which was not provided a runtime value.`,
|
|
200
|
+
valueNode,
|
|
199
201
|
);
|
|
200
202
|
}
|
|
201
|
-
|
|
203
|
+
continue;
|
|
202
204
|
}
|
|
205
|
+
isNull = variableValues[variableName] == null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (isNull && isNonNullType(argType)) {
|
|
209
|
+
throw new GraphQLError(
|
|
210
|
+
`Argument "${name}" of non-null type "${inspect(argType)}" ` +
|
|
211
|
+
'must not be null.',
|
|
212
|
+
valueNode,
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const coercedValue = valueFromAST(valueNode, argType, variableValues);
|
|
217
|
+
if (coercedValue === undefined) {
|
|
218
|
+
// Note: ValuesOfCorrectType validation should catch this before
|
|
219
|
+
// execution. This is a runtime check to ensure execution does not
|
|
220
|
+
// continue with an invalid argument value.
|
|
221
|
+
throw new GraphQLError(
|
|
222
|
+
`Argument "${name}" has invalid value ${print(valueNode)}.`,
|
|
223
|
+
valueNode,
|
|
224
|
+
);
|
|
203
225
|
}
|
|
226
|
+
coercedValues[name] = coercedValue;
|
|
204
227
|
}
|
|
205
228
|
return coercedValues;
|
|
206
229
|
}
|