-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
fetchQuery results not being added to store cache #29
Comments
fetchQuery does not insert the record in the store but only in the recordsource. To insert a record in the Store it is necessary to manage the retain function of the environment. |
Ahh gotcha. Does that mean there is no way to default to loading these values from the cache? And you can only use |
fetchQuery data is deleted after the garbage collector is run ... @sibelius can you indicate where the retain function is documented and how it should be used in combination with the fetchQuery? |
Interesting. I've been playing about with this, and see that you can write something like
and then I see data is retained in the store. Problem is, I then want to be able to fallback to the cache data if I'm offline, which is what the react-relay-offline QueryRenderer does nicely. Is there a way using the library of replicating this logic? I tried using |
I can't understand your use case, it looks like you're completely recreating the queryrenderer |
I'd like to be able to do exactly that - recreate the use-cache-if-offline functionality from the query renderer but using the imperative |
Not necessarily a bad idea, I'm curious about how you're using the library / offline to see if there's anything to improve in react-relay-offline or recommend other solutions.
|
You seem to be dealing with the same theme as my example project: https://github.com/morrys/offline-examples/blob/master/relay/nextjs/relay/withData.tsx |
This use case is possible with new relay hooks on experimental package |
Our use case: We have one app query that we run imperatively using As a new user to this library I would have expected the lib's fetchQuery to work the same way as QueryRenderer in this sense. But now the different behaviour seems like more of a Relay quirk, so can see why you haven't implemented it.
Cool thanks. What specifically will this be addressing @sibelius - adding imperative requests to the cache by default? |
I imagine that fetchQuery is not supposed to manage the Store as it is a direct request on the network. What seems strange to me is that the lookup gives null. For your use case the correct procedure is as follows: online: fetchQuery, retain Obviously the lookup returns null when the garbage collector has eliminated the references in the store. During the offline state the garbage collector is disabled. |
OK cool - well good to know I was on the right lines. Perhaps there's something I've done wrong - will keep looking. Thanks! |
Hi morrys, I've also been following this issue, and I was wondering that wouldn't the unmount Thanks! |
hi @octodhruv, It is necessary to make the dispose to allow the garbage collector to clean the store and avoid growing keeping invalid data. In react-relay-offline I added the TTL in the queries and a default value for all the queries that are executed (10 minutes). This means that even if a query has been disposed, the garbage collector does not delete it until the TTL expires. Furthermore, when the application is offline I disabled the garbage collector. |
It's quite possible this is because of another library I'm using (or I've set something up wrong), but would at least like to check my usage appears OK...
I'm finding caching and Async storage persistance is generally working great 👍
If I print out
environment._store._cache.data
I can see the queries I have visited successfully being added. The one exception to this is a query that I call imperatively usingfetchQuery
, which is causing me problems.I create my Network/Environment like this:
I am then using
fetchQuery
like this:Is there any setup here for react-relay-offline I've missed? Is there anything I could debug here that might point me in the right direction?
The text was updated successfully, but these errors were encountered: