Skip to content

Commit 69ed240

Browse files
authored
Merge pull request #140 from chentsulin/deprecationReason
allow deprecationReason in mutationWithClientMutationId
2 parents a3500b8 + 34d5fc5 commit 69ed240

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

src/mutation/__tests__/mutation.js

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ const simpleMutationWithDescription = mutationWithClientMutationId({
4343
mutateAndGetPayload: () => ({result: 1})
4444
});
4545

46+
const simpleMutationWithDeprecationReason = mutationWithClientMutationId({
47+
name: 'SimpleMutationWithDeprecationReason',
48+
inputFields: {},
49+
outputFields: {
50+
result: {
51+
type: GraphQLInt
52+
}
53+
},
54+
mutateAndGetPayload: () => ({result: 1}),
55+
deprecationReason: 'Just because'
56+
});
57+
4658
const simpleMutationWithThunkFields = mutationWithClientMutationId({
4759
name: 'SimpleMutationWithThunkFields',
4860
inputFields: () => ({
@@ -92,6 +104,7 @@ const mutationType = new GraphQLObjectType({
92104
fields: {
93105
simpleMutation,
94106
simpleMutationWithDescription,
107+
simpleMutationWithDeprecationReason,
95108
simpleMutationWithThunkFields,
96109
simplePromiseMutation,
97110
simpleRootValueMutation,
@@ -145,7 +158,7 @@ describe('mutationWithClientMutationId()', () => {
145158
});
146159
});
147160

148-
it('Supports thunks as input and output fields', async () => {
161+
it('supports thunks as input and output fields', async () => {
149162
const query = `
150163
mutation M {
151164
simpleMutationWithThunkFields(input: {
@@ -465,5 +478,60 @@ describe('mutationWithClientMutationId()', () => {
465478
}
466479
});
467480
});
481+
482+
it('contains correct deprecation reasons', async () => {
483+
const query = `{
484+
__schema {
485+
mutationType {
486+
fields(includeDeprecated: true) {
487+
name
488+
isDeprecated
489+
deprecationReason
490+
}
491+
}
492+
}
493+
}`;
494+
495+
return expect(await graphql(schema, query)).to.deep.equal({
496+
data: {
497+
__schema: {
498+
mutationType: {
499+
fields: [
500+
{
501+
name: 'simpleMutation',
502+
isDeprecated: false,
503+
deprecationReason: null
504+
},
505+
{
506+
name: 'simpleMutationWithDescription',
507+
isDeprecated: false,
508+
deprecationReason: null
509+
},
510+
{
511+
name: 'simpleMutationWithDeprecationReason',
512+
isDeprecated: true,
513+
deprecationReason: 'Just because',
514+
},
515+
{
516+
name: 'simpleMutationWithThunkFields',
517+
isDeprecated: false,
518+
deprecationReason: null
519+
},
520+
{
521+
name: 'simplePromiseMutation',
522+
isDeprecated: false,
523+
deprecationReason: null
524+
},
525+
{
526+
name: 'simpleRootValueMutation',
527+
isDeprecated: false,
528+
deprecationReason: null
529+
}
530+
]
531+
}
532+
}
533+
}
534+
});
535+
});
468536
});
469537
});

src/mutation/mutation.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function resolveMaybeThunk<T>(thingOrThunk: Thunk<T>): T {
5050
type MutationConfig = {
5151
name: string,
5252
description?: string,
53+
deprecationReason?: string,
5354
inputFields: Thunk<GraphQLInputFieldConfigMap>,
5455
outputFields: Thunk<GraphQLFieldConfigMap<*, *>>,
5556
mutateAndGetPayload: mutationFn,
@@ -65,6 +66,7 @@ export function mutationWithClientMutationId(
6566
const {
6667
name,
6768
description,
69+
deprecationReason,
6870
inputFields,
6971
outputFields,
7072
mutateAndGetPayload
@@ -95,6 +97,7 @@ export function mutationWithClientMutationId(
9597
return {
9698
type: outputType,
9799
description,
100+
deprecationReason,
98101
args: {
99102
input: {type: new GraphQLNonNull(inputType)}
100103
},

0 commit comments

Comments
 (0)