From f12bde689f93be6fafb65b1d73e5337220f3ce56 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sun, 5 Jul 2020 21:28:00 +0300 Subject: [PATCH] Added new 'FormattedExecutionResult' type --- src/execution/execute.d.ts | 11 +++++++++++ src/execution/execute.js | 7 +++++++ src/execution/index.d.ts | 1 + src/execution/index.js | 7 ++++++- src/index.d.ts | 1 + src/index.js | 6 +++++- 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/execution/execute.d.ts b/src/execution/execute.d.ts index a879b538d9..3adfdc4733 100644 --- a/src/execution/execute.d.ts +++ b/src/execution/execute.d.ts @@ -4,6 +4,7 @@ import { PromiseOrValue } from '../jsutils/PromiseOrValue'; import { Path } from '../jsutils/Path'; import { GraphQLError } from '../error/GraphQLError'; +import { GraphQLFormattedError } from '../error/formatError'; import { DocumentNode, @@ -55,6 +56,16 @@ export interface ExecutionResult< extensions?: TExtensions; } +export interface FormattedExecutionResult< + TData = { [key: string]: any }, + TExtensions = { [key: string]: any } +> { + errors?: ReadonlyArray; + // TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229 + data?: TData | null; + extensions?: TExtensions; +} + export interface ExecutionArgs { schema: GraphQLSchema; document: DocumentNode; diff --git a/src/execution/execute.js b/src/execution/execute.js index 0fc79b5818..624a4fcdcb 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -16,6 +16,7 @@ import promiseReduce from '../jsutils/promiseReduce'; import promiseForObject from '../jsutils/promiseForObject'; import { addPath, pathToArray } from '../jsutils/Path'; +import type { GraphQLFormattedError } from '../error/formatError'; import { GraphQLError } from '../error/GraphQLError'; import { locatedError } from '../error/locatedError'; @@ -120,6 +121,12 @@ export type ExecutionResult = {| extensions?: ObjMap, |}; +export type FormattedExecutionResult = {| + errors?: $ReadOnlyArray, + data?: ObjMap | null, + extensions?: ObjMap, +|}; + export type ExecutionArgs = {| schema: GraphQLSchema, document: DocumentNode, diff --git a/src/execution/index.d.ts b/src/execution/index.d.ts index 043e061982..d70ba3aaa5 100644 --- a/src/execution/index.d.ts +++ b/src/execution/index.d.ts @@ -7,6 +7,7 @@ export { defaultTypeResolver, ExecutionArgs, ExecutionResult, + FormattedExecutionResult, } from './execute'; export { getDirectiveValues } from './values'; diff --git a/src/execution/index.js b/src/execution/index.js index cccb9f0a73..14366ad194 100644 --- a/src/execution/index.js +++ b/src/execution/index.js @@ -8,6 +8,11 @@ export { 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.d.ts b/src/index.d.ts index 6273448f22..9ff5ee02a6 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -299,6 +299,7 @@ export { getDirectiveValues, ExecutionArgs, ExecutionResult, + FormattedExecutionResult, } from './execution/index'; export { diff --git a/src/index.js b/src/index.js index ff46b68ad9..23bb3980a6 100644 --- a/src/index.js +++ b/src/index.js @@ -288,7 +288,11 @@ export { getDirectiveValues, } from './execution/index'; -export type { ExecutionArgs, ExecutionResult } from './execution/index'; +export type { + ExecutionArgs, + ExecutionResult, + FormattedExecutionResult, +} from './execution/index'; export { subscribe, createSourceEventStream } from './subscription/index'; export type { SubscriptionArgs } from './subscription/index';