From 3cb83249487cecdfa4636bfb7286a6fe5b07ae32 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Tue, 7 Dec 2021 22:25:50 +0200 Subject: [PATCH] Drop support for PromiseLike object in mutation resolvers (#364) --- src/mutation/__tests__/mutation-test.js | 47 +++++++++++++++++++++++++ src/mutation/mutation.js | 4 +-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/mutation/__tests__/mutation-test.js b/src/mutation/__tests__/mutation-test.js index 6ee2332..93bee42 100644 --- a/src/mutation/__tests__/mutation-test.js +++ b/src/mutation/__tests__/mutation-test.js @@ -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', diff --git a/src/mutation/mutation.js b/src/mutation/mutation.js index 2a62a39..2156b9e 100644 --- a/src/mutation/mutation.js +++ b/src/mutation/mutation.js @@ -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(thingOrThunk: Thunk): T { @@ -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);