Skip to content

Commit 8c9c898

Browse files
committed
adding test case for thunk fields on mutation inputFields and outputFields
1 parent a9765f1 commit 8c9c898

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/mutation/__tests__/mutation.js

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

34+
var simpleMutationWithThunkFields = mutationWithClientMutationId({
35+
name: 'SimpleMutationWithThunkFields',
36+
inputFields: () => ({
37+
inputData: {
38+
type: GraphQLInt
39+
}
40+
}),
41+
outputFields: () => ({
42+
result: {
43+
type: GraphQLInt
44+
}
45+
}),
46+
mutateAndGetPayload: ({ inputData }) => ({result: inputData})
47+
});
48+
3449
var simplePromiseMutation = mutationWithClientMutationId({
3550
name: 'SimplePromiseMutation',
3651
inputFields: {},
@@ -46,6 +61,7 @@ var mutation = new GraphQLObjectType({
4661
name: 'Mutation',
4762
fields: {
4863
simpleMutation: simpleMutation,
64+
simpleMutationWithThunkFields: simpleMutationWithThunkFields,
4965
simplePromiseMutation: simplePromiseMutation
5066
}
5167
});
@@ -89,6 +105,26 @@ describe('mutationWithClientMutationId()', () => {
89105
return expect(graphql(schema, query)).to.become(expected);
90106
});
91107

108+
it('Supports thunks as input and output fields', () => {
109+
var query = `
110+
mutation M {
111+
simpleMutationWithThunkFields(input: {inputData: 1234, clientMutationId: "abc"}) {
112+
result
113+
clientMutationId
114+
}
115+
}
116+
`;
117+
var expected = {
118+
data: {
119+
simpleMutationWithThunkFields: {
120+
result: 1234,
121+
clientMutationId: 'abc'
122+
}
123+
}
124+
};
125+
return expect(graphql(schema, query)).to.become(expected);
126+
});
127+
92128
it('supports promise mutations', () => {
93129
var query = `
94130
mutation M {
@@ -249,6 +285,26 @@ describe('mutationWithClientMutationId()', () => {
249285
kind: 'OBJECT',
250286
}
251287
},
288+
{
289+
name: 'simpleMutationWithThunkFields',
290+
args: [
291+
{
292+
name: 'input',
293+
type: {
294+
name: null,
295+
kind: 'NON_NULL',
296+
ofType: {
297+
name: 'SimpleMutationWithThunkFieldsInput',
298+
kind: 'INPUT_OBJECT'
299+
}
300+
},
301+
}
302+
],
303+
type: {
304+
name: 'SimpleMutationWithThunkFieldsPayload',
305+
kind: 'OBJECT',
306+
}
307+
},
252308
{
253309
name: 'simplePromiseMutation',
254310
args: [

0 commit comments

Comments
 (0)