mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +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:
committed by
Mohamed Hegazy
parent
3a151309f6
commit
deb7d8beaf
Vendored
+10
-5
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user