Skip to content

Commit 90a2823

Browse files
authored
Merge pull request #923 from apollostack/design-docs
Design docs
2 parents d14621f + 6c43b14 commit 90a2823

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

DESIGNS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Apollo Design Documents
2+
3+
A design document is a way to communicate to others what the intent behind a certain feature/solution is. In the Apollo community we use them to facilitate discussions and reach agreement about important design decisions.
4+
5+
Design docs are written with the purpose of helping community members and contributors understand design proposals and judge them on their merits.
6+
7+
A good design document should:
8+
- state the problem that is being solved as clearly as possible
9+
- explain why the problem should be solved in this package, and not a different one (or possibly a new one)
10+
- show that the proposed solution fits in with the stated vision for Apollo Client
11+
- incrementally adoptable
12+
- universally compatible
13+
- easy to understand and use
14+
- compare the proposed solution with obvious alternatives and show that
15+
- the proposed solution is better than its alternatives with respect to the Apollo vision.
16+
17+
For an example of a design doc, see [Apollo Errors](./designs/errors.md).

designs/errors.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Error handling - design proposal
2+
3+
## Motivation
4+
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](https://github.com/graphql/graphql-js/pull/561) and the [proposal to add it to the spec](https://github.com/facebook/graphql/pull/230), we have an opportunity to improve error handling and write partial results to the store when the server provides one.
5+
6+
## Proposed feature / solution
7+
As far as Apollo Client is concerned, errors can be roughly divided into two categories:
8+
9+
1. Errors that make the entire result unusable
10+
2. Errors that make only part of the result unusable
11+
12+
An example for the first kind of error is when the server cannot be reached, or the server does not return valid JSON. An example for the second kind of error is when the server returned a partial result and a GraphQL error because it could not reach a backend service.
13+
14+
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.
15+
16+
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.error` 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.
17+
18+
Note: We call `observer.error` with the partial result instead of `observer.next` in order to make error handling stay as close as possible to the current behavior.
19+
20+
Because initially not all servers will have support for error paths, the current behavior (discarding all data) will be used when errors without path are encountered in the result.
21+
22+
## Implementation steps / changes needed
23+
1. Call `observer.error` and discard the result if not all errors have an error path
24+
2. Write result to store if at least partial data is available. Ignore fields if there's an error with a path to that field.
25+
3. Call `observer.next` with data and errors if there is at least a partial result.
26+
27+
## Changes to the external API
28+
* ApolloClient will have a new configuration option to keep using the current error behavior. Initially this could be on by default to provide a non-breaking change & smooth transition.
29+
* `observer.error` will now receive data as well if is a partial result
30+
* Partial results are now written to the store in the presence of GraphQL errors.
31+

0 commit comments

Comments
 (0)