Skip to content

Commit 0dca219

Browse files
mutationWithClientMutationId: pass through extensions (#333)
1 parent 54c22ae commit 0dca219

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

src/mutation/__tests__/mutation-test.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,36 @@ describe('mutationWithClientMutationId()', () => {
202202
});
203203
});
204204

205+
it('generates correct types', () => {
206+
const description = 'Some Mutation Description';
207+
const deprecationReason = 'Just because';
208+
const extensions = Object.freeze({});
209+
210+
const someMutationField = mutationWithClientMutationId({
211+
name: 'SomeMutation',
212+
description,
213+
deprecationReason,
214+
extensions,
215+
inputFields: {},
216+
outputFields: {},
217+
mutateAndGetPayload: dummyResolve,
218+
});
219+
220+
expect(someMutationField).to.include({
221+
description,
222+
deprecationReason,
223+
extensions,
224+
});
225+
});
226+
205227
it('generates correct types', () => {
206228
const someMutation = mutationWithClientMutationId({
207229
name: 'SomeMutation',
208-
description: 'Some Mutation Description',
209230
inputFields: {},
210231
outputFields: {
211232
result: { type: GraphQLInt },
212233
},
213234
mutateAndGetPayload: dummyResolve,
214-
deprecationReason: 'Just because',
215235
});
216236

217237
const schema = wrapInSchema({ someMutation });
@@ -223,8 +243,7 @@ describe('mutationWithClientMutationId()', () => {
223243
}
224244
225245
type Mutation {
226-
"""Some Mutation Description"""
227-
someMutation(input: SomeMutationInput!): SomeMutationPayload @deprecated(reason: "Just because")
246+
someMutation(input: SomeMutationInput!): SomeMutationPayload
228247
}
229248
230249
type SomeMutationPayload {

src/mutation/mutation.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {
22
GraphQLFieldConfig,
3+
GraphQLFieldExtensions,
34
GraphQLInputFieldConfigMap,
45
GraphQLFieldConfigMap,
56
GraphQLResolveInfo,
@@ -31,10 +32,11 @@ export type MutationFn = (
3132
export interface MutationConfig {
3233
name: string;
3334
description?: string;
35+
deprecationReason?: string;
36+
extensions?: GraphQLFieldExtensions<any, any>;
3437
inputFields: Thunk<GraphQLInputFieldConfigMap>;
3538
outputFields: Thunk<GraphQLFieldConfigMap<any, any>>;
3639
mutateAndGetPayload: MutationFn;
37-
deprecationReason?: string;
3840
}
3941

4042
/**

src/mutation/mutation.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type MutationConfig = {|
4444
name: string,
4545
description?: string,
4646
deprecationReason?: string,
47+
extensions?: { [name: string]: mixed },
4748
inputFields: Thunk<GraphQLInputFieldConfigMap>,
4849
outputFields: Thunk<GraphQLFieldConfigMap<any, any>>,
4950
mutateAndGetPayload: MutationFn,
@@ -56,14 +57,7 @@ type MutationConfig = {|
5657
export function mutationWithClientMutationId(
5758
config: MutationConfig,
5859
): GraphQLFieldConfig<mixed, mixed> {
59-
const {
60-
name,
61-
description,
62-
deprecationReason,
63-
inputFields,
64-
outputFields,
65-
mutateAndGetPayload,
66-
} = config;
60+
const { name, inputFields, outputFields, mutateAndGetPayload } = config;
6761
const augmentedInputFields = () => ({
6862
...resolveMaybeThunk(inputFields),
6963
clientMutationId: {
@@ -89,8 +83,9 @@ export function mutationWithClientMutationId(
8983

9084
return {
9185
type: outputType,
92-
description,
93-
deprecationReason,
86+
description: config.description,
87+
deprecationReason: config.deprecationReason,
88+
extensions: config.extensions,
9489
args: {
9590
input: { type: new GraphQLNonNull(inputType) },
9691
},

0 commit comments

Comments
 (0)