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.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import find from '../polyfills/find';
|
|
2
|
-
import { GraphQLError } from '../error/GraphQLError';
|
|
3
|
-
import inspect from '../jsutils/inspect';
|
|
4
|
-
import invariant from '../jsutils/invariant';
|
|
5
2
|
import keyMap from '../jsutils/keyMap';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
3
|
+
import inspect from '../jsutils/inspect';
|
|
4
|
+
import printPathArray from '../jsutils/printPathArray';
|
|
5
|
+
import { GraphQLError } from '../error/GraphQLError';
|
|
9
6
|
import { Kind } from '../language/kinds';
|
|
10
7
|
import { print } from '../language/printer';
|
|
11
8
|
import { isInputType, isNonNullType } from '../type/definition';
|
|
9
|
+
import { typeFromAST } from '../utilities/typeFromAST';
|
|
10
|
+
import { valueFromAST } from '../utilities/valueFromAST';
|
|
11
|
+
import { coerceInputValue } from '../utilities/coerceInputValue';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Prepares an object map of variableValues of the correct type based on the
|
|
@@ -19,83 +19,90 @@ import { isInputType, isNonNullType } from '../type/definition';
|
|
|
19
19
|
* exposed to user code. Care should be taken to not pull values from the
|
|
20
20
|
* Object prototype.
|
|
21
21
|
*/
|
|
22
|
-
export function getVariableValues(schema, varDefNodes, inputs) {
|
|
22
|
+
export function getVariableValues(schema, varDefNodes, inputs, options) {
|
|
23
|
+
var maxErrors = options && options.maxErrors;
|
|
23
24
|
var errors = [];
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
var coerced = coerceVariableValues(schema, varDefNodes, inputs, function (error) {
|
|
28
|
+
if (maxErrors != null && errors.length >= maxErrors) {
|
|
29
|
+
throw new GraphQLError('Too many errors processing variables, error limit reached. Execution aborted.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
errors.push(error);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (errors.length === 0) {
|
|
36
|
+
return {
|
|
37
|
+
coerced: coerced
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
} catch (error) {
|
|
41
|
+
errors.push(error);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
errors: errors
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function coerceVariableValues(schema, varDefNodes, inputs, onError) {
|
|
24
50
|
var coercedValues = {};
|
|
25
51
|
|
|
26
|
-
|
|
27
|
-
var varDefNode = varDefNodes[
|
|
52
|
+
var _loop = function _loop(_i2) {
|
|
53
|
+
var varDefNode = varDefNodes[_i2];
|
|
28
54
|
var varName = varDefNode.variable.name.value;
|
|
29
55
|
var varType = typeFromAST(schema, varDefNode.type);
|
|
30
56
|
|
|
31
57
|
if (!isInputType(varType)) {
|
|
32
58
|
// Must use input types for variables. This should be caught during
|
|
33
59
|
// validation, however is checked again here for safety.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// use the default value.
|
|
60
|
+
var varTypeStr = print(varDefNode.type);
|
|
61
|
+
onError(new GraphQLError("Variable \"$".concat(varName, "\" expected value of type \"").concat(varTypeStr, "\" which cannot be used as an input type."), varDefNode.type));
|
|
62
|
+
return "continue";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!hasOwnProperty(inputs, varName)) {
|
|
66
|
+
if (varDefNode.defaultValue) {
|
|
42
67
|
coercedValues[varName] = valueFromAST(varDefNode.defaultValue, varType);
|
|
43
|
-
} else if ((!hasValue || value === null) && isNonNullType(varType)) {
|
|
44
|
-
// If no value or a nullish value was provided to a variable with a
|
|
45
|
-
// non-null type (required), produce an error.
|
|
46
|
-
errors.push(new GraphQLError(hasValue ? "Variable \"$".concat(varName, "\" of non-null type ") + "\"".concat(inspect(varType), "\" must not be null.") : "Variable \"$".concat(varName, "\" of required type ") + "\"".concat(inspect(varType), "\" was not provided."), varDefNode));
|
|
47
|
-
} else if (hasValue) {
|
|
48
|
-
if (value === null) {
|
|
49
|
-
// If the explicit value `null` was provided, an entry in the coerced
|
|
50
|
-
// values must exist as the value `null`.
|
|
51
|
-
coercedValues[varName] = null;
|
|
52
|
-
} else {
|
|
53
|
-
// Otherwise, a non-null value was provided, coerce it to the expected
|
|
54
|
-
// type or report an error if coercion fails.
|
|
55
|
-
var coerced = coerceValue(value, varType, varDefNode);
|
|
56
|
-
var coercionErrors = coerced.errors;
|
|
57
|
-
|
|
58
|
-
if (coercionErrors) {
|
|
59
|
-
var _iteratorNormalCompletion = true;
|
|
60
|
-
var _didIteratorError = false;
|
|
61
|
-
var _iteratorError = undefined;
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
for (var _iterator = coercionErrors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
65
|
-
var error = _step.value;
|
|
66
|
-
error.message = "Variable \"$".concat(varName, "\" got invalid value ").concat(inspect(value), "; ") + error.message;
|
|
67
|
-
}
|
|
68
|
-
} catch (err) {
|
|
69
|
-
_didIteratorError = true;
|
|
70
|
-
_iteratorError = err;
|
|
71
|
-
} finally {
|
|
72
|
-
try {
|
|
73
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
74
|
-
_iterator.return();
|
|
75
|
-
}
|
|
76
|
-
} finally {
|
|
77
|
-
if (_didIteratorError) {
|
|
78
|
-
throw _iteratorError;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
errors.push.apply(errors, coercionErrors);
|
|
84
|
-
} else {
|
|
85
|
-
coercedValues[varName] = coerced.value;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
68
|
}
|
|
69
|
+
|
|
70
|
+
if (isNonNullType(varType)) {
|
|
71
|
+
var _varTypeStr = inspect(varType);
|
|
72
|
+
|
|
73
|
+
onError(new GraphQLError("Variable \"$".concat(varName, "\" of required type \"").concat(_varTypeStr, "\" was not provided."), varDefNode));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return "continue";
|
|
89
77
|
}
|
|
90
|
-
}
|
|
91
78
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
79
|
+
var value = inputs[varName];
|
|
80
|
+
|
|
81
|
+
if (value === null && isNonNullType(varType)) {
|
|
82
|
+
var _varTypeStr2 = inspect(varType);
|
|
83
|
+
|
|
84
|
+
onError(new GraphQLError("Variable \"$".concat(varName, "\" of non-null type \"").concat(_varTypeStr2, "\" must not be null."), varDefNode));
|
|
85
|
+
return "continue";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
coercedValues[varName] = coerceInputValue(value, varType, function (path, invalidValue, error) {
|
|
89
|
+
var prefix = "Variable \"$".concat(varName, "\" got invalid value ") + inspect(invalidValue);
|
|
90
|
+
|
|
91
|
+
if (path.length > 0) {
|
|
92
|
+
prefix += " at \"".concat(varName).concat(printPathArray(path), "\"");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
onError(new GraphQLError(prefix + '; ' + error.message, varDefNode, undefined, undefined, undefined, error.originalError));
|
|
96
|
+
});
|
|
98
97
|
};
|
|
98
|
+
|
|
99
|
+
for (var _i2 = 0; _i2 < varDefNodes.length; _i2++) {
|
|
100
|
+
var _ret = _loop(_i2);
|
|
101
|
+
|
|
102
|
+
if (_ret === "continue") continue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return coercedValues;
|
|
99
106
|
}
|
|
100
107
|
/**
|
|
101
108
|
* Prepares an object map of argument values given a list of argument
|
|
@@ -106,77 +113,62 @@ export function getVariableValues(schema, varDefNodes, inputs) {
|
|
|
106
113
|
* Object prototype.
|
|
107
114
|
*/
|
|
108
115
|
|
|
116
|
+
|
|
109
117
|
export function getArgumentValues(def, node, variableValues) {
|
|
110
118
|
var coercedValues = {};
|
|
111
|
-
var
|
|
112
|
-
var argNodes = node.arguments;
|
|
113
|
-
|
|
114
|
-
if (!argDefs || !argNodes) {
|
|
115
|
-
return coercedValues;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
var argNodeMap = keyMap(argNodes, function (arg) {
|
|
119
|
+
var argNodeMap = keyMap(node.arguments || [], function (arg) {
|
|
119
120
|
return arg.name.value;
|
|
120
121
|
});
|
|
121
122
|
|
|
122
|
-
for (var
|
|
123
|
-
var argDef =
|
|
123
|
+
for (var _i4 = 0, _def$args2 = def.args; _i4 < _def$args2.length; _i4++) {
|
|
124
|
+
var argDef = _def$args2[_i4];
|
|
124
125
|
var name = argDef.name;
|
|
125
126
|
var argType = argDef.type;
|
|
126
127
|
var argumentNode = argNodeMap[name];
|
|
127
|
-
var hasValue = void 0;
|
|
128
|
-
var isNull = void 0;
|
|
129
|
-
|
|
130
|
-
if (argumentNode && argumentNode.value.kind === Kind.VARIABLE) {
|
|
131
|
-
var variableName = argumentNode.value.name.value;
|
|
132
|
-
hasValue = variableValues != null && hasOwnProperty(variableValues, variableName);
|
|
133
|
-
isNull = variableValues != null && variableValues[variableName] === null;
|
|
134
|
-
} else {
|
|
135
|
-
hasValue = argumentNode != null;
|
|
136
|
-
isNull = argumentNode != null && argumentNode.value.kind === Kind.NULL;
|
|
137
|
-
}
|
|
138
128
|
|
|
139
|
-
if (!
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
} else if ((!hasValue || isNull) && isNonNullType(argType)) {
|
|
144
|
-
// If no argument or a null value was provided to an argument with a
|
|
145
|
-
// non-null type (required), produce a field error.
|
|
146
|
-
if (isNull) {
|
|
147
|
-
throw new GraphQLError("Argument \"".concat(name, "\" of non-null type \"").concat(inspect(argType), "\" ") + 'must not be null.', argumentNode.value);
|
|
148
|
-
} else if (argumentNode && argumentNode.value.kind === Kind.VARIABLE) {
|
|
149
|
-
var _variableName = argumentNode.value.name.value;
|
|
150
|
-
throw new GraphQLError("Argument \"".concat(name, "\" of required type \"").concat(inspect(argType), "\" ") + "was provided the variable \"$".concat(_variableName, "\" which was not provided a runtime value."), argumentNode.value);
|
|
151
|
-
} else {
|
|
129
|
+
if (!argumentNode) {
|
|
130
|
+
if (argDef.defaultValue !== undefined) {
|
|
131
|
+
coercedValues[name] = argDef.defaultValue;
|
|
132
|
+
} else if (isNonNullType(argType)) {
|
|
152
133
|
throw new GraphQLError("Argument \"".concat(name, "\" of required type \"").concat(inspect(argType), "\" ") + 'was not provided.', node);
|
|
153
134
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (coercedValue === undefined) {
|
|
171
|
-
// Note: ValuesOfCorrectType validation should catch this before
|
|
172
|
-
// execution. This is a runtime check to ensure execution does not
|
|
173
|
-
// continue with an invalid argument value.
|
|
174
|
-
throw new GraphQLError("Argument \"".concat(name, "\" has invalid value ").concat(print(valueNode), "."), argumentNode.value);
|
|
135
|
+
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
var valueNode = argumentNode.value;
|
|
140
|
+
var isNull = valueNode.kind === Kind.NULL;
|
|
141
|
+
|
|
142
|
+
if (valueNode.kind === Kind.VARIABLE) {
|
|
143
|
+
var variableName = valueNode.name.value;
|
|
144
|
+
|
|
145
|
+
if (variableValues == null || !hasOwnProperty(variableValues, variableName)) {
|
|
146
|
+
if (argDef.defaultValue !== undefined) {
|
|
147
|
+
coercedValues[name] = argDef.defaultValue;
|
|
148
|
+
} else if (isNonNullType(argType)) {
|
|
149
|
+
throw new GraphQLError("Argument \"".concat(name, "\" of required type \"").concat(inspect(argType), "\" ") + "was provided the variable \"$".concat(variableName, "\" which was not provided a runtime value."), valueNode);
|
|
175
150
|
}
|
|
176
151
|
|
|
177
|
-
|
|
152
|
+
continue;
|
|
178
153
|
}
|
|
154
|
+
|
|
155
|
+
isNull = variableValues[variableName] == null;
|
|
179
156
|
}
|
|
157
|
+
|
|
158
|
+
if (isNull && isNonNullType(argType)) {
|
|
159
|
+
throw new GraphQLError("Argument \"".concat(name, "\" of non-null type \"").concat(inspect(argType), "\" ") + 'must not be null.', valueNode);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
var coercedValue = valueFromAST(valueNode, argType, variableValues);
|
|
163
|
+
|
|
164
|
+
if (coercedValue === undefined) {
|
|
165
|
+
// Note: ValuesOfCorrectType validation should catch this before
|
|
166
|
+
// execution. This is a runtime check to ensure execution does not
|
|
167
|
+
// continue with an invalid argument value.
|
|
168
|
+
throw new GraphQLError("Argument \"".concat(name, "\" has invalid value ").concat(print(valueNode), "."), valueNode);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
coercedValues[name] = coercedValue;
|
|
180
172
|
}
|
|
181
173
|
|
|
182
174
|
return coercedValues;
|
package/graphql.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import Maybe from './tsutils/Maybe';
|
|
2
|
+
import { Source } from './language/source';
|
|
3
|
+
import { GraphQLSchema } from './type/schema';
|
|
4
|
+
import { GraphQLFieldResolver, GraphQLTypeResolver } from './type/definition';
|
|
5
|
+
import {
|
|
6
|
+
ExecutionResult,
|
|
7
|
+
ExecutionResultDataDefault,
|
|
8
|
+
} from './execution/execute';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This is the primary entry point function for fulfilling GraphQL operations
|
|
12
|
+
* by parsing, validating, and executing a GraphQL document along side a
|
|
13
|
+
* GraphQL schema.
|
|
14
|
+
*
|
|
15
|
+
* More sophisticated GraphQL servers, such as those which persist queries,
|
|
16
|
+
* may wish to separate the validation and execution phases to a static time
|
|
17
|
+
* tooling step, and a server runtime step.
|
|
18
|
+
*
|
|
19
|
+
* Accepts either an object with named arguments, or individual arguments:
|
|
20
|
+
*
|
|
21
|
+
* schema:
|
|
22
|
+
* The GraphQL type system to use when validating and executing a query.
|
|
23
|
+
* source:
|
|
24
|
+
* A GraphQL language formatted string representing the requested operation.
|
|
25
|
+
* rootValue:
|
|
26
|
+
* The value provided as the first argument to resolver functions on the top
|
|
27
|
+
* level type (e.g. the query object type).
|
|
28
|
+
* contextValue:
|
|
29
|
+
* The context value is provided as an argument to resolver functions after
|
|
30
|
+
* field arguments. It is used to pass shared information useful at any point
|
|
31
|
+
* during executing this query, for example the currently logged in user and
|
|
32
|
+
* connections to databases or other services.
|
|
33
|
+
* variableValues:
|
|
34
|
+
* A mapping of variable name to runtime value to use for all variables
|
|
35
|
+
* defined in the requestString.
|
|
36
|
+
* operationName:
|
|
37
|
+
* The name of the operation to use if requestString contains multiple
|
|
38
|
+
* possible operations. Can be omitted if requestString contains only
|
|
39
|
+
* one operation.
|
|
40
|
+
* fieldResolver:
|
|
41
|
+
* A resolver function to use when one is not provided by the schema.
|
|
42
|
+
* If not provided, the default field resolver is used (which looks for a
|
|
43
|
+
* value or method on the source value with the field's name).
|
|
44
|
+
*/
|
|
45
|
+
export interface GraphQLArgs {
|
|
46
|
+
schema: GraphQLSchema;
|
|
47
|
+
source: string | Source;
|
|
48
|
+
rootValue?: any;
|
|
49
|
+
contextValue?: any;
|
|
50
|
+
variableValues?: Maybe<{ [key: string]: any }>;
|
|
51
|
+
operationName?: Maybe<string>;
|
|
52
|
+
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
|
|
53
|
+
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function graphql<TData = ExecutionResultDataDefault>(
|
|
57
|
+
args: GraphQLArgs,
|
|
58
|
+
): Promise<ExecutionResult<TData>>;
|
|
59
|
+
export function graphql<TData = ExecutionResultDataDefault>(
|
|
60
|
+
schema: GraphQLSchema,
|
|
61
|
+
source: Source | string,
|
|
62
|
+
rootValue?: any,
|
|
63
|
+
contextValue?: any,
|
|
64
|
+
variableValues?: Maybe<{ [key: string]: any }>,
|
|
65
|
+
operationName?: Maybe<string>,
|
|
66
|
+
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
|
|
67
|
+
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
|
|
68
|
+
): Promise<ExecutionResult<TData>>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The graphqlSync function also fulfills GraphQL operations by parsing,
|
|
72
|
+
* validating, and executing a GraphQL document along side a GraphQL schema.
|
|
73
|
+
* However, it guarantees to complete synchronously (or throw an error) assuming
|
|
74
|
+
* that all field resolvers are also synchronous.
|
|
75
|
+
*/
|
|
76
|
+
export function graphqlSync<TData = ExecutionResultDataDefault>(
|
|
77
|
+
args: GraphQLArgs,
|
|
78
|
+
): ExecutionResult<TData>;
|
|
79
|
+
export function graphqlSync<TData = ExecutionResultDataDefault>(
|
|
80
|
+
schema: GraphQLSchema,
|
|
81
|
+
source: Source | string,
|
|
82
|
+
rootValue?: any,
|
|
83
|
+
contextValue?: any,
|
|
84
|
+
variableValues?: Maybe<{ [key: string]: any }>,
|
|
85
|
+
operationName?: Maybe<string>,
|
|
86
|
+
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
|
|
87
|
+
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
|
|
88
|
+
): ExecutionResult<TData>;
|
package/graphql.js
CHANGED
|
@@ -8,11 +8,11 @@ exports.graphqlSync = graphqlSync;
|
|
|
8
8
|
|
|
9
9
|
var _isPromise = _interopRequireDefault(require("./jsutils/isPromise"));
|
|
10
10
|
|
|
11
|
-
var _validate = require("./type/validate");
|
|
12
|
-
|
|
13
11
|
var _parser = require("./language/parser");
|
|
14
12
|
|
|
15
|
-
var
|
|
13
|
+
var _validate = require("./validation/validate");
|
|
14
|
+
|
|
15
|
+
var _validate2 = require("./type/validate");
|
|
16
16
|
|
|
17
17
|
var _execute = require("./execution/execute");
|
|
18
18
|
|
|
@@ -76,7 +76,7 @@ function graphqlImpl(args) {
|
|
|
76
76
|
fieldResolver = args.fieldResolver,
|
|
77
77
|
typeResolver = args.typeResolver; // Validate Schema
|
|
78
78
|
|
|
79
|
-
var schemaValidationErrors = (0,
|
|
79
|
+
var schemaValidationErrors = (0, _validate2.validateSchema)(schema);
|
|
80
80
|
|
|
81
81
|
if (schemaValidationErrors.length > 0) {
|
|
82
82
|
return {
|
|
@@ -96,7 +96,7 @@ function graphqlImpl(args) {
|
|
|
96
96
|
} // Validate
|
|
97
97
|
|
|
98
98
|
|
|
99
|
-
var validationErrors = (0,
|
|
99
|
+
var validationErrors = (0, _validate.validate)(schema, document);
|
|
100
100
|
|
|
101
101
|
if (validationErrors.length > 0) {
|
|
102
102
|
return {
|
package/graphql.js.flow
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
// @flow strict
|
|
2
2
|
|
|
3
3
|
import isPromise from './jsutils/isPromise';
|
|
4
|
-
import {
|
|
4
|
+
import { type PromiseOrValue } from './jsutils/PromiseOrValue';
|
|
5
|
+
|
|
5
6
|
import { parse } from './language/parser';
|
|
6
|
-
import { validate } from './validation/validate';
|
|
7
|
-
import { type ExecutionResult, execute } from './execution/execute';
|
|
8
7
|
import { type Source } from './language/source';
|
|
8
|
+
|
|
9
|
+
import { validate } from './validation/validate';
|
|
10
|
+
|
|
11
|
+
import { validateSchema } from './type/validate';
|
|
12
|
+
import { type GraphQLSchema } from './type/schema';
|
|
9
13
|
import {
|
|
10
14
|
type GraphQLFieldResolver,
|
|
11
15
|
type GraphQLTypeResolver,
|
|
12
16
|
} from './type/definition';
|
|
13
|
-
|
|
14
|
-
import { type
|
|
17
|
+
|
|
18
|
+
import { type ExecutionResult, execute } from './execution/execute';
|
|
15
19
|
|
|
16
20
|
/**
|
|
17
21
|
* This is the primary entry point function for fulfilling GraphQL operations
|
package/graphql.mjs
CHANGED
|
@@ -1,8 +1,48 @@
|
|
|
1
1
|
import isPromise from './jsutils/isPromise';
|
|
2
|
-
import { validateSchema } from './type/validate';
|
|
3
2
|
import { parse } from './language/parser';
|
|
4
3
|
import { validate } from './validation/validate';
|
|
4
|
+
import { validateSchema } from './type/validate';
|
|
5
5
|
import { execute } from './execution/execute';
|
|
6
|
+
/**
|
|
7
|
+
* This is the primary entry point function for fulfilling GraphQL operations
|
|
8
|
+
* by parsing, validating, and executing a GraphQL document along side a
|
|
9
|
+
* GraphQL schema.
|
|
10
|
+
*
|
|
11
|
+
* More sophisticated GraphQL servers, such as those which persist queries,
|
|
12
|
+
* may wish to separate the validation and execution phases to a static time
|
|
13
|
+
* tooling step, and a server runtime step.
|
|
14
|
+
*
|
|
15
|
+
* Accepts either an object with named arguments, or individual arguments:
|
|
16
|
+
*
|
|
17
|
+
* schema:
|
|
18
|
+
* The GraphQL type system to use when validating and executing a query.
|
|
19
|
+
* source:
|
|
20
|
+
* A GraphQL language formatted string representing the requested operation.
|
|
21
|
+
* rootValue:
|
|
22
|
+
* The value provided as the first argument to resolver functions on the top
|
|
23
|
+
* level type (e.g. the query object type).
|
|
24
|
+
* contextValue:
|
|
25
|
+
* The context value is provided as an argument to resolver functions after
|
|
26
|
+
* field arguments. It is used to pass shared information useful at any point
|
|
27
|
+
* during executing this query, for example the currently logged in user and
|
|
28
|
+
* connections to databases or other services.
|
|
29
|
+
* variableValues:
|
|
30
|
+
* A mapping of variable name to runtime value to use for all variables
|
|
31
|
+
* defined in the requestString.
|
|
32
|
+
* operationName:
|
|
33
|
+
* The name of the operation to use if requestString contains multiple
|
|
34
|
+
* possible operations. Can be omitted if requestString contains only
|
|
35
|
+
* one operation.
|
|
36
|
+
* fieldResolver:
|
|
37
|
+
* A resolver function to use when one is not provided by the schema.
|
|
38
|
+
* If not provided, the default field resolver is used (which looks for a
|
|
39
|
+
* value or method on the source value with the field's name).
|
|
40
|
+
* typeResolver:
|
|
41
|
+
* A type resolver function to use when none is provided by the schema.
|
|
42
|
+
* If not provided, the default type resolver is used (which looks for a
|
|
43
|
+
* `__typename` field or alternatively calls the `isTypeOf` method).
|
|
44
|
+
*/
|
|
45
|
+
|
|
6
46
|
export function graphql(argsOrSchema, source, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) {
|
|
7
47
|
var _arguments = arguments;
|
|
8
48
|
|