Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c24898b

Browse files
Improve mutationWithClientId types with generics (#389)
1 parent bad0dd2 commit c24898b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

‎src/mutation/mutation.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
ThunkObjMap,
1515
} from 'graphql';
1616

17-
type MutationFn = (object: any, ctx: any, info: GraphQLResolveInfo) => unknown;
17+
type MutationFn<TInput = any,TOutput=unknown,TContext=any>=(object: TInput, ctx: TContext, info: GraphQLResolveInfo) => TOutput;
1818

1919
/**
2020
* A description of a mutation consumable by mutationWithClientMutationId
@@ -30,22 +30,22 @@ type MutationFn = (object: any, ctx: any, info: GraphQLResolveInfo) => unknown;
3030
* input field, and it should return an Object with a key for each
3131
* output field. It may return synchronously, or return a Promise.
3232
*/
33-
interface MutationConfig {
33+
interface MutationConfig<TInput=any,TOutput=unknown,TContext=any> {
3434
name: string;
3535
description?: string;
3636
deprecationReason?: string;
3737
extensions?: GraphQLFieldExtensions<any, any>;
3838
inputFields: ThunkObjMap<GraphQLInputFieldConfig>;
39-
outputFields: ThunkObjMap<GraphQLFieldConfig<any,any>>;
40-
mutateAndGetPayload: MutationFn;
39+
outputFields: ThunkObjMap<GraphQLFieldConfig<TOutput,TContext>>;
40+
mutateAndGetPayload: MutationFn<TInput,TOutput,TContext>;
4141
}
4242

4343
/**
4444
* Returns a GraphQLFieldConfig for the mutation described by the
4545
* provided MutationConfig.
4646
*/
47-
export function mutationWithClientMutationId(
48-
config: MutationConfig,
47+
export function mutationWithClientMutationId<TInput=any,TOutput=unknown,TContext=any>(
48+
config: MutationConfig<TInput,TOutput,TContext>,
4949
): GraphQLFieldConfig<unknown, unknown> {
5050
const { name, inputFields, outputFields, mutateAndGetPayload } = config;
5151
const augmentedInputFields = () => ({

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /