Errors should not be shared between queries
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
We're currently experimenting with Relay's new (experimental) approach to handling queries that contain errors. We've enabled both the `ENABLE_FIELD_ERROR_HANDLING` and `ENABLE_FIELD_ERROR_HANDLING_THROW_BY_DEFAULT` feature flag.
Overall it works really nicely and error-handling-clients are definitely the future. There is one major caveat though that still needs to be addressed in our opinion: Errors being shared between queries / fragments.
> Note: I'm well aware that this is all experimental at the moment, but I still wanted to provide some early feedback from outside of Meta.
## What's the issue?
Let's imagine we have a page-level query like this:
```tsx
usePreloadedQuery(graphql`
query PageQuery($id: ID!) {
productById(id: $id) {
...BuyBox
}
}`,
queryRef
);
```
and we also have another query that is only invoked, once you scroll down the page:
```tsx
useLazyLoadQuery(graphql`
query LazyPageQuery($id: ID!) {
productById(id: $id) {
...Reviews
}
}`,
{ id }
);
```
Currently, if the `PageQuery` is able to fetch the `productById` without an error, but the `LazyPageQuery` contains an error for the `productById` field, both queries will throw an error, since they both read out the errornous `productById` field.
This is pretty bad, because a temporary failure in the `LazyPageQuery` could take down other, previously successful, queries like the `PageQuery`.
### Reproduction
https://github.com/tobias-tengler/relay-errorhandling-error
## Expected behavior
I would expect that errors aren't shared between queries and fragments. In the above example I would expect only the `useLazyLoadQuery` hook to throw, since the error is associated with the `productById` field, which is read out by that hook. The `usePreloadedQuery` also reads out the `productById` field, but its query was able to resolve the `productById`, so it doesn't make sense to also propagate the error there and potentially kill an entire page, if the query itself completed without errors before.
In the same vain, fields that are associated with errors shouldn't update the store. Errornous fields are nulled and just how you would not want to share the error between queries, you also wouldn't want the `productById` field to suddenly become null in other places that were able to read it out without an error.
Contributor guide
Assessment
This issue has not been assessed yet.