Skip to content

Commit

Permalink
Avoid null payload in mutation (#268)
Browse files Browse the repository at this point in the history
Fixes #192
  • Loading branch information
IvanGoncharov committed Jun 25, 2020
1 parent 74f57c9 commit 0595d8b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/mutation/__tests__/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,26 @@ describe('mutationWithClientMutationId()', () => {
});
});

it('supports mutations returning null', async () => {
const query = `
mutation M {
simpleRootValueMutation(input: {clientMutationId: "abc"}) {
result
clientMutationId
}
}
`;

expect(await graphql(schema, query, null)).to.deep.equal({
data: {
simpleRootValueMutation: {
result: null,
clientMutationId: 'abc',
},
},
});
});

describe('introspection', () => {
it('contains correct input', async () => {
const query = `
Expand Down
8 changes: 4 additions & 4 deletions src/mutation/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ export function mutationWithClientMutationId(
},
resolve: (_, { input }, context, info) =>
Promise.resolve(mutateAndGetPayload(input, context, info)).then(
(payload) => {
payload.clientMutationId = input.clientMutationId;
return payload;
},
(payload) => ({
...payload,
clientMutationId: input.clientMutationId,
}),
),
};
}

0 comments on commit 0595d8b

Please sign in to comment.