Skip to content

Commit

Permalink
Improve mutationWithClientId types with generics (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
noghartt authored Mar 27, 2024
1 parent bad0dd2 commit c24898b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/mutation/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
ThunkObjMap,
} from 'graphql';

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

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

/**
* Returns a GraphQLFieldConfig for the mutation described by the
* provided MutationConfig.
*/
export function mutationWithClientMutationId(
config: MutationConfig,
export function mutationWithClientMutationId<TInput = any, TOutput = unknown, TContext = any>(
config: MutationConfig<TInput, TOutput, TContext>,
): GraphQLFieldConfig<unknown, unknown> {
const { name, inputFields, outputFields, mutateAndGetPayload } = config;
const augmentedInputFields = () => ({
Expand Down

0 comments on commit c24898b

Please sign in to comment.