Skip to content

Commit

Permalink
Added new 'FormattedExecutionResult' type
Browse files Browse the repository at this point in the history
Back port of #2688
  • Loading branch information
IvanGoncharov committed Jul 6, 2020
1 parent 0eb088b commit 0060551
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/execution/execute.js
Expand Up @@ -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';

Expand Down Expand Up @@ -117,6 +118,12 @@ export type ExecutionResult = {
...
};

export type FormattedExecutionResult = {|
errors?: $ReadOnlyArray<GraphQLFormattedError>,
data?: ObjMap<mixed> | null,
extensions?: ObjMap<mixed>,
|};

export type ExecutionArgs = {|
schema: GraphQLSchema,
document: DocumentNode,
Expand Down
6 changes: 5 additions & 1 deletion src/execution/index.js
Expand Up @@ -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';
6 changes: 5 additions & 1 deletion src/index.js
Expand Up @@ -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';
Expand Down
8 changes: 7 additions & 1 deletion tstypes/execution/execute.d.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -56,6 +56,12 @@ export interface ExecutionResult<TData = ExecutionResultDataDefault> {
data?: TData | null;
}

export interface FormattedExecutionResult<TData = ExecutionResultDataDefault> {
errors?: ReadonlyArray<GraphQLFormattedError>;
// TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229
data?: TData | null;
}

export type ExecutionArgs = {
schema: GraphQLSchema;
document: DocumentNode;
Expand Down
1 change: 1 addition & 0 deletions tstypes/execution/index.d.ts
Expand Up @@ -6,6 +6,7 @@ export {
defaultTypeResolver,
ExecutionArgs,
ExecutionResult,
FormattedExecutionResult,
} from './execute';

export { getDirectiveValues } from './values';
1 change: 1 addition & 0 deletions tstypes/index.d.ts
Expand Up @@ -287,6 +287,7 @@ export {
getDirectiveValues,
ExecutionArgs,
ExecutionResult,
FormattedExecutionResult,
} from './execution';

export {
Expand Down

0 comments on commit 0060551

Please sign in to comment.