diff --git a/src/mutation/__tests__/mutation.js b/src/mutation/__tests__/mutation.js index 20beacc..55d42b4 100644 --- a/src/mutation/__tests__/mutation.js +++ b/src/mutation/__tests__/mutation.js @@ -57,12 +57,24 @@ var simplePromiseMutation = mutationWithClientMutationId({ mutateAndGetPayload: () => Promise.resolve({result: 1}) }); +var simpleRootValueMutation = mutationWithClientMutationId({ + name: 'SimpleRootValueMutation', + inputFields: {}, + outputFields: { + result: { + type: GraphQLInt + } + }, + mutateAndGetPayload: (params, context, {rootValue}) => (rootValue) +}); + var mutation = new GraphQLObjectType({ name: 'Mutation', fields: { simpleMutation: simpleMutation, simpleMutationWithThunkFields: simpleMutationWithThunkFields, - simplePromiseMutation: simplePromiseMutation + simplePromiseMutation: simplePromiseMutation, + simpleRootValueMutation: simpleRootValueMutation } }); @@ -145,6 +157,26 @@ describe('mutationWithClientMutationId()', () => { return expect(graphql(schema, query)).to.become(expected); }); + it('can access rootValue', () => { + var query = ` + mutation M { + simpleRootValueMutation(input: {clientMutationId: "abc"}) { + result + clientMutationId + } + } + `; + var expected = { + data: { + simpleRootValueMutation: { + result: 1, + clientMutationId: 'abc' + } + } + }; + return expect(graphql(schema, query, {result: 1})).to.become(expected); + }); + describe('introspection', () => { it('contains correct input', () => { var query = `{ @@ -325,6 +357,26 @@ describe('mutationWithClientMutationId()', () => { kind: 'OBJECT', } }, + { + name: 'simpleRootValueMutation', + args: [ + { + name: 'input', + type: { + name: null, + kind: 'NON_NULL', + ofType: { + name: 'SimpleRootValueMutationInput', + kind: 'INPUT_OBJECT' + } + }, + } + ], + type: { + name: 'SimpleRootValueMutationPayload', + kind: 'OBJECT', + } + }, ] } } diff --git a/src/mutation/mutation.js b/src/mutation/mutation.js index 5fae43e..c5478d3 100644 --- a/src/mutation/mutation.js +++ b/src/mutation/mutation.js @@ -22,8 +22,9 @@ import type { GraphQLResolveInfo } from 'graphql'; -type mutationFn = (object: Object, info: GraphQLResolveInfo) => Object | - (object: Object, info: GraphQLResolveInfo) => Promise; +type mutationFn = + (object: Object, ctx: Object, info: GraphQLResolveInfo) => Object | + (object: Object, ctx: Object, info: GraphQLResolveInfo) => Promise; function resolveMaybeThunk(thingOrThunk: T | () => T): T { return typeof thingOrThunk === 'function' ? thingOrThunk() : thingOrThunk;