laravel-graphql
laravel-graphql copied to clipboard
How to do my custom Resolver of a field?
I have a list of products associated to each category, I have defined categories as a Type other than Product. The resolver that believes if it runs but does not send me the data.
the function resolveCategoryField not is send my data. HelpMe Please.
You should rename 'category' field to 'categories' :
...
'categories'=>[
'type' => Type::listOf(GraphQL::type('Category'))
],
Or write this code in the resolver function:
protected function resolveCategoriesField($root,$args)
{
// you may have some code here...
return $root->categories; // this relationship must be defined in the product model
}