I'm having a little bit more complex data structure resulting in a deeply nested graph. Right now I'm always fetching/reloading through root queries. However I think this is not the best way since it always requires the server to resolve the whole tree.
Is it possible to fetch / reload additional data/edges of sub edges in an nested graph in a second request without traversing the whole tree?
If yes how?
Eg: I have a
RootQuery Spaces
+ ... Other Layers
+ Project
+ Edge Tasks
+ Edge SubTasks
+ Edge Assigned User
Showing the Project list I'm not loading Tasks on initial request. If the user opens a Project I'd like to lacy load the tasks of only this project, without reloading the parent/root or the whole tree starting from the RootQuery.
Short answer: No, you can't query data that is not listed as a field of your root query type definition.
Long answer:
Although this is not possible without adding a field to your root query, you can achieve the behaviour you are looking for with only adding a tasks
query with a parameter that is the Project id. Then in your client, while you query the projects
, don't ask for their tasks edge, rather just send a separate query tasks(projectId: ID)
when you need it.
In apollo's GitHunt example, they are doing the same thing to query for each repo's comments list, and even prefetch the data when the user hovers over the repo's link. That is of course, semi eager behaviour rather than lazy so you can make your own choices there.
GraphQL's future features will enable you to @stream
the list of task to the client when they are ready, and also @defer
any field you wish to continue without. Your scenario would possibly have a better solution that does not require second query to be sent.
For more info look into lee's talk here: https://youtu.be/ViXL0YQnioU?t=12m50s