Skip to content

Commit

Permalink
Avoid null payload in mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jun 25, 2020
1 parent 74f57c9 commit 2a92bd9
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 2a92bd9

Please sign in to comment.