laravel-graphql
laravel-graphql copied to clipboard
what is the difference between return type listOf() and GraphQL?
public function type() { return Type::listOf(GraphQL::type('User')); }
public function type() { return GraphQL::type('User')); }
- With the former you can return
User:where(…)->get()
(i.e. a collection) - with the latter only
User::where()->firstOrFail()
(i.e.. only a single model)
Makes sense?
I got an error when using listOf()
with User::findOrFail($args['id'])
. The error message was
User Error: expected iterable, but did not find one for field Query
So, we have to use User::where('id',$args['id'])->get()
instead of User::findOrFail($args['id'])
when using listOf()
method
Thanks @mfn
@pramonoagung Note that there is no reason to use listOf()
when only ever returning at most one model.