Skip to content

Commit 2a92bd9

Browse files
committed
Avoid null payload in mutation
Fixes graphql#192
1 parent 74f57c9 commit 2a92bd9

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/mutation/__tests__/mutation.js

+20
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,26 @@ describe('mutationWithClientMutationId()', () => {
206206
});
207207
});
208208

209+
it('supports mutations returning null', async () => {
210+
const query = `
211+
mutation M {
212+
simpleRootValueMutation(input: {clientMutationId: "abc"}) {
213+
result
214+
clientMutationId
215+
}
216+
}
217+
`;
218+
219+
expect(await graphql(schema, query, null)).to.deep.equal({
220+
data: {
221+
simpleRootValueMutation: {
222+
result: null,
223+
clientMutationId: 'abc',
224+
},
225+
},
226+
});
227+
});
228+
209229
describe('introspection', () => {
210230
it('contains correct input', async () => {
211231
const query = `

src/mutation/mutation.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ export function mutationWithClientMutationId(
9898
},
9999
resolve: (_, { input }, context, info) =>
100100
Promise.resolve(mutateAndGetPayload(input, context, info)).then(
101-
(payload) => {
102-
payload.clientMutationId = input.clientMutationId;
103-
return payload;
104-
},
101+
(payload) => ({
102+
...payload,
103+
clientMutationId: input.clientMutationId,
104+
}),
105105
),
106106
};
107107
}

0 commit comments

Comments
 (0)