-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Prevent persisting of errors from queries #72
Comments
Hi @matt-dalton, |
Hmm interesting...are you suggesting using this in some middleware when returning an error request? How would I "override" the logic in react-relay-offline that currently persists the state? |
This feature is useful when starting the application to verify / migrate persistent data. Another possibility is to use the mutateKeys / mutateValues functions to modify the behavior when reading / writing keys / values from the store https://morrys.github.io/wora/docs/cache-persist#cache-options |
Thanks for the pointers - really helpful. As well as react-relay-offline, we use a few pieces of middleware from |
react-relay-offline works differently from cacheMiddleware in fact it uses the relay store to manage the offline and in your case it is relay that modifies the store and react-relay-offline does not modify its behavior. If you cannot manage this exception in the network layer, you could consider clearing the store when starting the application. |
Yeah exactly - I wasn't suggesting using it. Was just saying this is an example of what we're looking for.
Hmm...our application performance is very dependent on booting from a persisted store. I guess we could persist when an error on a query has been received, and then clear the store on the next app load. But this might happen reasonably often, so would be a shame to lose the performance benefit for everything. |
maybe this thread can help you facebook/relay#1913 |
That's an interesting thread, and does touch on some of the underlying issues we sometimes have. We could implement some of the suggestions there (custom error schemas, making most fields nullable), which would help. However, if there was an error, we'd still have a problem, as this would be persisted. Unless I'm missing something? |
What I mean is to manage a logic of this type on the client side at the network level: fetch(
'/api/graphql',
{
method: 'POST',
body: JSON.stringify({
query: operation.text,
variables,
}),
},
).then(response => response.json()).then(responeJson => {
if (responeJson.errors) {
throw new Error(...)
}
console.log(responeJson)
return responeJson
});
} |
Ahhh so if an error is thrown in the network layer, react-relay-offline will avoid updating the store? That's the simple (and probably obvious) thing I was missing |
There might already be some smart solution to this in the library, but I've not been able to find anything on it yet.
We use React Native and persist state to Async Storage. Unfortunately, we're still on an older version of react-relay-offline (1.1.0) so not sure if this question has been resolved later on.
The problem flow is:
To me it would make sense to either:
Are there any nice solutions to this built into the library? Or is this something we should implement?
The text was updated successfully, but these errors were encountered: