Skip to content

Commit

Permalink
Drop support for PromiseLike object in mutation resolvers (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Dec 7, 2021
1 parent 691a529 commit 3cb8324
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
47 changes: 47 additions & 0 deletions src/mutation/__tests__/mutation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,53 @@ describe('mutationWithClientMutationId()', () => {
});
});

/* FIXME fail because of this https://github.com/graphql/graphql-js/pull/3243#issuecomment-919510590
it.only('JS specific: handles `then` as field name', async () => {
const someMutation = mutationWithClientMutationId({
name: 'SomeMutation',
inputFields: {},
outputFields: {
result: {
type: new GraphQLObjectType({
name: 'Payload',
fields: {
then: { type: GraphQLString },
},
}),
},
},
mutateAndGetPayload() {
return {
then() {
return new Date(0);
}
};
},
});
const schema = wrapInSchema({ someMutation });
const source = `
mutation {
someMutation(input: {clientMutationId: "abc"}) {
clientMutationId
result { then }
}
}
`;
expect(await graphql({ schema, source })).to.deep.equal({
data: {
someMutation: {
clientMutationId: 'abc',
result: {
then: '',
},
},
},
});
});
*/

it('can access rootValue', () => {
const someMutation = mutationWithClientMutationId({
name: 'SomeMutation',
Expand Down
4 changes: 1 addition & 3 deletions src/mutation/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import type {
Thunk,
} from 'graphql';

import isPromise from 'graphql/jsutils/isPromise';

type MutationFn = (object: any, ctx: any, info: GraphQLResolveInfo) => mixed;

function resolveMaybeThunk<T>(thingOrThunk: Thunk<T>): T {
Expand Down Expand Up @@ -90,7 +88,7 @@ export function mutationWithClientMutationId(
resolve: (_, { input }, context, info) => {
const { clientMutationId } = input;
const payload = mutateAndGetPayload(input, context, info);
if (isPromise(payload)) {
if (payload instanceof Promise) {
return payload.then(injectClientMutationId);
}
return injectClientMutationId(payload);
Expand Down

0 comments on commit 3cb8324

Please sign in to comment.