tinrab / spidey

A Microservices and GraphQL based online store
MIT License
372 stars 59 forks source link

Nested queries are not executed #3

Open davidalcoba opened 6 years ago

davidalcoba commented 6 years ago

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:

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

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!

tinrab commented 6 years ago

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.

davidalcoba commented 6 years ago

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.

tinrab commented 6 years ago

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.

davidalcoba commented 6 years ago

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