Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Revert 27cc028 (#1983) (#2432)
Browse files Browse the repository at this point in the history
* Revert 27cc028 (#1983)

* Changelog adjustments

* Grammer fix

* Preserve some test changes
  • Loading branch information
hwillson authored Sep 28, 2018
1 parent 17704e1 commit 969460f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
10 changes: 10 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
provider value is reset to the previous value it had after its children are
walked. <br/>
[@mitchellhamilton](https://github.com/mitchellhamilton) in [#2304](https://github.com/apollographql/react-apollo/pull/2304)
- Revert: <br/>
When a query failed on the first result, the query result `data` was being
returned as `undefined`. This behavior has been changed so that `data` is
returned as an empty object. This makes checking for data (e.g.
instead of `data && data.user` you can just check `data.user`) and
destructring (e.g. `{ data: { user } }`) easier. **Note:** this could
potentially hurt applications that are relying on a falsey check of `data`
to see if any query errors have occurred. A better (and supported) way to
check for errors is to use the result `errors` property. <br/>
[#1983](https://github.com/apollographql/react-apollo/pull/1983)

## 2.2.1 (September 26, 2018)

Expand Down
11 changes: 4 additions & 7 deletions src/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface QueryResult<TData = any, TVariables = OperationVariables>
// I'm aware of. So intead we enforce checking for data
// like so result.data!.user. This tells TS to use TData
// XXX is there a better way to do this?
data: TData | {};
data: TData | undefined;
error?: ApolloError;
loading: boolean;
networkStatus: NetworkStatus;
Expand Down Expand Up @@ -391,12 +391,9 @@ export default class Query<TData = any, TVariables = OperationVariables> extends
if (loading) {
Object.assign(data.data, this.previousData, currentResult.data);
} else if (error) {
const lastResult = this.queryObservable!.getLastResult();
if (lastResult) {
Object.assign(data, {
data: lastResult.data,
});
}
Object.assign(data, {
data: (this.queryObservable!.getLastResult() || {}).data,
});
} else {
const { fetchPolicy } = this.queryObservable!.options;
const { partialRefetch } = this.props;
Expand Down
1 change: 0 additions & 1 deletion test/client/Query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ describe('Query component', () => {
return null;
}
catchAsyncError(done, () => {
expect(result.data).toEqual({});
expect(result.error).toEqual(new Error('Network error: error occurred'));
done();
});
Expand Down
6 changes: 2 additions & 4 deletions test/client/getDataFromTree.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,9 @@ describe('SSR', () => {

class CurrentUserQuery extends Query<Data> {}

const hasOwn = Object.prototype.hasOwnProperty;

const WrappedElement = () => (
<CurrentUserQuery query={query}>
{({ data, loading }: { data: Data; loading: boolean }) => (
{({ data, loading }) => (
<div>{loading || !data ? 'loading' : data.currentUser!.firstName}</div>
)}
</CurrentUserQuery>
Expand Down Expand Up @@ -1291,7 +1289,7 @@ describe('SSR', () => {

const Element = (props: { id: string }) => (
<CurrentUserQuery query={query} ssr={false} variables={props}>
{({ data, loading }: { data: Data; loading: boolean }) => (
{({ data, loading }) => (
<div>{loading || !data ? 'loading' : data.currentUser!.firstName}</div>
)}
</CurrentUserQuery>
Expand Down

0 comments on commit 969460f

Please sign in to comment.