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
Nested Resolvers #475
Comments
I'm not sure I completely follow, but how would it know where the @parent post is from? Why can't this be in its own Resolver class? It looks like you're trying to shove two entities in the same Resolver, when they should really be two separate classes |
@krislefeber I just want to make possible query like this one: {
Level1(id: "someId") {
level1Field
Level2(optionalParam: "optional") {
level2Field
Level3(optionalParam: "optional") {
level3Field
}
}
}
} It is perfectly fine, to have it in separate resolver classes... but is it possible to nest it like this? |
You would end up with something like this. First define the classes. Notice that there are no decorators on the object references. We instead add the mappings to that object in the Resolver.
In the first resolver, add the initial query for a search by id. We also add the getLevel2Property function, which tells graphql how to connect the two objects.
In the level 2 resolver, we need to add the mapping to Level3. Once again, the code inside getLevel3Property can be whatever you want.
Let me know if that makes sense. Thanks |
@krislefeber Thanks for help, that did work! I actually tried similar approach before but had some errors, so I thought it won't work like that. Turns out it does, so I must have messed something up. 🤔 Anyway - thanks again, I appreciate it. 🙂 |
How to get Level1 input fields like (id: "someId") in Level2 resolver?
|
@m7rlin, couldn't you just pass that input in again? |
@krislefeber if I pass input again like so:
it will work but I don't want duplication and maybe later on I will add another input at Level2.
On Level2 resolver I can access parent object. I don't know any other solution. It will be nice to have custom decorator which will achieve similar solution. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm submitting a...
Current behavior
No possibility to create nested resolvers (or no info in the docs).
Expected behavior
Possibility to make nested resolvers (and/or appropriate info in the docs).
Minimal reproduction of the problem with instructions
In the docs we have example how to make
Posts
property resolver onAuthor
Resolver. But we don't have any info, how to make nested resolver on those posts. For example - we'd like to lazy fetch (only when someone requests the field) posts statistics. Seems like this isn't possible at the moment?So, is this possible in any way? If not, would a feature request like this be acceptable?
What is the motivation / use case for changing the behavior?
One of the biggest advantages of graphQL is lazy fetching nested fields (graph-like connections). Current implementation of graphQL decorators probably doesn't allow creating nested resolvers.
Edit: Found similar question here: #162, but no luck with an answer yet. :(
The text was updated successfully, but these errors were encountered: