-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Modern] Deferred queries #2194
Comments
Here's the approach I imagine:
|
Thank you for the detailed write-up @josephsavona! I have some questions though
If you add the node dependency on the fragment spread type, how do you know which one to fetch later? Will the generate id transform add the What if we put the responsibillity on the parent type instead? If I understand your suggestion the queries will roughly look like this:
However, the issue I see with this is that what if even requesting the id of the liveData object is expensive too? I imagine that pushing the fetching up to the parent node would allow for easier usage. However, as seen below the queries becomes more complex.
How do we handle network failures or server errors? |
I notice that this is in-progress @leebyron is there a plan to support For example wrt to the above query, client could manage the variable state to handle like so until
|
AFAIK this is actually already working, I haven't tested it though. I know that the runtime and compile is capable of handling some sort of deferred fragments at least. I plan to try it in my app within a few weeks. |
@edvinerikson Are there code examples of deferred fragments? |
Not what I know, though you can annotate a fragment whose type uses the Node interface. But you need to implement your own network interface that supports the batching request that Relay generates for deferred queries. You can have a look at the deferred tests if you want to see more about the annotation. https://github.com/facebook/relay/tree/475585b78db7690e4c7364d32a30b9b34cf31916/packages/relay-compiler/transforms/__tests__/fixtures/deferrable-fragment-transform |
cc @dwwoelfel |
For anybody trying to implement this You need to use Observable in your executeFunction of Network take this as an example #2174 (comment) |
I've managed to implemented it It's open source here: https://github.com/sibelius/relay-modern-network-deep-dive There is also a medium post about it: https://medium.com/@sibelius/relay-modern-network-deep-dive-ec187629dfd3 now we need to improve Relay official docs |
@sibelius thanks for sharing the awesome write up and the very clean and organized example code. I hope this can make its way into the public docs and we can start seeing use of this become more practical to integrate. Have you tried this over connections at all (when deferred query variables end up as lists)? I made it about this far a month or two ago based on the comments here and some digging in the Relay source code. I eventually ditched the solution because I was unable to get it to work when deferring through to “many” items — for instance deferring fields from nodes in a connection which was the main requirement for me. I was able to get partway through figuring out how to extract the proper variables to send with the queries, but eventually ran into a situation where obtaining the proper key for the variable was not possible (I don’t remember the exact reason, but could probably find out if someone from the core team wanted to help us continue to push forward here). My code has more application specific stuff in it, but seems functionally close to what you have ended up looking like this. Have you tried getting things working through connections? Somewhat related… for the time being, I tried using a It’d be really nice to use deferred queries instead of hacking it together. |
I have a @todo to implement it here https://github.com/sibelius/relay-modern-network-deep-dive/blob/master/src/5-deferrable-queries/batchRequestQuery.js#L20
So when you have a list you probably should fire N requests or use |
@sibelius yeah, using a |
there is no final solution of doing defer on GraphQL world |
Just read this great article telling us we can use To my big disappointment this does not seem to be the case. Can't find any documentation that talks about a
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This is being worked on here: #3121 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hello everyone!
I very recently started thinking about using deferred queries for making a progressive react app with Relay. My idea to use deferred queries for this is to be able to split data requirements the same way we can split react components. This is kind of possible by having query renderers.. but it quickly becomes very bloated and hard to work with.
From a conversation on Twitter I am creating this issue to track the progress and share thoughts on adding deferred queries into Relay Modern. I have myself started experimenting with it, so far I've only been working on a basic query transformer in the compiler.
I heard that you @leebyron actually are working on this internally right now. Is it possible for you to share your work and issues here on Github? I think it would be really good if this can be developed in the open behind some experimental/unstable flag (like React does).
It would also be very interesting to hear what thoughts the rest of the Relay team and others have on this! @josephsavona "confirmed" on Twitter that it is possible to solve. @wincent Maybe you have some ideas on this since you worked on it for Relay Classic.
I am imaging the relay compiler building these extra queries just like normal queries and have the runtime linking them together somehow. Or maybe it makes sense to introduce a list/tree on the concrete batch for deferred queries.
Main issues I see
I see some problems right now... I have not had time to dig into them yet though...
Variables
Figuring out what variables the deferred queries needs and does not need. Maybe we need some sort filtering of variables at runtime.
store selectors
Do we need to switch the selectors when starting to execute deferred queries or can Relay handle the initial selector including all fields from the deferred responses? Since the initial query response will miss those fields I assume Relay will throw errors about fields being undefined in the normalize phase.
Refetch containers / pagination containers
I don't know if this will be a problem.. but I have feeling these will require some extra logic around this.
The text was updated successfully, but these errors were encountered: