mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
[@types/graphql] Add generic type on ExecutionResult (#26763)
* [@types/graphql] Add generic type on ExecutionResult Without a generic type on ExecutionResult we can't have typesafe operations. * Add default type to the generic so it's not a breaking change * Don't make TData readonly
This commit is contained in:
parent
3a151309f6
commit
deb7d8beaf
15
types/graphql/execution/execute.d.ts
vendored
15
types/graphql/execution/execute.d.ts
vendored
@ -36,15 +36,19 @@ export interface ExecutionContext {
|
||||
errors: GraphQLError[];
|
||||
}
|
||||
|
||||
export interface ExecutionResultDataDefault {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/**
|
||||
* The result of GraphQL execution.
|
||||
*
|
||||
* - `errors` is included when any errors occurred as a non-empty array.
|
||||
* - `data` is the result of a successful execution of the query.
|
||||
*/
|
||||
export interface ExecutionResult {
|
||||
export interface ExecutionResult<TData = ExecutionResultDataDefault> {
|
||||
errors?: ReadonlyArray<GraphQLError>;
|
||||
data?: { [key: string]: any };
|
||||
data?: TData;
|
||||
}
|
||||
|
||||
export type ExecutionArgs = {
|
||||
@ -69,8 +73,8 @@ export type ExecutionArgs = {
|
||||
*
|
||||
* Accepts either an object with named arguments, or individual arguments.
|
||||
*/
|
||||
export function execute(args: ExecutionArgs): MaybePromise<ExecutionResult>;
|
||||
export function execute(
|
||||
export function execute<TData = ExecutionResultDataDefault>(args: ExecutionArgs): MaybePromise<ExecutionResult<TData>>;
|
||||
export function execute<TData = ExecutionResultDataDefault>(
|
||||
schema: GraphQLSchema,
|
||||
document: DocumentNode,
|
||||
rootValue?: any,
|
||||
@ -78,7 +82,7 @@ export function execute(
|
||||
variableValues?: Maybe<{ [key: string]: any }>,
|
||||
operationName?: Maybe<string>,
|
||||
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>
|
||||
): MaybePromise<ExecutionResult>;
|
||||
): MaybePromise<ExecutionResult<TData>>;
|
||||
|
||||
/**
|
||||
* Given a ResponsePath (found in the `path` entry in the information provided
|
||||
@ -89,6 +93,7 @@ export function responsePathAsArray(path: ResponsePath): ReadonlyArray<string |
|
||||
/**
|
||||
* Given a ResponsePath and a key, return a new ResponsePath containing the
|
||||
* new key.
|
||||
|
||||
*/
|
||||
export function addPath(
|
||||
prev: ResponsePath | undefined,
|
||||
|
||||
14
types/graphql/graphql.d.ts
vendored
14
types/graphql/graphql.d.ts
vendored
@ -2,7 +2,7 @@ import Maybe from "./tsutils/Maybe";
|
||||
import { Source } from "./language/source";
|
||||
import { GraphQLFieldResolver } from "./type/definition";
|
||||
import { GraphQLSchema } from "./type/schema";
|
||||
import { ExecutionResult } from "./execution/execute";
|
||||
import { ExecutionResult, ExecutionResultDataDefault } from "./execution/execute";
|
||||
|
||||
/**
|
||||
* This is the primary entry point function for fulfilling GraphQL operations
|
||||
@ -44,8 +44,8 @@ export interface GraphQLArgs {
|
||||
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
|
||||
}
|
||||
|
||||
export function graphql(args: GraphQLArgs): Promise<ExecutionResult>;
|
||||
export function graphql(
|
||||
export function graphql<TData = ExecutionResultDataDefault>(args: GraphQLArgs): Promise<ExecutionResult<TData>>;
|
||||
export function graphql<TData = ExecutionResultDataDefault>(
|
||||
schema: GraphQLSchema,
|
||||
source: Source | string,
|
||||
rootValue?: any,
|
||||
@ -53,7 +53,7 @@ export function graphql(
|
||||
variableValues?: Maybe<{ [key: string]: any }>,
|
||||
operationName?: Maybe<string>,
|
||||
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>
|
||||
): Promise<ExecutionResult>;
|
||||
): Promise<ExecutionResult<TData>>;
|
||||
|
||||
/**
|
||||
* The graphqlSync function also fulfills GraphQL operations by parsing,
|
||||
@ -61,8 +61,8 @@ export function graphql(
|
||||
* However, it guarantees to complete synchronously (or throw an error) assuming
|
||||
* that all field resolvers are also synchronous.
|
||||
*/
|
||||
export function graphqlSync(args: GraphQLArgs): ExecutionResult;
|
||||
export function graphqlSync(
|
||||
export function graphqlSync<TData = ExecutionResultDataDefault>(args: GraphQLArgs): ExecutionResult<TData>;
|
||||
export function graphqlSync<TData = ExecutionResultDataDefault>(
|
||||
schema: GraphQLSchema,
|
||||
source: Source | string,
|
||||
rootValue?: any,
|
||||
@ -70,4 +70,4 @@ export function graphqlSync(
|
||||
variableValues?: Maybe<{ [key: string]: any }>,
|
||||
operationName?: Maybe<string>,
|
||||
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>
|
||||
): ExecutionResult;
|
||||
): ExecutionResult<TData>;
|
||||
|
||||
1
types/graphql/index.d.ts
vendored
1
types/graphql/index.d.ts
vendored
@ -14,6 +14,7 @@
|
||||
// Alessio Dionisi <https://github.com/adnsio>
|
||||
// Divyendu Singh <https://github.com/divyenduz>
|
||||
// Brad Zacher <https://github.com/bradzacher>
|
||||
// Curtis Layne <https://github.com/clayne11>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
|
||||
14
types/graphql/subscription/subscribe.d.ts
vendored
14
types/graphql/subscription/subscribe.d.ts
vendored
@ -2,7 +2,7 @@ import Maybe from "../tsutils/Maybe";
|
||||
import { GraphQLSchema } from "../type/schema";
|
||||
import { DocumentNode } from "../language/ast";
|
||||
import { GraphQLFieldResolver } from "../type/definition";
|
||||
import { ExecutionResult } from "../execution/execute";
|
||||
import { ExecutionResult, ExecutionResultDataDefault } from "../execution/execute";
|
||||
|
||||
/**
|
||||
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
||||
@ -24,7 +24,7 @@ import { ExecutionResult } from "../execution/execute";
|
||||
*
|
||||
* Accepts either an object with named arguments, or individual arguments.
|
||||
*/
|
||||
export function subscribe(args: {
|
||||
export function subscribe<TData = ExecutionResultDataDefault>(args: {
|
||||
schema: GraphQLSchema;
|
||||
document: DocumentNode;
|
||||
rootValue?: any;
|
||||
@ -33,9 +33,9 @@ export function subscribe(args: {
|
||||
operationName?: Maybe<string>;
|
||||
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
|
||||
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
|
||||
}): Promise<AsyncIterator<ExecutionResult> | ExecutionResult>;
|
||||
}): Promise<AsyncIterator<ExecutionResult<TData>> | ExecutionResult<TData>>;
|
||||
|
||||
export function subscribe(
|
||||
export function subscribe<TData = ExecutionResultDataDefault>(
|
||||
schema: GraphQLSchema,
|
||||
document: DocumentNode,
|
||||
rootValue?: any,
|
||||
@ -44,7 +44,7 @@ export function subscribe(
|
||||
operationName?: Maybe<string>,
|
||||
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
|
||||
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>
|
||||
): Promise<AsyncIterator<ExecutionResult> | ExecutionResult>;
|
||||
): Promise<AsyncIterator<ExecutionResult<TData>> | ExecutionResult<TData>>;
|
||||
|
||||
/**
|
||||
* Implements the "CreateSourceEventStream" algorithm described in the
|
||||
@ -64,7 +64,7 @@ export function subscribe(
|
||||
* or otherwise separating these two steps. For more on this, see the
|
||||
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
||||
*/
|
||||
export function createSourceEventStream(
|
||||
export function createSourceEventStream<TData = ExecutionResultDataDefault>(
|
||||
schema: GraphQLSchema,
|
||||
document: DocumentNode,
|
||||
rootValue?: any,
|
||||
@ -72,4 +72,4 @@ export function createSourceEventStream(
|
||||
variableValues?: { [key: string]: any },
|
||||
operationName?: Maybe<string>,
|
||||
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>
|
||||
): Promise<AsyncIterable<any> | ExecutionResult>;
|
||||
): Promise<AsyncIterable<any> | ExecutionResult<TData>>;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user