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.
@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!
Most helpful comment
Ok, I was assuming that you wanted to return the data from the resolver. If you pass the
infoit 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.