Skip to content

N+1 Problem with ListTransformers #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lorado opened this issue Aug 5, 2018 · 2 comments
Closed

N+1 Problem with ListTransformers #26

lorado opened this issue Aug 5, 2018 · 2 comments

Comments

@lorado
Copy link
Contributor

lorado commented Aug 5, 2018

Hi there! Thank you very much for this awesome package! I am new to GraphQL and tried before a package from rebing, but you package seems to be more fresh and your features are simple crazy awesome!

When I tried your library, it was important to me, that all relationships loads eager. As you provide transformers, I didn't even need to write a query for testing this out - nice! BUT exactly there I found a bug.

I would like to fix it, but I don't feel much confidence with your code, as I see at it since 1 hour. So I just describe the problem ;)

In file StudioNet\GraphQL\Support\Transformer\Transformer.php in method getResolverCallable() you tries to guess the relations with $this->guessWithRelations($definition, $fields). For ViewTransformation (and all other mutation-transformations) it works perfectly. Relations are guessed correctly, as fields at the root contains exactly the structure of queried type.

But to query data via ListTransformer, we have to use query like this:

{
   items {...}
}

So in getResolverCallable() the variable $fields contains that, what was given (same as in example).
When you then call $this->guessWithRelations($definition, $fields), variable $fields contains wrong attributes, better saying it contains correct attributes, but inside items{...}. So the guessWithRelations() guesses, there are no relations at all, because it checks only items field.

I know, you have a TODO there (Improve this checker). If you wish, I could try to improve it.

P.s. Child-relations are also not guessed.

@lorado
Copy link
Contributor Author

lorado commented Aug 5, 2018

Actually I tried to solve it by myself 🤣

What do you think? Can we merge it?

@cmizzi
Copy link
Contributor

cmizzi commented Sep 11, 2018

Done !

@cmizzi cmizzi closed this as completed Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants