Skip to content
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

Design docs #923

Merged
merged 11 commits into from
Nov 29, 2016
Merged

Design docs #923

merged 11 commits into from
Nov 29, 2016

Conversation

helfer
Copy link
Contributor

@helfer helfer commented Nov 16, 2016

Initial stages of draft for proposed design docs process.

@@ -0,0 +1,29 @@
# Error handling - design proposal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file name is misspelled :]

@helfer
Copy link
Contributor Author

helfer commented Nov 17, 2016

@jbaxleyiii @tmeasday would be curious to get your thoughts about the error proposal. If you have feedback on design docs in general that would be useful, too.

Anyone else's feedback is of course welcome and appreciated as well!

@tmeasday
Copy link
Contributor

It seems reasonable. What do we thing RA should do? There seem to be 3 cases

  1. Error getting query, nothing in store
  2. Error getting query, partial (or full) results already in the store
  3. Error during query, which returns partial results.

Do we need to distinguish between those cases? It seems challenging if we are trying to include the errors on the standard data: {top, level, fields} object.

Copy link
Contributor

@stubailo stubailo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the right approach - I don't think we should make error handling much more complex. I agree that we should use partial results, but I think maybe we should still throw the error?

- universally compatible
- easy to understand and use
- compare the proposed solution with obvious alternatives and show that
- the proposed solution is better than its alternatives with respect to the Apollo vision.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also add some factors like:

  • this is the simplest way to solve the proposed problem
  • this should be in this package and not in a different package or a new one altogether

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like your first point is included in the comparison with alternatives. I'll add the second point.

PS: I actually had a more complete list, but I felt like it was getting too long. I'd say let's start simple and add more stuff later if we see that it's necessary.

# Error handling - design proposal

## Motivation
ApolloClient currently does not deal with errors very gracefully. When the server returns any error, Apollo Client will discard the result and call `observer.error`. With the recent addition of error paths in the standard `formatError` function of graphql-js, we have an opportunity to improve error handling and write partial results to the store.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call out "GraphQL errors" in particular. That is, errors that have a partial response and something in the errors field.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd link to the PR with this addition, and the RFC on the spec: graphql/graphql-spec#230


For errors of the first category, the server does not return any data that can be displayed to the user, only errors, so Apollo Client should call `observer.error` and not write data to the store.

For errors of the second category, the server returns data *and* errors, so there is data that can be displayed to the user and Apollo Client should call `observer.next` with `{ data, errors }`, and write as much of the result to the store as possible. Any `null` fields in `result.data` should not be written to the store if there is an error with a path corresponding to that field.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried that this will make error handling extremely cumbersome. Right now it's very easy to find out if something went wrong - you just look at the error.

To put it a different way - how will users of react-apollo get notified about the GraphQL error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how it would be any more complicated now? It's just the way the error gets delivered that's different, depending on the semantics of the error.


For errors of the second category, the server returns data *and* errors, so there is data that can be displayed to the user and Apollo Client should call `observer.next` with `{ data, errors }`, and write as much of the result to the store as possible. Any `null` fields in `result.data` should not be written to the store if there is an error with a path corresponding to that field.

Because initially not all servers will have support for error paths, a configuration option is necessary to tell Apollo Client to use the current default behavior - i.e. call `observer.error` and discard all data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the right approach. I feel like we should treat errors without path the same way we did before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same way as before = discard the result?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@helfer
Copy link
Contributor Author

helfer commented Nov 18, 2016

@stubailo I don't think error handling will be more cumbersome if GraphQL errors get delivered with the data. If the server returns data and errors, shouldn't you be able to pass both of those to the UI at the same time? If you call the next callback and the error callback separately, how can you be sure that these are associated? And which one do you call first? Will both of them re-render the component?

On second thought though, maybe we can avoid complexity in our code by just sending all errors through the errors callback and all data through the next callback. Is that what you're proposing?

@tmeasday I think we don't need to distinguish between 1 and 2, because that would make things complicated.

@tmeasday
Copy link
Contributor

@tmeasday I think we don't need to distinguish between 1 and 2, because that would make things complicated.

@helfer I guess it just depends on whether we want to make that data available in 2 (or 3).

@helfer
Copy link
Contributor Author

helfer commented Nov 29, 2016

@tmeasday I would say for the sake of simplicity we don't make that data available at the moment. If there's an error and no data is returned, then that's what you get from Apollo Client. One can always try to repeat that same query with noFetch turned on if you want to know what's in the store.

@helfer helfer merged commit 90a2823 into master Nov 29, 2016
@jbaxleyiii jbaxleyiii deleted the design-docs branch July 20, 2017 17:41
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants