Skip to content
This repository has been archived by the owner on Feb 10, 2019. It is now read-only.

How to do my custom Resolver of a field? #372

Open
yosoyjp opened this issue Aug 28, 2018 · 1 comment
Open

How to do my custom Resolver of a field? #372

yosoyjp opened this issue Aug 28, 2018 · 1 comment

Comments

@yosoyjp
Copy link

yosoyjp commented Aug 28, 2018

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.

captura de pantalla de 2018-08-28 07-54-59
captura de pantalla de 2018-08-28 07-58-18

the function resolveCategoryField not is send my data.
HelpMe Please.

@mohammad-fouladgar
Copy link
Contributor

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
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants