Debugging "Cannot return null for non-nullable type"


#1

I’ve been trying to debug this and is stuck and need some pointers where to look next.

Basically we have this in datamodel.prisma

type X {
    id: ID! @id
    ys: [Y!]! @relation(onDelete: CASCADE)
}

type Y {
    id: ID! @id
    z: Z! @relation(onDelete: CASCADE)
}

type Z {
    id: ID! @id
}

When we get “Cannot return null for non-nullable type” we find that in a GraphQL response X.ys === null and the error object looks something like this:

"Cannot return null for non-nullable type (line 3, column 5):\n   z {\n    ^"

According to datamodel.prisma neither X.ys nor X.ys.z should be nullable. So that is puzzling how either got into such a state. I’m not entirely clear on whether it is the Ys or the Z that is null, but I’m guessing the Ys.

Now where it gets even more puzzling is when I look at the generated schema.graphql I get:

type X {
    id: ID! @id
    ys: [Y!] @relation(onDelete: CASCADE)
}

Her ys is nullable?!?

I’ve looked at our custom resolvers, inputs, enums etc. and nothing are related to these particular models.

The broken X’s are created by using nested creation of both Y and Z and I would assume that the entire transaction would fail and roll back, but it appears that X’s are created while the subparts are not.

Any ideas where to look next?