Skip to content

Commit 3cb8324

Browse files
Drop support for PromiseLike object in mutation resolvers (#364)
1 parent 691a529 commit 3cb8324

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/mutation/__tests__/mutation-test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,53 @@ describe('mutationWithClientMutationId()', () => {
147147
});
148148
});
149149

150+
/* FIXME fail because of this https://github.com/graphql/graphql-js/pull/3243#issuecomment-919510590
151+
it.only('JS specific: handles `then` as field name', async () => {
152+
const someMutation = mutationWithClientMutationId({
153+
name: 'SomeMutation',
154+
inputFields: {},
155+
outputFields: {
156+
result: {
157+
type: new GraphQLObjectType({
158+
name: 'Payload',
159+
fields: {
160+
then: { type: GraphQLString },
161+
},
162+
}),
163+
},
164+
},
165+
mutateAndGetPayload() {
166+
return {
167+
then() {
168+
return new Date(0);
169+
}
170+
};
171+
},
172+
});
173+
const schema = wrapInSchema({ someMutation });
174+
175+
const source = `
176+
mutation {
177+
someMutation(input: {clientMutationId: "abc"}) {
178+
clientMutationId
179+
result { then }
180+
}
181+
}
182+
`;
183+
184+
expect(await graphql({ schema, source })).to.deep.equal({
185+
data: {
186+
someMutation: {
187+
clientMutationId: 'abc',
188+
result: {
189+
then: '',
190+
},
191+
},
192+
},
193+
});
194+
});
195+
*/
196+
150197
it('can access rootValue', () => {
151198
const someMutation = mutationWithClientMutationId({
152199
name: 'SomeMutation',

src/mutation/mutation.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import type {
1313
Thunk,
1414
} from 'graphql';
1515

16-
import isPromise from 'graphql/jsutils/isPromise';
17-
1816
type MutationFn = (object: any, ctx: any, info: GraphQLResolveInfo) => mixed;
1917

2018
function resolveMaybeThunk<T>(thingOrThunk: Thunk<T>): T {
@@ -90,7 +88,7 @@ export function mutationWithClientMutationId(
9088
resolve: (_, { input }, context, info) => {
9189
const { clientMutationId } = input;
9290
const payload = mutateAndGetPayload(input, context, info);
93-
if (isPromise(payload)) {
91+
if (payload instanceof Promise) {
9492
return payload.then(injectClientMutationId);
9593
}
9694
return injectClientMutationId(payload);

0 commit comments

Comments
 (0)