Skip to content

Commit

Permalink
Added new 'FormattedExecutionResult' type (#2688)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jul 5, 2020
1 parent fb042fc commit 0c66053
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/execution/execute.d.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -55,6 +56,16 @@ export interface ExecutionResult<
extensions?: TExtensions;
}

export interface FormattedExecutionResult<
TData = { [key: string]: any },
TExtensions = { [key: string]: any }
> {
errors?: ReadonlyArray<GraphQLFormattedError>;
// 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;
Expand Down
7 changes: 7 additions & 0 deletions src/execution/execute.js
Expand Up @@ -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';

Expand Down Expand Up @@ -120,6 +121,12 @@ export type ExecutionResult = {|
extensions?: ObjMap<mixed>,
|};

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

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

export { getDirectiveValues } from './values';
7 changes: 6 additions & 1 deletion src/execution/index.js
Expand Up @@ -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';
1 change: 1 addition & 0 deletions src/index.d.ts
Expand Up @@ -299,6 +299,7 @@ export {
getDirectiveValues,
ExecutionArgs,
ExecutionResult,
FormattedExecutionResult,
} from './execution/index';

export {
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Expand Up @@ -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';
Expand Down

0 comments on commit 0c66053

Please sign in to comment.