Prisma1: prisma query not returning all type properties

Created on 29 May 2019  路  5Comments  路  Source: prisma/prisma1

Describe the bug

prisma queries are omitting fields

I'm trying to query for a user

const user = await ctx.db.query.user({
   where: { email }
});

prisma gives me back a user object but it doesn't have the permissions property on it so it's throwing an error.

Error: Cannot return null for non-nullable field User.permissions.

My mutation expects for a User type to be returned

signin(email: String!, password: String!): User!

and my type looks like the following

type User {
  id: ID!
  name: String!
  email: String!
  password: String!
  resetToken: String
  resetTokenExpiry: String
  store: Store
  permissions: [Permission!]!
}

The object prisma returns to me looks like this

{ id: '5cedfc7602743900070ba914',
  name: 'test ',
  email: '[email protected]',
  password: 'lsjfdslfj',
  resetToken: null,
  resetTokenExpiry: null }

Expected behavior

I'd expect prisma to return me an object w/ all the properties described on the User type.

kinquestion areapi

Most helpful comment

Ok, I was assuming that you wanted to return the data from the resolver. If you pass the info it guarantees that we are not overfetching.

In order to fetch all the field that you need, you will need to pass a custom info object.

const user = await ctx.db.query.user(
  {
    where: { email }
  },
  `
    { id name  permission { id } }
`
);

All 5 comments

@MaxwellGover

Since you are using prisma-binding you will need to pass the GraphQL info object.

{
    user: (parent, args, ctx, info) => {
        const user = await ctx.db.query.user({
            where: { email }
        }, info);
}

If you are not using graphql, please use prisma client instead of bindings

@pantharshit00 Passing the info object actually causes even less properties to be returned on the user object. For example, password field is then missing so can't do any validation. I'll look into using prisma client tho.

@pantharshit00 Is there an example of how to set this up?

Ok, I was assuming that you wanted to return the data from the resolver. If you pass the info it guarantees that we are not overfetching.

In order to fetch all the field that you need, you will need to pass a custom info object.

const user = await ctx.db.query.user(
  {
    where: { email }
  },
  `
    { id name  permission { id } }
`
);

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ragnorc picture ragnorc  路  3Comments

hoodsy picture hoodsy  路  3Comments

thomaswright picture thomaswright  路  3Comments

AlessandroAnnini picture AlessandroAnnini  路  3Comments

marktani picture marktani  路  3Comments