@@ -57,12 +57,24 @@ var simplePromiseMutation = mutationWithClientMutationId({
57
57
mutateAndGetPayload : ( ) => Promise . resolve ( { result : 1 } )
58
58
} ) ;
59
59
60
+ var simpleRootValueMutation = mutationWithClientMutationId ( {
61
+ name : 'SimpleRootValueMutation' ,
62
+ inputFields : { } ,
63
+ outputFields : {
64
+ result : {
65
+ type : GraphQLInt
66
+ }
67
+ } ,
68
+ mutateAndGetPayload : ( params , context , { rootValue} ) => ( rootValue )
69
+ } ) ;
70
+
60
71
var mutation = new GraphQLObjectType ( {
61
72
name : 'Mutation' ,
62
73
fields : {
63
74
simpleMutation : simpleMutation ,
64
75
simpleMutationWithThunkFields : simpleMutationWithThunkFields ,
65
- simplePromiseMutation : simplePromiseMutation
76
+ simplePromiseMutation : simplePromiseMutation ,
77
+ simpleRootValueMutation : simpleRootValueMutation
66
78
}
67
79
} ) ;
68
80
@@ -145,6 +157,26 @@ describe('mutationWithClientMutationId()', () => {
145
157
return expect ( graphql ( schema , query ) ) . to . become ( expected ) ;
146
158
} ) ;
147
159
160
+ it ( 'can access rootValue' , ( ) => {
161
+ var query = `
162
+ mutation M {
163
+ simpleRootValueMutation(input: {clientMutationId: "abc"}) {
164
+ result
165
+ clientMutationId
166
+ }
167
+ }
168
+ ` ;
169
+ var expected = {
170
+ data : {
171
+ simpleRootValueMutation : {
172
+ result : 1 ,
173
+ clientMutationId : 'abc'
174
+ }
175
+ }
176
+ } ;
177
+ return expect ( graphql ( schema , query , { result : 1 } ) ) . to . become ( expected ) ;
178
+ } ) ;
179
+
148
180
describe ( 'introspection' , ( ) => {
149
181
it ( 'contains correct input' , ( ) => {
150
182
var query = `{
@@ -325,6 +357,26 @@ describe('mutationWithClientMutationId()', () => {
325
357
kind : 'OBJECT' ,
326
358
}
327
359
} ,
360
+ {
361
+ name : 'simpleRootValueMutation' ,
362
+ args : [
363
+ {
364
+ name : 'input' ,
365
+ type : {
366
+ name : null ,
367
+ kind : 'NON_NULL' ,
368
+ ofType : {
369
+ name : 'SimpleRootValueMutationInput' ,
370
+ kind : 'INPUT_OBJECT'
371
+ }
372
+ } ,
373
+ }
374
+ ] ,
375
+ type : {
376
+ name : 'SimpleRootValueMutationPayload' ,
377
+ kind : 'OBJECT' ,
378
+ }
379
+ } ,
328
380
]
329
381
}
330
382
}
0 commit comments