From 0060551b1f0a38aed70ce66d39e7d02bf03b66e2 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sun, 5 Jul 2020 21:57:14 +0300 Subject: [PATCH] Added new 'FormattedExecutionResult' type Back port of #2688 --- src/execution/execute.js | 7 +++++++ src/execution/index.js | 6 +++++- src/index.js | 6 +++++- tstypes/execution/execute.d.ts | 8 +++++++- tstypes/execution/index.d.ts | 1 + tstypes/index.d.ts | 1 + 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/execution/execute.js b/src/execution/execute.js index 7e1ea84dea..ff2cb01c82 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -16,6 +16,7 @@ import promiseForObject from '../jsutils/promiseForObject'; import { type PromiseOrValue } from '../jsutils/PromiseOrValue'; import { type Path, addPath, pathToArray } from '../jsutils/Path'; +import { type GraphQLFormattedError } from '../error/formatError'; import { GraphQLError } from '../error/GraphQLError'; import { locatedError } from '../error/locatedError'; @@ -117,6 +118,12 @@ export type ExecutionResult = { ... }; +export type FormattedExecutionResult = {| + errors?: $ReadOnlyArray, + data?: ObjMap | null, + extensions?: ObjMap, +|}; + export type ExecutionArgs = {| schema: GraphQLSchema, document: DocumentNode, diff --git a/src/execution/index.js b/src/execution/index.js index c7ffa5cdef..fed0faa5d8 100644 --- a/src/execution/index.js +++ b/src/execution/index.js @@ -3,6 +3,10 @@ export { pathToArray as responsePathAsArray } from '../jsutils/Path'; export { execute, defaultFieldResolver, defaultTypeResolver } from './execute'; -export type { ExecutionArgs, ExecutionResult } from './execute'; +export type { + ExecutionArgs, + ExecutionResult, + FormattedExecutionResult, +} from './execute'; export { getDirectiveValues } from './values'; diff --git a/src/index.js b/src/index.js index 140ab33f66..7acfe627bb 100644 --- a/src/index.js +++ b/src/index.js @@ -288,7 +288,11 @@ export { getDirectiveValues, } from './execution'; -export type { ExecutionArgs, ExecutionResult } from './execution'; +export type { + ExecutionArgs, + ExecutionResult, + FormattedExecutionResult, +} from './execution'; export { subscribe, createSourceEventStream } from './subscription'; export type { SubscriptionArgs } from './subscription'; diff --git a/tstypes/execution/execute.d.ts b/tstypes/execution/execute.d.ts index 95d2acbe0b..d11bca31dd 100644 --- a/tstypes/execution/execute.d.ts +++ b/tstypes/execution/execute.d.ts @@ -3,7 +3,7 @@ import { PromiseOrValue } from '../jsutils/PromiseOrValue'; import { Path, addPath, pathToArray } from '../jsutils/Path'; import { GraphQLError } from '../error/GraphQLError'; -import { locatedError } from '../error/locatedError'; +import { GraphQLFormattedError } from '../error/formatError'; import { DirectiveNode, @@ -56,6 +56,12 @@ export interface ExecutionResult { data?: TData | null; } +export interface FormattedExecutionResult { + errors?: ReadonlyArray; + // TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229 + data?: TData | null; +} + export type ExecutionArgs = { schema: GraphQLSchema; document: DocumentNode; diff --git a/tstypes/execution/index.d.ts b/tstypes/execution/index.d.ts index ed0f8f1808..83094589b8 100644 --- a/tstypes/execution/index.d.ts +++ b/tstypes/execution/index.d.ts @@ -6,6 +6,7 @@ export { defaultTypeResolver, ExecutionArgs, ExecutionResult, + FormattedExecutionResult, } from './execute'; export { getDirectiveValues } from './values'; diff --git a/tstypes/index.d.ts b/tstypes/index.d.ts index 46a19bb1e3..ae890f8d9a 100644 --- a/tstypes/index.d.ts +++ b/tstypes/index.d.ts @@ -287,6 +287,7 @@ export { getDirectiveValues, ExecutionArgs, ExecutionResult, + FormattedExecutionResult, } from './execution'; export {