Prisma-client-js: Problem with the typescript auth demo project.

Created on 20 Jun 2019  路  5Comments  路  Source: prisma/prisma-client-js

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;
      }
    });
bu1-repro-available kinbug

Most helpful comment

Thanks guys, this now works great for me. 馃檶

All 5 comments

@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 馃檶

I used the init flow and I am unable to reproduce this now.

image

version: [email protected], binary version: bbbeff6f84b408e534ebd866bfd378748e6d6611

Thanks guys, this now works great for me. 馃檶

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samrith-s picture samrith-s  路  3Comments

emroot picture emroot  路  4Comments

divyenduz picture divyenduz  路  3Comments

williamluke4 picture williamluke4  路  3Comments

MichalLytek picture MichalLytek  路  3Comments