I’ve the following schema
type Employee {
id: UUID!
createdAt: Time!
updatedAt: Time!
lastActivity: Activity
}
type Activity {
id: UUID!
createdAt: Time!
updatedAt: Time!
}
extend type Query {
Myself: Employee!
}
The lastActivity
may or may not be present of course, but when querying it from my client it throws the following error
{
"errors": [
{
"message": "the requested element is null which the schema does not allow",
"path": [
"Myself",
"lastActivity",
"createdAt"
]
}
],
"data": {
"Myself": {
"id": "257d9db3-118e-4728-9e6b-ef28e87b4907",
"lastActivity": null,
"__typename": "Employee"
}
}
}
What I send from the client is the following
query Myself {
Myself {
id
lastActivity {
id
action
createdAt
}
organization {
id
name
slug
}
}
}
I’m not sure to understand why the query isn’t satisfied, because Activity
in the context of Employee
is indeed nullable. I tried changing the Activity
type itself to make everything nullable and it solved the problem, but it’s only in this context that I want it nullable, not other ones. What I receive right now is actually what I expected.
What am I doing wrong here?
PS: I use Apollo on the client side with Vite and GQLGen with Golang on the server side, if that changes anything.
1
I read that error message as saying a
lastActivity
exists, but itscreatedAt
time is incorrectly null. When a field error is reported the nearest nullable ancestor of the failing field becomesnull
in the response data.4 mins ago