Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new 'FormattedExecutionResult' type #2688

Merged
merged 1 commit into from Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, why do these types need to be exported from index.js if they are already exported from index.d.ts?

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