Cannot return null for non-nullable field
Closed this issue · 5 comments
Hi,
I'm new with GraphQL and maybe doing something wrong.
I have this query:
getTapeLanguages(tapeId:112830){
languageId
name
createdAt
}
Query type is something like this
'type' => Type::listOf($types->getOutput(Language::class))
And resolver return this
$tape->getLanguages()->toArray()
While getLanguages()->count() is equal to 1 and getLanguages()->current()->getLanguageId() return 12 (expected value) I get this error:
Cannot return null for non-nullable field Language.languageId.
What I'm doing wrong? Resolver could return a Language Collection as array and is it supported?
Regards
The default resolver provided by this lib should be able to resolve getters of objects in an array. But it seems you are not giving an array but a collection of some sort. Maybe an ArrayObject ?
You should double check that and either write your own resolver or return a real array.
See
I will check but put in this
return [$tape->getLanguages()->current()]
instead of
return $tape->getLanguages()->toArray()
Also output same error.
Thanks!
This is a bit of a blind guess, but you should try validating your schema (in your unit tests) with the \GraphQL\Type\Schema::assertValid()
method. Just to be sure your schema makes sense.
My bad, I was missing
GraphQL::setDefaultFieldResolver(new DefaultFieldResolver());
Regards