Skip to content

Commit

Permalink
improve mutationWithClientId types with generics
Browse files Browse the repository at this point in the history
  • Loading branch information
noghartt committed Dec 5, 2022
1 parent 3796e09 commit 7dac92b
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, TOutput>(
config: MutationConfig<TInput, TOutput>,
): GraphQLFieldConfig<unknown, unknown> {
const { name, inputFields, outputFields, mutateAndGetPayload } = config;
const augmentedInputFields = () => ({
Expand Down

0 comments on commit 7dac92b

Please sign in to comment.