Skip to content

Commit 0f54efb

Browse files
committed
added a test for rootValue and updated mutationFn
1 parent 427d32d commit 0f54efb

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

src/mutation/__tests__/mutation.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,24 @@ var simplePromiseMutation = mutationWithClientMutationId({
5757
mutateAndGetPayload: () => Promise.resolve({result: 1})
5858
});
5959

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+
6071
var mutation = new GraphQLObjectType({
6172
name: 'Mutation',
6273
fields: {
6374
simpleMutation: simpleMutation,
6475
simpleMutationWithThunkFields: simpleMutationWithThunkFields,
65-
simplePromiseMutation: simplePromiseMutation
76+
simplePromiseMutation: simplePromiseMutation,
77+
simpleRootValueMutation: simpleRootValueMutation
6678
}
6779
});
6880

@@ -145,6 +157,26 @@ describe('mutationWithClientMutationId()', () => {
145157
return expect(graphql(schema, query)).to.become(expected);
146158
});
147159

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+
148180
describe('introspection', () => {
149181
it('contains correct input', () => {
150182
var query = `{
@@ -325,6 +357,26 @@ describe('mutationWithClientMutationId()', () => {
325357
kind: 'OBJECT',
326358
}
327359
},
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+
},
328380
]
329381
}
330382
}

src/mutation/mutation.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import type {
2222
GraphQLResolveInfo
2323
} from 'graphql';
2424

25-
type mutationFn = (object: Object, info: GraphQLResolveInfo) => Object |
26-
(object: Object, info: GraphQLResolveInfo) => Promise<Object>;
25+
type mutationFn =
26+
(object: Object, ctx: Object, info: GraphQLResolveInfo) => Object |
27+
(object: Object, ctx: Object, info: GraphQLResolveInfo) => Promise<Object>;
2728

2829
function resolveMaybeThunk<T>(thingOrThunk: T | () => T): T {
2930
return typeof thingOrThunk === 'function' ? thingOrThunk() : thingOrThunk;

0 commit comments

Comments
 (0)