Skip to content

Commit adb856f

Browse files
committed
mutation input and output fields should support thunks
1 parent 87d865e commit adb856f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/mutation/mutation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import type {
2525
type mutationFn = (object: Object, info: GraphQLResolveInfo) => Object |
2626
(object: Object, info: GraphQLResolveInfo) => Promise<Object>;
2727

28+
function resolveMaybeThunk<T>(thingOrThunk: T | () => T): T {
29+
return typeof thingOrThunk === 'function' ? thingOrThunk() : thingOrThunk;
30+
}
31+
2832
/**
2933
* A description of a mutation consumable by mutationWithClientMutationId
3034
* to create a GraphQLFieldConfig for that mutation.
@@ -55,13 +59,13 @@ export function mutationWithClientMutationId(
5559
): GraphQLFieldConfig {
5660
var {name, inputFields, outputFields, mutateAndGetPayload} = config;
5761
var augmentedInputFields = {
58-
...inputFields,
62+
...resolveMaybeThunk(inputFields),
5963
clientMutationId: {
6064
type: new GraphQLNonNull(GraphQLString)
6165
}
6266
};
6367
var augmentedOutputFields = {
64-
...outputFields,
68+
...resolveMaybeThunk(outputFields),
6569
clientMutationId: {
6670
type: new GraphQLNonNull(GraphQLString)
6771
}

0 commit comments

Comments
 (0)