Skip to content

Commit 2fd517e

Browse files
committed
Merge branch 'master' of https://github.com/christensenemc/graphql-relay-js into christensenemc-master
2 parents 373f2da + 1d4d3cc commit 2fd517e

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

src/mutation/__tests__/mutation.js

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

34+
const 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
const simpleMutationWithThunkFields = mutationWithClientMutationId({
3547
name: 'SimpleMutationWithThunkFields',
3648
inputFields: () => ({
@@ -79,6 +91,7 @@ const mutationType = new GraphQLObjectType({
7991
name: 'Mutation',
8092
fields: {
8193
simpleMutation,
94+
simpleMutationWithDescription,
8295
simpleMutationWithThunkFields,
8396
simplePromiseMutation,
8497
simpleRootValueMutation,
@@ -322,6 +335,26 @@ describe('mutationWithClientMutationId()', () => {
322335
kind: 'OBJECT',
323336
}
324337
},
338+
{
339+
name: 'simpleMutationWithDescription',
340+
args: [
341+
{
342+
name: 'input',
343+
type: {
344+
name: null,
345+
kind: 'NON_NULL',
346+
ofType: {
347+
name: 'SimpleMutationWithDescriptionInput',
348+
kind: 'INPUT_OBJECT'
349+
}
350+
},
351+
}
352+
],
353+
type: {
354+
name: 'SimpleMutationWithDescriptionPayload',
355+
kind: 'OBJECT',
356+
}
357+
},
325358
{
326359
name: 'simpleMutationWithThunkFields',
327360
args: [
@@ -388,5 +421,49 @@ describe('mutationWithClientMutationId()', () => {
388421
}
389422
});
390423
});
424+
425+
it('contains correct descriptions', async () => {
426+
const query = `{
427+
__schema {
428+
mutationType {
429+
fields {
430+
name
431+
description
432+
}
433+
}
434+
}
435+
}`;
436+
437+
return expect(await graphql(schema, query)).to.deep.equal({
438+
data: {
439+
__schema: {
440+
mutationType: {
441+
fields: [
442+
{
443+
name: 'simpleMutation',
444+
description: null
445+
},
446+
{
447+
name: 'simpleMutationWithDescription',
448+
description: 'Simple Mutation Description'
449+
},
450+
{
451+
name: 'simpleMutationWithThunkFields',
452+
description: null
453+
},
454+
{
455+
name: 'simplePromiseMutation',
456+
description: null
457+
},
458+
{
459+
name: 'simpleRootValueMutation',
460+
description: null
461+
}
462+
]
463+
}
464+
}
465+
}
466+
});
467+
});
391468
});
392469
});

src/mutation/mutation.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function resolveMaybeThunk<T>(thingOrThunk: Thunk<T>): T {
4949
*/
5050
type MutationConfig = {
5151
name: string,
52+
description?: string,
5253
inputFields: Thunk<GraphQLInputFieldConfigMap>,
5354
outputFields: Thunk<GraphQLFieldConfigMap<*, *>>,
5455
mutateAndGetPayload: mutationFn,
@@ -61,7 +62,13 @@ type MutationConfig = {
6162
export function mutationWithClientMutationId(
6263
config: MutationConfig
6364
): GraphQLFieldConfig<*, *> {
64-
const { name, inputFields, outputFields, mutateAndGetPayload } = config;
65+
const {
66+
name,
67+
description,
68+
inputFields,
69+
outputFields,
70+
mutateAndGetPayload
71+
} = config;
6572
const augmentedInputFields = () => ({
6673
...resolveMaybeThunk(inputFields),
6774
clientMutationId: {
@@ -87,6 +94,7 @@ export function mutationWithClientMutationId(
8794

8895
return {
8996
type: outputType,
97+
description,
9098
args: {
9199
input: {type: new GraphQLNonNull(inputType)}
92100
},

0 commit comments

Comments
 (0)