Lighthouse: null return not being allowed

Created on 2 Nov 2019  路  3Comments  路  Source: nuwave/lighthouse

My schema has

type Query {
  me: User
}

And my me resolver is returning null if the user is not logging it. But I get this error

debugMessage: Cannot return null for non-nullable field User.id.

Shouldn't I be allowed to return null in this case?

I was able to circumvent this by creating a a custom type and returning it instead

type Query {    
    me: mePayload
}

type mePayload {
    user: User
}

This allows me to return null

question

Most helpful comment

Can you show us your User model type?

type User @model {
    id: ID! <--- is the reason probably
}

All 3 comments

Can you show us your User model type?

type User @model {
    id: ID! <--- is the reason probably
}

Are you returning null or are you returning a user without data?

I think the issue you are having is a combination of what @eriktisme and @joskfg said.

Make sure to return null from the me field, not an empty User.

Closing as this looks like expected behaviour.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sadhakbj picture sadhakbj  路  4Comments

caizhigang97 picture caizhigang97  路  3Comments

alexwhb picture alexwhb  路  4Comments

Leuloch picture Leuloch  路  3Comments

mikeerickson picture mikeerickson  路  3Comments