graphql 0.12.3 → 0.13.2
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/error/GraphQLError.js +2 -3
- package/error/GraphQLError.js.flow +3 -4
- package/{module/error/GraphQLError.js → error/GraphQLError.mjs} +2 -3
- package/error/formatError.js +1 -1
- package/error/formatError.js.flow +1 -1
- package/{module/error/formatError.js → error/formatError.mjs} +1 -1
- package/error/index.js.flow +1 -1
- package/{module/error/index.js → error/index.mjs} +1 -1
- package/error/locatedError.js +2 -1
- package/error/locatedError.js.flow +2 -1
- package/{module/error/locatedError.js → error/locatedError.mjs} +2 -1
- package/error/printError.js +1 -1
- package/error/printError.js.flow +1 -1
- package/{module/error/printError.js → error/printError.mjs} +1 -1
- package/error/syntaxError.js +1 -1
- package/error/syntaxError.js.flow +1 -1
- package/{module/error/syntaxError.js → error/syntaxError.mjs} +1 -1
- package/execution/execute.js +70 -90
- package/execution/execute.js.flow +83 -106
- package/{module/execution/execute.js → execution/execute.mjs} +53 -81
- package/execution/index.js.flow +1 -1
- package/{module/execution/index.js → execution/index.mjs} +1 -1
- package/execution/values.js +2 -6
- package/execution/values.js.flow +6 -7
- package/{module/execution/values.js → execution/values.mjs} +2 -2
- package/graphql.js +1 -1
- package/graphql.js.flow +3 -2
- package/{module/graphql.js → graphql.mjs} +1 -1
- package/index.js +24 -6
- package/index.js.flow +16 -2
- package/{module/index.js → index.mjs} +10 -2
- package/jsutils/MaybePromise.js +1 -0
- package/{module/jsutils/ObjMap.js.flow → jsutils/MaybePromise.js.flow} +2 -2
- package/{module/jsutils/ObjMap.js → jsutils/MaybePromise.mjs} +0 -0
- package/jsutils/ObjMap.js.flow +1 -1
- package/{module/language/ast.js → jsutils/ObjMap.mjs} +0 -0
- package/jsutils/dedent.js +23 -18
- package/jsutils/dedent.js.flow +21 -20
- package/jsutils/dedent.mjs +50 -0
- package/jsutils/find.js +1 -1
- package/jsutils/find.js.flow +1 -1
- package/{module/jsutils/find.js → jsutils/find.mjs} +1 -1
- package/jsutils/instanceOf.js +17 -16
- package/jsutils/instanceOf.js.flow +21 -15
- package/jsutils/instanceOf.mjs +31 -0
- package/jsutils/invariant.js +1 -1
- package/jsutils/invariant.js.flow +1 -1
- package/{module/jsutils/invariant.js → jsutils/invariant.mjs} +1 -1
- package/jsutils/isInvalid.js +1 -1
- package/jsutils/isInvalid.js.flow +1 -1
- package/{module/jsutils/isInvalid.js → jsutils/isInvalid.mjs} +1 -1
- package/jsutils/isNullish.js +1 -1
- package/jsutils/isNullish.js.flow +1 -1
- package/{module/jsutils/isNullish.js → jsutils/isNullish.mjs} +1 -1
- package/jsutils/isPromise.js +24 -0
- package/jsutils/isPromise.js.flow +20 -0
- package/jsutils/isPromise.mjs +18 -0
- package/jsutils/keyMap.js +1 -1
- package/jsutils/keyMap.js.flow +1 -1
- package/{module/jsutils/keyMap.js → jsutils/keyMap.mjs} +1 -1
- package/jsutils/keyValMap.js +1 -1
- package/jsutils/keyValMap.js.flow +1 -1
- package/{module/jsutils/keyValMap.js → jsutils/keyValMap.mjs} +1 -1
- package/jsutils/memoize3.js +48 -0
- package/jsutils/memoize3.js.flow +44 -0
- package/jsutils/memoize3.mjs +42 -0
- package/jsutils/objectValues.js +24 -0
- package/jsutils/objectValues.js.flow +18 -0
- package/jsutils/objectValues.mjs +19 -0
- package/jsutils/orList.js +1 -1
- package/jsutils/orList.js.flow +1 -1
- package/{module/jsutils/orList.js → jsutils/orList.mjs} +1 -1
- package/jsutils/promiseForObject.js +34 -0
- package/jsutils/promiseForObject.js.flow +30 -0
- package/jsutils/promiseForObject.mjs +28 -0
- package/jsutils/promiseReduce.js +34 -0
- package/jsutils/promiseReduce.js.flow +32 -0
- package/jsutils/promiseReduce.mjs +26 -0
- package/jsutils/quotedOrList.js +1 -1
- package/jsutils/quotedOrList.js.flow +1 -1
- package/{module/jsutils/quotedOrList.js → jsutils/quotedOrList.mjs} +1 -1
- package/jsutils/suggestionList.js +1 -1
- package/jsutils/suggestionList.js.flow +1 -1
- package/{module/jsutils/suggestionList.js → jsutils/suggestionList.mjs} +1 -1
- package/language/ast.js.flow +3 -30
- package/language/ast.mjs +0 -0
- package/language/blockStringValue.js +1 -1
- package/language/blockStringValue.js.flow +1 -1
- package/{module/language/blockStringValue.js → language/blockStringValue.mjs} +1 -1
- package/language/directiveLocation.js +3 -3
- package/language/directiveLocation.js.flow +4 -4
- package/{module/language/directiveLocation.js → language/directiveLocation.mjs} +3 -3
- package/language/index.js +10 -10
- package/language/index.js.flow +5 -4
- package/{module/language/index.js → language/index.mjs} +3 -3
- package/language/kinds.js +70 -71
- package/language/kinds.js.flow +71 -71
- package/language/kinds.mjs +79 -0
- package/language/lexer.js +73 -87
- package/language/lexer.js.flow +87 -93
- package/{module/language/lexer.js → language/lexer.mjs} +73 -87
- package/language/location.js +1 -1
- package/language/location.js.flow +1 -1
- package/{module/language/location.js → language/location.mjs} +1 -1
- package/language/parser.js +68 -58
- package/language/parser.js.flow +104 -110
- package/{module/language/parser.js → language/parser.mjs} +69 -59
- package/language/printer.js +52 -55
- package/language/printer.js.flow +74 -120
- package/{module/language/printer.js → language/printer.mjs} +52 -55
- package/language/source.js +1 -1
- package/language/source.js.flow +1 -1
- package/{module/language/source.js → language/source.mjs} +1 -1
- package/language/visitor.js +1 -1
- package/language/visitor.js.flow +1 -1
- package/{module/language/visitor.js → language/visitor.mjs} +1 -1
- package/package.json +4 -9
- package/subscription/asyncIteratorReject.js +1 -1
- package/subscription/asyncIteratorReject.js.flow +1 -1
- package/{module/subscription/asyncIteratorReject.js → subscription/asyncIteratorReject.mjs} +1 -1
- package/subscription/index.js.flow +1 -1
- package/{module/subscription/index.js → subscription/index.mjs} +1 -1
- package/subscription/mapAsyncIterator.js +3 -1
- package/subscription/mapAsyncIterator.js.flow +7 -4
- package/{module/subscription/mapAsyncIterator.js → subscription/mapAsyncIterator.mjs} +4 -1
- package/subscription/subscribe.js +1 -1
- package/subscription/subscribe.js.flow +1 -1
- package/{module/subscription/subscribe.js → subscription/subscribe.mjs} +1 -1
- package/type/definition.js +76 -10
- package/type/definition.js.flow +105 -13
- package/{module/type/definition.js → type/definition.mjs} +72 -4
- package/type/directives.js +4 -4
- package/type/directives.js.flow +3 -3
- package/{module/type/directives.js → type/directives.mjs} +8 -8
- package/type/index.js +2 -5
- package/type/index.js.flow +6 -5
- package/{module/type/index.js → type/index.mjs} +3 -5
- package/type/introspection.js +34 -41
- package/type/introspection.js.flow +7 -10
- package/{module/type/introspection.js → type/introspection.mjs} +6 -15
- package/type/scalars.js +6 -10
- package/type/scalars.js.flow +2 -2
- package/{module/type/scalars.js → type/scalars.mjs} +2 -2
- package/type/schema.js +39 -15
- package/type/schema.js.flow +73 -22
- package/{module/type/schema.js → type/schema.mjs} +37 -16
- package/type/validate.js +33 -30
- package/type/validate.js.flow +40 -37
- package/{module/type/validate.js → type/validate.mjs} +30 -30
- package/utilities/TypeInfo.js +23 -27
- package/utilities/TypeInfo.js.flow +2 -2
- package/{module/utilities/TypeInfo.js → utilities/TypeInfo.mjs} +2 -2
- package/utilities/assertValidName.js +2 -6
- package/utilities/assertValidName.js.flow +2 -10
- package/{module/utilities/assertValidName.js → utilities/assertValidName.mjs} +2 -6
- package/utilities/astFromValue.js +37 -37
- package/utilities/astFromValue.js.flow +36 -44
- package/{module/utilities/astFromValue.js → utilities/astFromValue.mjs} +26 -25
- package/utilities/buildASTSchema.js +65 -82
- package/utilities/buildASTSchema.js.flow +52 -59
- package/{module/utilities/buildASTSchema.js → utilities/buildASTSchema.mjs} +48 -62
- package/utilities/buildClientSchema.js +12 -15
- package/utilities/buildClientSchema.js.flow +7 -11
- package/{module/utilities/buildClientSchema.js → utilities/buildClientSchema.mjs} +4 -5
- package/utilities/coerceValue.js +1 -1
- package/utilities/coerceValue.js.flow +1 -1
- package/{module/utilities/coerceValue.js → utilities/coerceValue.mjs} +1 -1
- package/utilities/concatAST.js +1 -1
- package/utilities/concatAST.js.flow +1 -1
- package/{module/utilities/concatAST.js → utilities/concatAST.mjs} +1 -1
- package/utilities/extendSchema.js +91 -77
- package/utilities/extendSchema.js.flow +93 -68
- package/{module/utilities/extendSchema.js → utilities/extendSchema.mjs} +65 -52
- package/utilities/findBreakingChanges.js +1 -1
- package/utilities/findBreakingChanges.js.flow +1 -1
- package/{module/utilities/findBreakingChanges.js → utilities/findBreakingChanges.mjs} +1 -1
- package/utilities/findDeprecatedUsages.js +1 -1
- package/utilities/findDeprecatedUsages.js.flow +1 -1
- package/{module/utilities/findDeprecatedUsages.js → utilities/findDeprecatedUsages.mjs} +1 -1
- package/utilities/getOperationAST.js +2 -2
- package/utilities/getOperationAST.js.flow +3 -3
- package/{module/utilities/getOperationAST.js → utilities/getOperationAST.mjs} +3 -3
- package/utilities/index.js +30 -0
- package/utilities/index.js.flow +10 -3
- package/{module/utilities/index.js → utilities/index.mjs} +10 -3
- package/utilities/introspectionFromSchema.js +43 -0
- package/utilities/introspectionFromSchema.js.flow +37 -0
- package/utilities/introspectionFromSchema.mjs +31 -0
- package/utilities/introspectionQuery.js +1 -1
- package/utilities/introspectionQuery.js.flow +1 -1
- package/{module/utilities/introspectionQuery.js → utilities/introspectionQuery.mjs} +1 -1
- package/utilities/isValidJSValue.js +1 -1
- package/utilities/isValidJSValue.js.flow +1 -1
- package/{module/utilities/isValidJSValue.js → utilities/isValidJSValue.mjs} +1 -1
- package/utilities/isValidLiteralValue.js +8 -4
- package/utilities/isValidLiteralValue.js.flow +4 -4
- package/{module/utilities/isValidLiteralValue.js → utilities/isValidLiteralValue.mjs} +4 -4
- package/utilities/lexicographicSortSchema.js +243 -0
- package/utilities/lexicographicSortSchema.js.flow +198 -0
- package/utilities/lexicographicSortSchema.mjs +225 -0
- package/utilities/schemaPrinter.js +31 -29
- package/utilities/schemaPrinter.js.flow +28 -15
- package/{module/utilities/schemaPrinter.js → utilities/schemaPrinter.mjs} +21 -20
- package/utilities/separateOperations.js +1 -1
- package/utilities/separateOperations.js.flow +1 -1
- package/{module/utilities/separateOperations.js → utilities/separateOperations.mjs} +1 -1
- package/utilities/typeComparators.js +7 -10
- package/utilities/typeComparators.js.flow +7 -10
- package/{module/utilities/typeComparators.js → utilities/typeComparators.mjs} +7 -10
- package/utilities/typeFromAST.js +7 -11
- package/utilities/typeFromAST.js.flow +3 -3
- package/{module/utilities/typeFromAST.js → utilities/typeFromAST.mjs} +3 -3
- package/utilities/valueFromAST.js +26 -28
- package/utilities/valueFromAST.js.flow +14 -23
- package/{module/utilities/valueFromAST.js → utilities/valueFromAST.mjs} +9 -10
- package/utilities/valueFromASTUntyped.js +17 -22
- package/utilities/valueFromASTUntyped.js.flow +6 -7
- package/{module/utilities/valueFromASTUntyped.js → utilities/valueFromASTUntyped.mjs} +6 -7
- package/validation/ValidationContext.js +184 -0
- package/{module/validation/validate.js.flow → validation/ValidationContext.js.flow} +4 -60
- package/{module/validation/validate.js → validation/ValidationContext.mjs} +15 -57
- package/validation/index.js +12 -7
- package/validation/index.js.flow +6 -2
- package/{module/validation/index.js → validation/index.mjs} +6 -2
- package/validation/rules/ExecutableDefinitions.js +3 -3
- package/validation/rules/ExecutableDefinitions.js.flow +6 -10
- package/{module/validation/rules/ExecutableDefinitions.js → validation/rules/ExecutableDefinitions.mjs} +4 -4
- package/validation/rules/FieldsOnCorrectType.js +1 -1
- package/validation/rules/FieldsOnCorrectType.js.flow +2 -2
- package/{module/validation/rules/FieldsOnCorrectType.js → validation/rules/FieldsOnCorrectType.mjs} +1 -1
- package/validation/rules/FragmentsOnCompositeTypes.js +1 -1
- package/validation/rules/FragmentsOnCompositeTypes.js.flow +2 -2
- package/{module/validation/rules/FragmentsOnCompositeTypes.js → validation/rules/FragmentsOnCompositeTypes.mjs} +1 -1
- package/validation/rules/KnownArgumentNames.js +3 -3
- package/validation/rules/KnownArgumentNames.js.flow +6 -8
- package/{module/validation/rules/KnownArgumentNames.js → validation/rules/KnownArgumentNames.mjs} +4 -4
- package/validation/rules/KnownDirectives.js +23 -27
- package/validation/rules/KnownDirectives.js.flow +3 -3
- package/{module/validation/rules/KnownDirectives.js → validation/rules/KnownDirectives.mjs} +2 -2
- package/validation/rules/KnownFragmentNames.js +1 -1
- package/validation/rules/KnownFragmentNames.js.flow +2 -2
- package/{module/validation/rules/KnownFragmentNames.js → validation/rules/KnownFragmentNames.mjs} +1 -1
- package/validation/rules/KnownTypeNames.js +1 -1
- package/validation/rules/KnownTypeNames.js.flow +2 -2
- package/{module/validation/rules/KnownTypeNames.js → validation/rules/KnownTypeNames.mjs} +1 -1
- package/validation/rules/LoneAnonymousOperation.js +2 -2
- package/validation/rules/LoneAnonymousOperation.js.flow +4 -4
- package/{module/validation/rules/LoneAnonymousOperation.js → validation/rules/LoneAnonymousOperation.mjs} +3 -3
- package/validation/rules/NoFragmentCycles.js +1 -1
- package/validation/rules/NoFragmentCycles.js.flow +2 -2
- package/{module/validation/rules/NoFragmentCycles.js → validation/rules/NoFragmentCycles.mjs} +1 -1
- package/validation/rules/NoUndefinedVariables.js +1 -1
- package/validation/rules/NoUndefinedVariables.js.flow +2 -2
- package/{module/validation/rules/NoUndefinedVariables.js → validation/rules/NoUndefinedVariables.mjs} +1 -1
- package/validation/rules/NoUnusedFragments.js +1 -1
- package/validation/rules/NoUnusedFragments.js.flow +2 -2
- package/{module/validation/rules/NoUnusedFragments.js → validation/rules/NoUnusedFragments.mjs} +1 -1
- package/validation/rules/NoUnusedVariables.js +1 -1
- package/validation/rules/NoUnusedVariables.js.flow +2 -2
- package/{module/validation/rules/NoUnusedVariables.js → validation/rules/NoUnusedVariables.mjs} +1 -1
- package/validation/rules/OverlappingFieldsCanBeMerged.js +4 -8
- package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +3 -3
- package/{module/validation/rules/OverlappingFieldsCanBeMerged.js → validation/rules/OverlappingFieldsCanBeMerged.mjs} +2 -2
- package/validation/rules/PossibleFragmentSpreads.js +1 -1
- package/validation/rules/PossibleFragmentSpreads.js.flow +2 -2
- package/{module/validation/rules/PossibleFragmentSpreads.js → validation/rules/PossibleFragmentSpreads.mjs} +1 -1
- package/validation/rules/ProvidedNonNullArguments.js +1 -1
- package/validation/rules/ProvidedNonNullArguments.js.flow +2 -2
- package/{module/validation/rules/ProvidedNonNullArguments.js → validation/rules/ProvidedNonNullArguments.mjs} +1 -1
- package/validation/rules/ScalarLeafs.js +1 -1
- package/validation/rules/ScalarLeafs.js.flow +2 -2
- package/{module/validation/rules/ScalarLeafs.js → validation/rules/ScalarLeafs.mjs} +1 -1
- package/validation/rules/SingleFieldSubscriptions.js +1 -1
- package/validation/rules/SingleFieldSubscriptions.js.flow +2 -2
- package/{module/validation/rules/SingleFieldSubscriptions.js → validation/rules/SingleFieldSubscriptions.mjs} +1 -1
- package/validation/rules/UniqueArgumentNames.js +1 -1
- package/validation/rules/UniqueArgumentNames.js.flow +2 -2
- package/{module/validation/rules/UniqueArgumentNames.js → validation/rules/UniqueArgumentNames.mjs} +1 -1
- package/validation/rules/UniqueDirectivesPerLocation.js +1 -1
- package/validation/rules/UniqueDirectivesPerLocation.js.flow +2 -2
- package/{module/validation/rules/UniqueDirectivesPerLocation.js → validation/rules/UniqueDirectivesPerLocation.mjs} +1 -1
- package/validation/rules/UniqueFragmentNames.js +1 -1
- package/validation/rules/UniqueFragmentNames.js.flow +2 -2
- package/{module/validation/rules/UniqueFragmentNames.js → validation/rules/UniqueFragmentNames.mjs} +1 -1
- package/validation/rules/UniqueInputFieldNames.js +1 -1
- package/validation/rules/UniqueInputFieldNames.js.flow +2 -2
- package/{module/validation/rules/UniqueInputFieldNames.js → validation/rules/UniqueInputFieldNames.mjs} +1 -1
- package/validation/rules/UniqueOperationNames.js +1 -1
- package/validation/rules/UniqueOperationNames.js.flow +2 -2
- package/{module/validation/rules/UniqueOperationNames.js → validation/rules/UniqueOperationNames.mjs} +1 -1
- package/validation/rules/UniqueVariableNames.js +1 -1
- package/validation/rules/UniqueVariableNames.js.flow +2 -2
- package/{module/validation/rules/UniqueVariableNames.js → validation/rules/UniqueVariableNames.mjs} +1 -1
- package/validation/rules/ValuesOfCorrectType.js +1 -1
- package/validation/rules/ValuesOfCorrectType.js.flow +2 -2
- package/{module/validation/rules/ValuesOfCorrectType.js → validation/rules/ValuesOfCorrectType.mjs} +1 -1
- package/validation/rules/VariablesAreInputTypes.js +1 -1
- package/validation/rules/VariablesAreInputTypes.js.flow +2 -2
- package/{module/validation/rules/VariablesAreInputTypes.js → validation/rules/VariablesAreInputTypes.mjs} +1 -1
- package/validation/rules/VariablesDefaultValueAllowed.js +1 -1
- package/validation/rules/VariablesDefaultValueAllowed.js.flow +2 -2
- package/{module/validation/rules/VariablesDefaultValueAllowed.js → validation/rules/VariablesDefaultValueAllowed.mjs} +1 -1
- package/validation/rules/VariablesInAllowedPosition.js +9 -11
- package/validation/rules/VariablesInAllowedPosition.js.flow +3 -4
- package/{module/validation/rules/VariablesInAllowedPosition.js → validation/rules/VariablesInAllowedPosition.mjs} +2 -3
- package/validation/specifiedRules.js +1 -1
- package/validation/specifiedRules.js.flow +2 -2
- package/{module/validation/specifiedRules.js → validation/specifiedRules.mjs} +1 -1
- package/validation/validate.js +14 -175
- package/validation/validate.js.flow +3 -209
- package/validation/validate.mjs +57 -0
- package/module/error/GraphQLError.js.flow +0 -209
- package/module/error/formatError.js.flow +0 -34
- package/module/error/index.js.flow +0 -16
- package/module/error/locatedError.js.flow +0 -37
- package/module/error/printError.js.flow +0 -82
- package/module/error/syntaxError.js.flow +0 -25
- package/module/execution/execute.js.flow +0 -1375
- package/module/execution/index.js.flow +0 -13
- package/module/execution/values.js.flow +0 -206
- package/module/graphql.js.flow +0 -202
- package/module/index.js.flow +0 -389
- package/module/jsutils/dedent.js +0 -45
- package/module/jsutils/dedent.js.flow +0 -49
- package/module/jsutils/find.js.flow +0 -19
- package/module/jsutils/instanceOf.js +0 -27
- package/module/jsutils/instanceOf.js.flow +0 -44
- package/module/jsutils/invariant.js.flow +0 -15
- package/module/jsutils/isInvalid.js.flow +0 -15
- package/module/jsutils/isNullish.js.flow +0 -15
- package/module/jsutils/keyMap.js.flow +0 -43
- package/module/jsutils/keyValMap.js.flow +0 -38
- package/module/jsutils/orList.js.flow +0 -24
- package/module/jsutils/quotedOrList.js.flow +0 -17
- package/module/jsutils/suggestionList.js.flow +0 -94
- package/module/language/ast.js.flow +0 -594
- package/module/language/blockStringValue.js.flow +0 -64
- package/module/language/directiveLocation.js.flow +0 -39
- package/module/language/index.js.flow +0 -84
- package/module/language/kinds.js +0 -80
- package/module/language/kinds.js.flow +0 -80
- package/module/language/lexer.js.flow +0 -762
- package/module/language/location.js.flow +0 -34
- package/module/language/parser.js.flow +0 -1537
- package/module/language/printer.js.flow +0 -311
- package/module/language/source.js.flow +0 -43
- package/module/language/visitor.js.flow +0 -476
- package/module/subscription/asyncIteratorReject.js.flow +0 -41
- package/module/subscription/index.js.flow +0 -10
- package/module/subscription/mapAsyncIterator.js.flow +0 -78
- package/module/subscription/subscribe.js.flow +0 -288
- package/module/type/definition.js.flow +0 -1225
- package/module/type/directives.js.flow +0 -168
- package/module/type/index.js.flow +0 -156
- package/module/type/introspection.js.flow +0 -482
- package/module/type/scalars.js.flow +0 -158
- package/module/type/schema.js.flow +0 -271
- package/module/type/validate.js.flow +0 -723
- package/module/type/wrappers.js +0 -80
- package/module/type/wrappers.js.flow +0 -91
- package/module/utilities/TypeInfo.js.flow +0 -296
- package/module/utilities/assertValidName.js.flow +0 -56
- package/module/utilities/astFromValue.js.flow +0 -159
- package/module/utilities/buildASTSchema.js.flow +0 -518
- package/module/utilities/buildClientSchema.js.flow +0 -418
- package/module/utilities/coerceValue.js.flow +0 -257
- package/module/utilities/concatAST.js.flow +0 -29
- package/module/utilities/extendSchema.js.flow +0 -374
- package/module/utilities/findBreakingChanges.js.flow +0 -851
- package/module/utilities/findDeprecatedUsages.js.flow +0 -68
- package/module/utilities/getOperationAST.js.flow +0 -40
- package/module/utilities/index.js.flow +0 -111
- package/module/utilities/introspectionQuery.js.flow +0 -271
- package/module/utilities/isValidJSValue.js.flow +0 -22
- package/module/utilities/isValidLiteralValue.js.flow +0 -36
- package/module/utilities/schemaPrinter.js.flow +0 -402
- package/module/utilities/separateOperations.js.flow +0 -100
- package/module/utilities/typeComparators.js.flow +0 -135
- package/module/utilities/typeFromAST.js.flow +0 -56
- package/module/utilities/valueFromAST.js.flow +0 -184
- package/module/utilities/valueFromASTUntyped.js.flow +0 -64
- package/module/validation/index.js.flow +0 -138
- package/module/validation/rules/ExecutableDefinitions.js.flow +0 -52
- package/module/validation/rules/FieldsOnCorrectType.js.flow +0 -144
- package/module/validation/rules/FragmentsOnCompositeTypes.js.flow +0 -74
- package/module/validation/rules/KnownArgumentNames.js.flow +0 -98
- package/module/validation/rules/KnownDirectives.js.flow +0 -116
- package/module/validation/rules/KnownFragmentNames.js.flow +0 -36
- package/module/validation/rules/KnownTypeNames.js.flow +0 -59
- package/module/validation/rules/LoneAnonymousOperation.js.flow +0 -41
- package/module/validation/rules/NoFragmentCycles.js.flow +0 -85
- package/module/validation/rules/NoUndefinedVariables.js.flow +0 -57
- package/module/validation/rules/NoUnusedFragments.js.flow +0 -59
- package/module/validation/rules/NoUnusedVariables.js.flow +0 -62
- package/module/validation/rules/OverlappingFieldsCanBeMerged.js.flow +0 -847
- package/module/validation/rules/PossibleFragmentSpreads.js.flow +0 -94
- package/module/validation/rules/ProvidedNonNullArguments.js.flow +0 -105
- package/module/validation/rules/ScalarLeafs.js.flow +0 -69
- package/module/validation/rules/SingleFieldSubscriptions.js.flow +0 -44
- package/module/validation/rules/UniqueArgumentNames.js.flow +0 -48
- package/module/validation/rules/UniqueDirectivesPerLocation.js.flow +0 -57
- package/module/validation/rules/UniqueFragmentNames.js.flow +0 -42
- package/module/validation/rules/UniqueInputFieldNames.js.flow +0 -53
- package/module/validation/rules/UniqueOperationNames.js.flow +0 -44
- package/module/validation/rules/UniqueVariableNames.js.flow +0 -44
- package/module/validation/rules/ValuesOfCorrectType.js.flow +0 -218
- package/module/validation/rules/VariablesAreInputTypes.js.flow +0 -48
- package/module/validation/rules/VariablesDefaultValueAllowed.js.flow +0 -55
- package/module/validation/rules/VariablesInAllowedPosition.js.flow +0 -83
- package/module/validation/specifiedRules.js.flow +0 -127
- package/type/wrappers.js +0 -89
- package/type/wrappers.js.flow +0 -91
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @flow
|
|
7
|
+
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { forEach, isCollection } from 'iterall';
|
|
@@ -12,10 +12,15 @@ import { GraphQLError, locatedError } from '../error';
|
|
|
12
12
|
import invariant from '../jsutils/invariant';
|
|
13
13
|
import isInvalid from '../jsutils/isInvalid';
|
|
14
14
|
import isNullish from '../jsutils/isNullish';
|
|
15
|
+
import isPromise from '../jsutils/isPromise';
|
|
16
|
+
import memoize3 from '../jsutils/memoize3';
|
|
17
|
+
import promiseForObject from '../jsutils/promiseForObject';
|
|
18
|
+
import promiseReduce from '../jsutils/promiseReduce';
|
|
15
19
|
import type { ObjMap } from '../jsutils/ObjMap';
|
|
20
|
+
import type { MaybePromise } from '../jsutils/MaybePromise';
|
|
16
21
|
|
|
17
22
|
import { typeFromAST } from '../utilities/typeFromAST';
|
|
18
|
-
import
|
|
23
|
+
import { Kind } from '../language/kinds';
|
|
19
24
|
import {
|
|
20
25
|
getVariableValues,
|
|
21
26
|
getArgumentValues,
|
|
@@ -28,7 +33,6 @@ import {
|
|
|
28
33
|
isListType,
|
|
29
34
|
isNonNullType,
|
|
30
35
|
} from '../type/definition';
|
|
31
|
-
import type { GraphQLList } from '../type/wrappers';
|
|
32
36
|
import type {
|
|
33
37
|
GraphQLObjectType,
|
|
34
38
|
GraphQLOutputType,
|
|
@@ -38,6 +42,7 @@ import type {
|
|
|
38
42
|
GraphQLFieldResolver,
|
|
39
43
|
GraphQLResolveInfo,
|
|
40
44
|
ResponsePath,
|
|
45
|
+
GraphQLList,
|
|
41
46
|
} from '../type/definition';
|
|
42
47
|
import { GraphQLSchema } from '../type/schema';
|
|
43
48
|
import {
|
|
@@ -133,7 +138,7 @@ export type ExecutionArgs = {|
|
|
|
133
138
|
declare function execute(
|
|
134
139
|
ExecutionArgs,
|
|
135
140
|
..._: []
|
|
136
|
-
):
|
|
141
|
+
): MaybePromise<ExecutionResult>;
|
|
137
142
|
/* eslint-disable no-redeclare */
|
|
138
143
|
declare function execute(
|
|
139
144
|
schema: GraphQLSchema,
|
|
@@ -143,7 +148,7 @@ declare function execute(
|
|
|
143
148
|
variableValues?: ?{ [variable: string]: mixed },
|
|
144
149
|
operationName?: ?string,
|
|
145
150
|
fieldResolver?: ?GraphQLFieldResolver<any, any>,
|
|
146
|
-
):
|
|
151
|
+
): MaybePromise<ExecutionResult>;
|
|
147
152
|
export function execute(
|
|
148
153
|
argsOrSchema,
|
|
149
154
|
document,
|
|
@@ -222,11 +227,10 @@ function executeImpl(
|
|
|
222
227
|
*/
|
|
223
228
|
function buildResponse(
|
|
224
229
|
context: ExecutionContext,
|
|
225
|
-
data:
|
|
230
|
+
data: MaybePromise<ObjMap<mixed> | null>,
|
|
226
231
|
) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return promise.then(resolved => buildResponse(context, resolved));
|
|
232
|
+
if (isPromise(data)) {
|
|
233
|
+
return data.then(resolved => buildResponse(context, resolved));
|
|
230
234
|
}
|
|
231
235
|
return context.errors.length === 0
|
|
232
236
|
? { data }
|
|
@@ -376,7 +380,7 @@ function executeOperation(
|
|
|
376
380
|
exeContext: ExecutionContext,
|
|
377
381
|
operation: OperationDefinitionNode,
|
|
378
382
|
rootValue: mixed,
|
|
379
|
-
):
|
|
383
|
+
): MaybePromise<ObjMap<mixed> | null> {
|
|
380
384
|
const type = getOperationRootType(exeContext.schema, operation);
|
|
381
385
|
const fields = collectFields(
|
|
382
386
|
exeContext,
|
|
@@ -398,9 +402,8 @@ function executeOperation(
|
|
|
398
402
|
operation.operation === 'mutation'
|
|
399
403
|
? executeFieldsSerially(exeContext, type, rootValue, path, fields)
|
|
400
404
|
: executeFields(exeContext, type, rootValue, path, fields);
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
return promise.then(undefined, error => {
|
|
405
|
+
if (isPromise(result)) {
|
|
406
|
+
return result.then(undefined, error => {
|
|
404
407
|
exeContext.errors.push(error);
|
|
405
408
|
return Promise.resolve(null);
|
|
406
409
|
});
|
|
@@ -463,33 +466,32 @@ function executeFieldsSerially(
|
|
|
463
466
|
sourceValue: mixed,
|
|
464
467
|
path: ResponsePath | void,
|
|
465
468
|
fields: ObjMap<Array<FieldNode>>,
|
|
466
|
-
):
|
|
467
|
-
return
|
|
468
|
-
(
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
return results;
|
|
481
|
-
}
|
|
482
|
-
const promise = getPromise(result);
|
|
483
|
-
if (promise) {
|
|
484
|
-
return promise.then(resolvedResult => {
|
|
485
|
-
results[responseName] = resolvedResult;
|
|
486
|
-
return results;
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
results[responseName] = result;
|
|
469
|
+
): MaybePromise<ObjMap<mixed>> {
|
|
470
|
+
return promiseReduce(
|
|
471
|
+
Object.keys(fields),
|
|
472
|
+
(results, responseName) => {
|
|
473
|
+
const fieldNodes = fields[responseName];
|
|
474
|
+
const fieldPath = addPath(path, responseName);
|
|
475
|
+
const result = resolveField(
|
|
476
|
+
exeContext,
|
|
477
|
+
parentType,
|
|
478
|
+
sourceValue,
|
|
479
|
+
fieldNodes,
|
|
480
|
+
fieldPath,
|
|
481
|
+
);
|
|
482
|
+
if (result === undefined) {
|
|
490
483
|
return results;
|
|
491
|
-
}
|
|
492
|
-
|
|
484
|
+
}
|
|
485
|
+
if (isPromise(result)) {
|
|
486
|
+
return result.then(resolvedResult => {
|
|
487
|
+
results[responseName] = resolvedResult;
|
|
488
|
+
return results;
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
results[responseName] = result;
|
|
492
|
+
return results;
|
|
493
|
+
},
|
|
494
|
+
Object.create(null),
|
|
493
495
|
);
|
|
494
496
|
}
|
|
495
497
|
|
|
@@ -503,7 +505,7 @@ function executeFields(
|
|
|
503
505
|
sourceValue: mixed,
|
|
504
506
|
path: ResponsePath | void,
|
|
505
507
|
fields: ObjMap<Array<FieldNode>>,
|
|
506
|
-
):
|
|
508
|
+
): MaybePromise<ObjMap<mixed>> {
|
|
507
509
|
let containsPromise = false;
|
|
508
510
|
|
|
509
511
|
const finalResults = Object.keys(fields).reduce((results, responseName) => {
|
|
@@ -520,7 +522,7 @@ function executeFields(
|
|
|
520
522
|
return results;
|
|
521
523
|
}
|
|
522
524
|
results[responseName] = result;
|
|
523
|
-
if (
|
|
525
|
+
if (!containsPromise && isPromise(result)) {
|
|
524
526
|
containsPromise = true;
|
|
525
527
|
}
|
|
526
528
|
return results;
|
|
@@ -660,24 +662,6 @@ function doesFragmentConditionMatch(
|
|
|
660
662
|
return false;
|
|
661
663
|
}
|
|
662
664
|
|
|
663
|
-
/**
|
|
664
|
-
* This function transforms a JS object `ObjMap<Promise<T>>` into
|
|
665
|
-
* a `Promise<ObjMap<T>>`
|
|
666
|
-
*
|
|
667
|
-
* This is akin to bluebird's `Promise.props`, but implemented only using
|
|
668
|
-
* `Promise.all` so it will work with any implementation of ES6 promises.
|
|
669
|
-
*/
|
|
670
|
-
function promiseForObject<T>(object: ObjMap<Promise<T>>): Promise<ObjMap<T>> {
|
|
671
|
-
const keys = Object.keys(object);
|
|
672
|
-
const valuesAndPromises = keys.map(name => object[name]);
|
|
673
|
-
return Promise.all(valuesAndPromises).then(values =>
|
|
674
|
-
values.reduce((resolvedObject, value, i) => {
|
|
675
|
-
resolvedObject[keys[i]] = value;
|
|
676
|
-
return resolvedObject;
|
|
677
|
-
}, Object.create(null)),
|
|
678
|
-
);
|
|
679
|
-
}
|
|
680
|
-
|
|
681
665
|
/**
|
|
682
666
|
* Implements the logic to compute the key of a given field's entry
|
|
683
667
|
*/
|
|
@@ -697,7 +681,7 @@ function resolveField(
|
|
|
697
681
|
source: mixed,
|
|
698
682
|
fieldNodes: $ReadOnlyArray<FieldNode>,
|
|
699
683
|
path: ResponsePath,
|
|
700
|
-
): mixed {
|
|
684
|
+
): MaybePromise<mixed> {
|
|
701
685
|
const fieldNode = fieldNodes[0];
|
|
702
686
|
const fieldName = fieldNode.name.value;
|
|
703
687
|
|
|
@@ -786,8 +770,7 @@ export function resolveFieldValueOrError<TSource>(
|
|
|
786
770
|
const context = exeContext.contextValue;
|
|
787
771
|
|
|
788
772
|
const result = resolveFn(source, args, context, info);
|
|
789
|
-
|
|
790
|
-
return promise ? promise.then(undefined, asErrorInstance) : result;
|
|
773
|
+
return isPromise(result) ? result.then(undefined, asErrorInstance) : result;
|
|
791
774
|
} catch (error) {
|
|
792
775
|
return asErrorInstance(error);
|
|
793
776
|
}
|
|
@@ -808,7 +791,7 @@ function completeValueCatchingError(
|
|
|
808
791
|
info: GraphQLResolveInfo,
|
|
809
792
|
path: ResponsePath,
|
|
810
793
|
result: mixed,
|
|
811
|
-
): mixed {
|
|
794
|
+
): MaybePromise<mixed> {
|
|
812
795
|
// If the field type is non-nullable, then it is resolved without any
|
|
813
796
|
// protection from errors, however it still properly locates the error.
|
|
814
797
|
if (isNonNullType(returnType)) {
|
|
@@ -833,13 +816,12 @@ function completeValueCatchingError(
|
|
|
833
816
|
path,
|
|
834
817
|
result,
|
|
835
818
|
);
|
|
836
|
-
|
|
837
|
-
if (promise) {
|
|
819
|
+
if (isPromise(completed)) {
|
|
838
820
|
// If `completeValueWithLocatedError` returned a rejected promise, log
|
|
839
821
|
// the rejection error and resolve to null.
|
|
840
822
|
// Note: we don't rely on a `catch` method, but we do expect "thenable"
|
|
841
823
|
// to take a second callback for the error case.
|
|
842
|
-
return
|
|
824
|
+
return completed.then(undefined, error => {
|
|
843
825
|
exeContext.errors.push(error);
|
|
844
826
|
return Promise.resolve(null);
|
|
845
827
|
});
|
|
@@ -862,7 +844,7 @@ function completeValueWithLocatedError(
|
|
|
862
844
|
info: GraphQLResolveInfo,
|
|
863
845
|
path: ResponsePath,
|
|
864
846
|
result: mixed,
|
|
865
|
-
): mixed {
|
|
847
|
+
): MaybePromise<mixed> {
|
|
866
848
|
try {
|
|
867
849
|
const completed = completeValue(
|
|
868
850
|
exeContext,
|
|
@@ -872,9 +854,8 @@ function completeValueWithLocatedError(
|
|
|
872
854
|
path,
|
|
873
855
|
result,
|
|
874
856
|
);
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
return promise.then(undefined, error =>
|
|
857
|
+
if (isPromise(completed)) {
|
|
858
|
+
return completed.then(undefined, error =>
|
|
878
859
|
Promise.reject(
|
|
879
860
|
locatedError(
|
|
880
861
|
asErrorInstance(error),
|
|
@@ -922,11 +903,10 @@ function completeValue(
|
|
|
922
903
|
info: GraphQLResolveInfo,
|
|
923
904
|
path: ResponsePath,
|
|
924
905
|
result: mixed,
|
|
925
|
-
): mixed {
|
|
906
|
+
): MaybePromise<mixed> {
|
|
926
907
|
// If result is a Promise, apply-lift over completeValue.
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
return promise.then(resolved =>
|
|
908
|
+
if (isPromise(result)) {
|
|
909
|
+
return result.then(resolved =>
|
|
930
910
|
completeValue(exeContext, returnType, fieldNodes, info, path, resolved),
|
|
931
911
|
);
|
|
932
912
|
}
|
|
@@ -1025,7 +1005,7 @@ function completeListValue(
|
|
|
1025
1005
|
info: GraphQLResolveInfo,
|
|
1026
1006
|
path: ResponsePath,
|
|
1027
1007
|
result: mixed,
|
|
1028
|
-
): mixed {
|
|
1008
|
+
): MaybePromise<$ReadOnlyArray<mixed>> {
|
|
1029
1009
|
invariant(
|
|
1030
1010
|
isCollection(result),
|
|
1031
1011
|
`Expected Iterable, but did not find one for field ${
|
|
@@ -1051,7 +1031,7 @@ function completeListValue(
|
|
|
1051
1031
|
item,
|
|
1052
1032
|
);
|
|
1053
1033
|
|
|
1054
|
-
if (!containsPromise &&
|
|
1034
|
+
if (!containsPromise && isPromise(completedItem)) {
|
|
1055
1035
|
containsPromise = true;
|
|
1056
1036
|
}
|
|
1057
1037
|
completedResults.push(completedItem);
|
|
@@ -1087,14 +1067,13 @@ function completeAbstractValue(
|
|
|
1087
1067
|
info: GraphQLResolveInfo,
|
|
1088
1068
|
path: ResponsePath,
|
|
1089
1069
|
result: mixed,
|
|
1090
|
-
): mixed {
|
|
1070
|
+
): MaybePromise<ObjMap<mixed>> {
|
|
1091
1071
|
const runtimeType = returnType.resolveType
|
|
1092
1072
|
? returnType.resolveType(result, exeContext.contextValue, info)
|
|
1093
1073
|
: defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);
|
|
1094
1074
|
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
return promise.then(resolvedRuntimeType =>
|
|
1075
|
+
if (isPromise(runtimeType)) {
|
|
1076
|
+
return runtimeType.then(resolvedRuntimeType =>
|
|
1098
1077
|
completeObjectValue(
|
|
1099
1078
|
exeContext,
|
|
1100
1079
|
ensureValidRuntimeType(
|
|
@@ -1116,7 +1095,7 @@ function completeAbstractValue(
|
|
|
1116
1095
|
return completeObjectValue(
|
|
1117
1096
|
exeContext,
|
|
1118
1097
|
ensureValidRuntimeType(
|
|
1119
|
-
|
|
1098
|
+
runtimeType,
|
|
1120
1099
|
exeContext,
|
|
1121
1100
|
returnType,
|
|
1122
1101
|
fieldNodes,
|
|
@@ -1176,17 +1155,16 @@ function completeObjectValue(
|
|
|
1176
1155
|
info: GraphQLResolveInfo,
|
|
1177
1156
|
path: ResponsePath,
|
|
1178
1157
|
result: mixed,
|
|
1179
|
-
): mixed {
|
|
1158
|
+
): MaybePromise<ObjMap<mixed>> {
|
|
1180
1159
|
// If there is an isTypeOf predicate function, call it with the
|
|
1181
1160
|
// current result. If isTypeOf returns false, then raise an error rather
|
|
1182
1161
|
// than continuing execution.
|
|
1183
1162
|
if (returnType.isTypeOf) {
|
|
1184
1163
|
const isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
|
|
1185
1164
|
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
if (!isTypeOfResult) {
|
|
1165
|
+
if (isPromise(isTypeOf)) {
|
|
1166
|
+
return isTypeOf.then(resolvedIsTypeOf => {
|
|
1167
|
+
if (!resolvedIsTypeOf) {
|
|
1190
1168
|
throw invalidReturnTypeError(returnType, result, fieldNodes);
|
|
1191
1169
|
}
|
|
1192
1170
|
return collectAndExecuteSubfields(
|
|
@@ -1233,8 +1211,23 @@ function collectAndExecuteSubfields(
|
|
|
1233
1211
|
info: GraphQLResolveInfo,
|
|
1234
1212
|
path: ResponsePath,
|
|
1235
1213
|
result: mixed,
|
|
1236
|
-
): mixed {
|
|
1214
|
+
): MaybePromise<ObjMap<mixed>> {
|
|
1237
1215
|
// Collect sub-fields to execute to complete this value.
|
|
1216
|
+
const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
|
|
1217
|
+
return executeFields(exeContext, returnType, result, path, subFieldNodes);
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* A memoized collection of relevant subfields in the context of the return
|
|
1222
|
+
* type. Memoizing ensures the subfields are not repeatedly calculated, which
|
|
1223
|
+
* saves overhead when resolving lists of values.
|
|
1224
|
+
*/
|
|
1225
|
+
const collectSubfields = memoize3(_collectSubfields);
|
|
1226
|
+
function _collectSubfields(
|
|
1227
|
+
exeContext: ExecutionContext,
|
|
1228
|
+
returnType: GraphQLObjectType,
|
|
1229
|
+
fieldNodes: $ReadOnlyArray<FieldNode>,
|
|
1230
|
+
): ObjMap<Array<FieldNode>> {
|
|
1238
1231
|
let subFieldNodes = Object.create(null);
|
|
1239
1232
|
const visitedFragmentNames = Object.create(null);
|
|
1240
1233
|
for (let i = 0; i < fieldNodes.length; i++) {
|
|
@@ -1249,8 +1242,7 @@ function collectAndExecuteSubfields(
|
|
|
1249
1242
|
);
|
|
1250
1243
|
}
|
|
1251
1244
|
}
|
|
1252
|
-
|
|
1253
|
-
return executeFields(exeContext, returnType, result, path, subFieldNodes);
|
|
1245
|
+
return subFieldNodes;
|
|
1254
1246
|
}
|
|
1255
1247
|
|
|
1256
1248
|
/**
|
|
@@ -1288,9 +1280,8 @@ function defaultResolveTypeFn(
|
|
|
1288
1280
|
if (type.isTypeOf) {
|
|
1289
1281
|
const isTypeOfResult = type.isTypeOf(value, context, info);
|
|
1290
1282
|
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
promisedIsTypeOfResults[i] = promise;
|
|
1283
|
+
if (isPromise(isTypeOfResult)) {
|
|
1284
|
+
promisedIsTypeOfResults[i] = isTypeOfResult;
|
|
1294
1285
|
} else if (isTypeOfResult) {
|
|
1295
1286
|
return type;
|
|
1296
1287
|
}
|
|
@@ -1330,20 +1321,6 @@ export const defaultFieldResolver: GraphQLFieldResolver<any, *> = function(
|
|
|
1330
1321
|
}
|
|
1331
1322
|
};
|
|
1332
1323
|
|
|
1333
|
-
/**
|
|
1334
|
-
* Only returns the value if it acts like a Promise, i.e. has a "then" function,
|
|
1335
|
-
* otherwise returns void.
|
|
1336
|
-
*/
|
|
1337
|
-
function getPromise<T>(value: Promise<T> | mixed): Promise<T> | void {
|
|
1338
|
-
if (
|
|
1339
|
-
typeof value === 'object' &&
|
|
1340
|
-
value !== null &&
|
|
1341
|
-
typeof value.then === 'function'
|
|
1342
|
-
) {
|
|
1343
|
-
return (value: any);
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
1324
|
/**
|
|
1348
1325
|
* This method looks up the field on the given type defintion.
|
|
1349
1326
|
* It has special casing for the two introspection fields, __schema
|
|
@@ -6,7 +6,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* strict
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { forEach, isCollection } from 'iterall';
|
|
@@ -14,10 +14,14 @@ import { GraphQLError, locatedError } from '../error';
|
|
|
14
14
|
import invariant from '../jsutils/invariant';
|
|
15
15
|
import isInvalid from '../jsutils/isInvalid';
|
|
16
16
|
import isNullish from '../jsutils/isNullish';
|
|
17
|
+
import isPromise from '../jsutils/isPromise';
|
|
18
|
+
import memoize3 from '../jsutils/memoize3';
|
|
19
|
+
import promiseForObject from '../jsutils/promiseForObject';
|
|
20
|
+
import promiseReduce from '../jsutils/promiseReduce';
|
|
17
21
|
|
|
18
22
|
|
|
19
23
|
import { typeFromAST } from '../utilities/typeFromAST';
|
|
20
|
-
import
|
|
24
|
+
import { Kind } from '../language/kinds';
|
|
21
25
|
import { getVariableValues, getArgumentValues, getDirectiveValues } from './values';
|
|
22
26
|
import { isObjectType, isAbstractType, isLeafType, isListType, isNonNullType } from '../type/definition';
|
|
23
27
|
|
|
@@ -112,9 +116,8 @@ function executeImpl(schema, document, rootValue, contextValue, variableValues,
|
|
|
112
116
|
* response defined by the "Response" section of the GraphQL specification.
|
|
113
117
|
*/
|
|
114
118
|
function buildResponse(context, data) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return promise.then(function (resolved) {
|
|
119
|
+
if (isPromise(data)) {
|
|
120
|
+
return data.then(function (resolved) {
|
|
118
121
|
return buildResponse(context, resolved);
|
|
119
122
|
});
|
|
120
123
|
}
|
|
@@ -240,9 +243,8 @@ function executeOperation(exeContext, operation, rootValue) {
|
|
|
240
243
|
// Similar to completeValueCatchingError.
|
|
241
244
|
try {
|
|
242
245
|
var result = operation.operation === 'mutation' ? executeFieldsSerially(exeContext, type, rootValue, path, fields) : executeFields(exeContext, type, rootValue, path, fields);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
return promise.then(undefined, function (error) {
|
|
246
|
+
if (isPromise(result)) {
|
|
247
|
+
return result.then(undefined, function (error) {
|
|
246
248
|
exeContext.errors.push(error);
|
|
247
249
|
return Promise.resolve(null);
|
|
248
250
|
});
|
|
@@ -287,25 +289,22 @@ export function getOperationRootType(schema, operation) {
|
|
|
287
289
|
* for "write" mode.
|
|
288
290
|
*/
|
|
289
291
|
function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields) {
|
|
290
|
-
return Object.keys(fields)
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (result === undefined) {
|
|
296
|
-
return results;
|
|
297
|
-
}
|
|
298
|
-
var promise = getPromise(result);
|
|
299
|
-
if (promise) {
|
|
300
|
-
return promise.then(function (resolvedResult) {
|
|
301
|
-
results[responseName] = resolvedResult;
|
|
302
|
-
return results;
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
results[responseName] = result;
|
|
292
|
+
return promiseReduce(Object.keys(fields), function (results, responseName) {
|
|
293
|
+
var fieldNodes = fields[responseName];
|
|
294
|
+
var fieldPath = addPath(path, responseName);
|
|
295
|
+
var result = resolveField(exeContext, parentType, sourceValue, fieldNodes, fieldPath);
|
|
296
|
+
if (result === undefined) {
|
|
306
297
|
return results;
|
|
307
|
-
}
|
|
308
|
-
|
|
298
|
+
}
|
|
299
|
+
if (isPromise(result)) {
|
|
300
|
+
return result.then(function (resolvedResult) {
|
|
301
|
+
results[responseName] = resolvedResult;
|
|
302
|
+
return results;
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
results[responseName] = result;
|
|
306
|
+
return results;
|
|
307
|
+
}, Object.create(null));
|
|
309
308
|
}
|
|
310
309
|
|
|
311
310
|
/**
|
|
@@ -323,7 +322,7 @@ function executeFields(exeContext, parentType, sourceValue, path, fields) {
|
|
|
323
322
|
return results;
|
|
324
323
|
}
|
|
325
324
|
results[responseName] = result;
|
|
326
|
-
if (
|
|
325
|
+
if (!containsPromise && isPromise(result)) {
|
|
327
326
|
containsPromise = true;
|
|
328
327
|
}
|
|
329
328
|
return results;
|
|
@@ -421,26 +420,6 @@ function doesFragmentConditionMatch(exeContext, fragment, type) {
|
|
|
421
420
|
return false;
|
|
422
421
|
}
|
|
423
422
|
|
|
424
|
-
/**
|
|
425
|
-
* This function transforms a JS object `ObjMap<Promise<T>>` into
|
|
426
|
-
* a `Promise<ObjMap<T>>`
|
|
427
|
-
*
|
|
428
|
-
* This is akin to bluebird's `Promise.props`, but implemented only using
|
|
429
|
-
* `Promise.all` so it will work with any implementation of ES6 promises.
|
|
430
|
-
*/
|
|
431
|
-
function promiseForObject(object) {
|
|
432
|
-
var keys = Object.keys(object);
|
|
433
|
-
var valuesAndPromises = keys.map(function (name) {
|
|
434
|
-
return object[name];
|
|
435
|
-
});
|
|
436
|
-
return Promise.all(valuesAndPromises).then(function (values) {
|
|
437
|
-
return values.reduce(function (resolvedObject, value, i) {
|
|
438
|
-
resolvedObject[keys[i]] = value;
|
|
439
|
-
return resolvedObject;
|
|
440
|
-
}, Object.create(null));
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
|
|
444
423
|
/**
|
|
445
424
|
* Implements the logic to compute the key of a given field's entry
|
|
446
425
|
*/
|
|
@@ -506,8 +485,7 @@ export function resolveFieldValueOrError(exeContext, fieldDef, fieldNodes, resol
|
|
|
506
485
|
var context = exeContext.contextValue;
|
|
507
486
|
|
|
508
487
|
var result = resolveFn(source, args, context, info);
|
|
509
|
-
|
|
510
|
-
return promise ? promise.then(undefined, asErrorInstance) : result;
|
|
488
|
+
return isPromise(result) ? result.then(undefined, asErrorInstance) : result;
|
|
511
489
|
} catch (error) {
|
|
512
490
|
return asErrorInstance(error);
|
|
513
491
|
}
|
|
@@ -532,13 +510,12 @@ function completeValueCatchingError(exeContext, returnType, fieldNodes, info, pa
|
|
|
532
510
|
// a null value for this field if one is encountered.
|
|
533
511
|
try {
|
|
534
512
|
var completed = completeValueWithLocatedError(exeContext, returnType, fieldNodes, info, path, result);
|
|
535
|
-
|
|
536
|
-
if (promise) {
|
|
513
|
+
if (isPromise(completed)) {
|
|
537
514
|
// If `completeValueWithLocatedError` returned a rejected promise, log
|
|
538
515
|
// the rejection error and resolve to null.
|
|
539
516
|
// Note: we don't rely on a `catch` method, but we do expect "thenable"
|
|
540
517
|
// to take a second callback for the error case.
|
|
541
|
-
return
|
|
518
|
+
return completed.then(undefined, function (error) {
|
|
542
519
|
exeContext.errors.push(error);
|
|
543
520
|
return Promise.resolve(null);
|
|
544
521
|
});
|
|
@@ -557,9 +534,8 @@ function completeValueCatchingError(exeContext, returnType, fieldNodes, info, pa
|
|
|
557
534
|
function completeValueWithLocatedError(exeContext, returnType, fieldNodes, info, path, result) {
|
|
558
535
|
try {
|
|
559
536
|
var completed = completeValue(exeContext, returnType, fieldNodes, info, path, result);
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
return promise.then(undefined, function (error) {
|
|
537
|
+
if (isPromise(completed)) {
|
|
538
|
+
return completed.then(undefined, function (error) {
|
|
563
539
|
return Promise.reject(locatedError(asErrorInstance(error), fieldNodes, responsePathAsArray(path)));
|
|
564
540
|
});
|
|
565
541
|
}
|
|
@@ -592,9 +568,8 @@ function completeValueWithLocatedError(exeContext, returnType, fieldNodes, info,
|
|
|
592
568
|
*/
|
|
593
569
|
function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
|
|
594
570
|
// If result is a Promise, apply-lift over completeValue.
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
return promise.then(function (resolved) {
|
|
571
|
+
if (isPromise(result)) {
|
|
572
|
+
return result.then(function (resolved) {
|
|
598
573
|
return completeValue(exeContext, returnType, fieldNodes, info, path, resolved);
|
|
599
574
|
});
|
|
600
575
|
}
|
|
@@ -664,7 +639,7 @@ function completeListValue(exeContext, returnType, fieldNodes, info, path, resul
|
|
|
664
639
|
var fieldPath = addPath(path, index);
|
|
665
640
|
var completedItem = completeValueCatchingError(exeContext, itemType, fieldNodes, info, fieldPath, item);
|
|
666
641
|
|
|
667
|
-
if (!containsPromise &&
|
|
642
|
+
if (!containsPromise && isPromise(completedItem)) {
|
|
668
643
|
containsPromise = true;
|
|
669
644
|
}
|
|
670
645
|
completedResults.push(completedItem);
|
|
@@ -693,9 +668,8 @@ function completeLeafValue(returnType, result) {
|
|
|
693
668
|
function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result) {
|
|
694
669
|
var runtimeType = returnType.resolveType ? returnType.resolveType(result, exeContext.contextValue, info) : defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);
|
|
695
670
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
return promise.then(function (resolvedRuntimeType) {
|
|
671
|
+
if (isPromise(runtimeType)) {
|
|
672
|
+
return runtimeType.then(function (resolvedRuntimeType) {
|
|
699
673
|
return completeObjectValue(exeContext, ensureValidRuntimeType(resolvedRuntimeType, exeContext, returnType, fieldNodes, info, result), fieldNodes, info, path, result);
|
|
700
674
|
});
|
|
701
675
|
}
|
|
@@ -727,10 +701,9 @@ function completeObjectValue(exeContext, returnType, fieldNodes, info, path, res
|
|
|
727
701
|
if (returnType.isTypeOf) {
|
|
728
702
|
var isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
|
|
729
703
|
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
if (!isTypeOfResult) {
|
|
704
|
+
if (isPromise(isTypeOf)) {
|
|
705
|
+
return isTypeOf.then(function (resolvedIsTypeOf) {
|
|
706
|
+
if (!resolvedIsTypeOf) {
|
|
734
707
|
throw invalidReturnTypeError(returnType, result, fieldNodes);
|
|
735
708
|
}
|
|
736
709
|
return collectAndExecuteSubfields(exeContext, returnType, fieldNodes, info, path, result);
|
|
@@ -751,6 +724,17 @@ function invalidReturnTypeError(returnType, result, fieldNodes) {
|
|
|
751
724
|
|
|
752
725
|
function collectAndExecuteSubfields(exeContext, returnType, fieldNodes, info, path, result) {
|
|
753
726
|
// Collect sub-fields to execute to complete this value.
|
|
727
|
+
var subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
|
|
728
|
+
return executeFields(exeContext, returnType, result, path, subFieldNodes);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* A memoized collection of relevant subfields in the context of the return
|
|
733
|
+
* type. Memoizing ensures the subfields are not repeatedly calculated, which
|
|
734
|
+
* saves overhead when resolving lists of values.
|
|
735
|
+
*/
|
|
736
|
+
var collectSubfields = memoize3(_collectSubfields);
|
|
737
|
+
function _collectSubfields(exeContext, returnType, fieldNodes) {
|
|
754
738
|
var subFieldNodes = Object.create(null);
|
|
755
739
|
var visitedFragmentNames = Object.create(null);
|
|
756
740
|
for (var i = 0; i < fieldNodes.length; i++) {
|
|
@@ -759,8 +743,7 @@ function collectAndExecuteSubfields(exeContext, returnType, fieldNodes, info, pa
|
|
|
759
743
|
subFieldNodes = collectFields(exeContext, returnType, selectionSet, subFieldNodes, visitedFragmentNames);
|
|
760
744
|
}
|
|
761
745
|
}
|
|
762
|
-
|
|
763
|
-
return executeFields(exeContext, returnType, result, path, subFieldNodes);
|
|
746
|
+
return subFieldNodes;
|
|
764
747
|
}
|
|
765
748
|
|
|
766
749
|
/**
|
|
@@ -789,9 +772,8 @@ function defaultResolveTypeFn(value, context, info, abstractType) {
|
|
|
789
772
|
if (type.isTypeOf) {
|
|
790
773
|
var isTypeOfResult = type.isTypeOf(value, context, info);
|
|
791
774
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
promisedIsTypeOfResults[i] = promise;
|
|
775
|
+
if (isPromise(isTypeOfResult)) {
|
|
776
|
+
promisedIsTypeOfResults[i] = isTypeOfResult;
|
|
795
777
|
} else if (isTypeOfResult) {
|
|
796
778
|
return type;
|
|
797
779
|
}
|
|
@@ -826,16 +808,6 @@ export var defaultFieldResolver = function defaultFieldResolver(source, args, co
|
|
|
826
808
|
}
|
|
827
809
|
};
|
|
828
810
|
|
|
829
|
-
/**
|
|
830
|
-
* Only returns the value if it acts like a Promise, i.e. has a "then" function,
|
|
831
|
-
* otherwise returns void.
|
|
832
|
-
*/
|
|
833
|
-
function getPromise(value) {
|
|
834
|
-
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null && typeof value.then === 'function') {
|
|
835
|
-
return value;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
|
|
839
811
|
/**
|
|
840
812
|
* This method looks up the field on the given type defintion.
|
|
841
813
|
* It has special casing for the two introspection fields, __schema
|
package/execution/index.js.flow
CHANGED