spidey icon indicating copy to clipboard operation
spidey copied to clipboard

Nested queries are not executed

Open davidalcoba opened this issue 7 years ago • 4 comments

Hi @tinrab ,

First at all, thanks for your articles at outcrawl.com, I am personally learning a lot from them.

However I have a couple of doubts:

  • Why do you take Order model out from the code generation tool? You mention that " more control is needed for the Order mode" but I don't understand why.
  • I am not able to retrieve any Order when querying Accounts, it always returns an empty array. I have already checked that all data from creation of Accounts, Products and Orders is in the database. Also, I have noticed that method Account_orders is never called.

I have read the docs from https://gqlgen.com/getting-started/ where the binding rules are described:

  • If there is a property with that name and type, use it
  • If there is a method with that name and type, use it
  • Otherwise, add it to the Resolvers interface. This is the magic.

So I am assuming that since model Account contains a property []Order it tries to resolve it without calling to Account_orders, resulting always in an empty array. Also I am totally confused on the example provided in gqlgen tutorial: both User and Todo are not pregenerated (but User would generate the same model, while Todo uses a String instead of an Object for property UserID), and the Todo_user method is added automatically to the Resolvers interface, something that is not happening in the Spidey example.

There is something that I'm missing...

Thanks!

davidalcoba avatar Jun 25 '18 11:06 davidalcoba

There was an update to gqlgen tool that breaks this project. I don't know exactly what happened, but I fixed it now on 0f3f94a. I've manually created Order model, because it was impossible to get its products in one RPC call. That's all I can remember, but I might've made a dumb mistake.

tinrab avatar Jun 25 '18 12:06 tinrab

Thanks @tinrab , however I think that explicitly calling to method Account_orders within Query_accounts is not completely right. I was under the impression that code generated by gqlgen was also responsible for looking for the right resolver when needed, so each resolver only fetched the minimum data.

In the code from the tutorial (https://github.com/vektah/gqlgen-tutorials/tree/master/gettingstarted) in graph.go, the method Query_todos is not calling to Todo_user, it is the generated middleware which is doing the magic instead.

davidalcoba avatar Jun 25 '18 13:06 davidalcoba

Yes, but now the Todo_user method isn't even generated for the Resolvers struct. Same with Spidey, only top level queries are generated: Query_accounts and Query_products. Account_orders is missing.

tinrab avatar Jun 25 '18 13:06 tinrab

Maybe I've messed up with different gqlgen versions, but method Todo_user is still added to the Resolverswhen running go generate. I will try again with a cleaner workspace

davidalcoba avatar Jun 25 '18 15:06 davidalcoba