Using this example repo: https://github.com/prisma/photonjs/tree/master/examples/typescript/graphql-auth
I experience an error when I call the createDraft mutation.
Error: Cannot return null for non-nullable field Mutation.createDraft.
at completeValue (/Users/sjensen/dev/prisma-simple-demo/node_modules/graphql/execution/execute.js:579:13)
at /Users/sjensen/dev/prisma-simple-demo/node_modules/graphql/execution/execute.js:511:16
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
I found that I can fix it by adding an async await in the resolver but it doesn't make any sense to me why this would work.
Before:
t.field('createDraft', {
type: 'Post',
args: {
title: stringArg(),
content: stringArg({ nullable: true })
},
resolve: (parent, { title, content }, ctx) => {
const userId = getUserId(ctx);
return ctx.photon.posts.create({
data: {
title,
content,
published: false,
author: { connect: { id: userId } }
}
});
}
});
After:
This fixes it- first awaiting the response, saving it as the variable draft and then returning that works just fine.
t.field('createDraft', {
type: 'Post',
args: {
title: stringArg(),
content: stringArg({ nullable: true })
},
resolve: async (parent, { title, content }, ctx) => {
const userId = getUserId(ctx);
const draft = await ctx.photon.posts.create({
data: {
title,
content,
published: false,
author: { connect: { id: userId } }
}
});
return draft;
}
});
@CaptainChemist : I am unable to reproduce this issue, can you try the same without the author connect part? My hunch is that the first request failed for you (by returning null or equivalent and hence the mentioned GraphQL error) and the second request succeeded.
Can you please try to send multiple requests with the same non-await setup?
@pantharshit00 Please try to reproduce this one, and if you are unable to please close this issue.
@CaptainChemist Thanks for raising this one, I was unable to reproduce this, Harshit will try that again and if we fail, we will close this issue. Please re-open a new issue anyways if the problem persists for you.
Thanks 馃檶
Note that this example has been moved to https://github.com/prisma/prisma-examples/blob/prisma2/typescript/graphql-auth/src/resolvers/Mutation.ts
I used the init flow and I am unable to reproduce this now.

version: [email protected], binary version: bbbeff6f84b408e534ebd866bfd378748e6d6611
Thanks guys, this now works great for me. 馃檶
Most helpful comment
Thanks guys, this now works great for me. 馃檶