Skip to content

Commit 7312c84

Browse files
Add description field to mutationWithClientMutationId
1 parent deb4f5e commit 7312c84

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

src/mutation/__tests__/mutation.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ var simpleMutation = mutationWithClientMutationId({
3131
mutateAndGetPayload: () => ({result: 1})
3232
});
3333

34+
var simpleMutationWithDescription = mutationWithClientMutationId({
35+
name: 'SimpleMutationWithDescription',
36+
description: 'Simple Mutation Description',
37+
inputFields: {},
38+
outputFields: {
39+
result: {
40+
type: GraphQLInt
41+
}
42+
},
43+
mutateAndGetPayload: () => ({result: 1})
44+
});
45+
3446
var simpleMutationWithThunkFields = mutationWithClientMutationId({
3547
name: 'SimpleMutationWithThunkFields',
3648
inputFields: () => ({
@@ -61,6 +73,7 @@ var mutation = new GraphQLObjectType({
6173
name: 'Mutation',
6274
fields: {
6375
simpleMutation: simpleMutation,
76+
simpleMutationWithDescription: simpleMutationWithDescription,
6477
simpleMutationWithThunkFields: simpleMutationWithThunkFields,
6578
simplePromiseMutation: simplePromiseMutation
6679
}
@@ -285,6 +298,26 @@ describe('mutationWithClientMutationId()', () => {
285298
kind: 'OBJECT',
286299
}
287300
},
301+
{
302+
name: 'simpleMutationWithDescription',
303+
args: [
304+
{
305+
name: 'input',
306+
type: {
307+
name: null,
308+
kind: 'NON_NULL',
309+
ofType: {
310+
name: 'SimpleMutationWithDescriptionInput',
311+
kind: 'INPUT_OBJECT'
312+
}
313+
},
314+
}
315+
],
316+
type: {
317+
name: 'SimpleMutationWithDescriptionPayload',
318+
kind: 'OBJECT',
319+
}
320+
},
288321
{
289322
name: 'simpleMutationWithThunkFields',
290323
args: [
@@ -332,5 +365,44 @@ describe('mutationWithClientMutationId()', () => {
332365

333366
return expect(graphql(schema, query)).to.become({data: expected});
334367
});
368+
369+
it('contains correct descriptions', () => {
370+
var query = `{
371+
__schema {
372+
mutationType {
373+
fields {
374+
name
375+
description
376+
}
377+
}
378+
}
379+
}`;
380+
var expected = {
381+
__schema: {
382+
mutationType: {
383+
fields: [
384+
{
385+
name: 'simpleMutation',
386+
description: ''
387+
},
388+
{
389+
name: 'simpleMutationWithDescription',
390+
description: 'Simple Mutation Description'
391+
},
392+
{
393+
name: 'simpleMutationWithThunkFields',
394+
description: ''
395+
},
396+
{
397+
name: 'simplePromiseMutation',
398+
description: ''
399+
},
400+
]
401+
}
402+
}
403+
};
404+
405+
return expect(graphql(schema, query)).to.become({data: expected});
406+
});
335407
});
336408
});

src/mutation/mutation.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function resolveMaybeThunk<T>(thingOrThunk: T | () => T): T {
4545
*/
4646
type MutationConfig = {
4747
name: string,
48+
description?: string,
4849
inputFields: InputObjectConfigFieldMap,
4950
outputFields: GraphQLFieldConfigMap,
5051
mutateAndGetPayload: mutationFn,
@@ -58,6 +59,7 @@ export function mutationWithClientMutationId(
5859
config: MutationConfig
5960
): GraphQLFieldConfig {
6061
var {name, inputFields, outputFields, mutateAndGetPayload} = config;
62+
var description = config.description != null ? config.description : '';
6163
var augmentedInputFields = () => ({
6264
...resolveMaybeThunk(inputFields),
6365
clientMutationId: {
@@ -83,6 +85,7 @@ export function mutationWithClientMutationId(
8385

8486
return {
8587
type: outputType,
88+
description: description,
8689
args: {
8790
input: {type: new GraphQLNonNull(inputType)}
8891
},

0 commit comments

Comments
 (0)