New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve the `AuthPayload` type, why? #1737

Closed
steida opened this Issue Jan 26, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@steida

steida commented Jan 26, 2018

I don't get https://github.com/graphcool/prisma/blob/03c8957c2dd8239c0aca1119ff06a3c7204bc889/examples/auth/src/auth.js#L5

Why AuthPayload have to be resolved? It looks like it works without it.

@AlexanderChen1989

This comment has been minimized.

Contributor

AlexanderChen1989 commented Feb 27, 2018

same question

@nikolasburk

This comment has been minimized.

Member

nikolasburk commented Mar 9, 2018

Thanks for opening this issue @steida! There was in fact a bug which I just fixed, because the AuthPayload resolver was never included in the resolvers that was passed to the GraphQLServer.

To answer your question though why it's necessary. The short version is that in this example, it actually doesn't matter because the use case is so simple and there are no relations on the User type. However, if you have a relation on the User type and would query data from that relation via the AuthPayload type, the related data couldn't be resolved.

I created an example that extends the auth example here. You can run the example per instructions in the README. To observe the behaviour that I described above, you first need to signup with a mutation, e.g.:

mutation {
  signup(email: "nikolas@graph.cool", password: "asd") {
    token
    user {
      id
    }
  }
}

Then create a Post for that User (against the Prisma API):

mutation {
  createPost(data: {
    title: "ASD"
    author: {
      connect: {
        id: "__USER_ID__"
      }
    }
  }) {
    id
  }
}

Now, you can observe the behaviour by sending a login mutation in which you're querying posts of the User via the AuthPayload type:

mutation {
  login(email: "nikolas@graph.cool", password: "asd") {
    token
    user {
      id
      email
      posts {
        id
        title
      }
    }
  }
}

If you add the AuthPayload resolver to the resolvers object again (here), then the login mutation successfully returns the Post. Otherwise it returns the error message: "Cannot return null for non-nullable field User.posts."

To learn more about why that is be sure to check out this blog post: GraphQL Server Basics: Demystifying the info Argument in GraphQL Resolvers

@nikolasburk nikolasburk closed this Mar 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment