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

Commit

Permalink
Fixes loading state true for skipped queries (#190)
Browse files Browse the repository at this point in the history
* create failling test case

* fix loading state on skipped queries and mutability of defaults
  • Loading branch information
James Baxley authored Sep 5, 2016
1 parent 626dbb7 commit fe7926b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
33 changes: 16 additions & 17 deletions src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,22 @@ export default function graphql(
const { reduxRootKey } = this.client;
const queryOptions = this.calculateOptions(this.props);
const fragments = calculateFragments(queryOptions.fragments);
const { variables, forceFetch } = queryOptions;
let queryData = defaultQueryData as any;
const { variables, forceFetch, skip } = queryOptions as QueryOptions;

let queryData = assign({}, defaultQueryData) as any;
queryData.variables = variables;
if (skip) queryData.loading = false;

queryData.refetch = (vars) => this.client.query({
query: document,
variables: vars,
});

queryData.fetchMore = (opts) => {
opts.query = document;
return this.client.query(opts);
};

if (!forceFetch) {
try {
const result = readQueryFromStore({
Expand All @@ -340,21 +353,7 @@ export default function graphql(
fragmentMap: createFragmentMap(fragments),
});

const refetch = (vars) => {
return this.client.query({
query: document,
variables: vars,
});
};

const fetchMore = (opts) => {
opts.query = document;
return this.client.query(opts);
};

queryData = assign({
errors: null, loading: false, variables, refetch, fetchMore,
}, result);
queryData = assign(queryData, { errors: null, loading: false }, result);
} catch (e) {/* tslint:disable-line */}
}

Expand Down
1 change: 1 addition & 0 deletions test/react-web/client/graphql/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ describe('queries', () => {
queryExecuted = true;
}
render() {
expect(this.props.data.loading).to.be.false;
return null;
}
};
Expand Down
1 change: 1 addition & 0 deletions test/react-web/client/graphql/shared-operations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ describe('shared opertations', () => {
queryExecuted = true;
}
render() {
expect(this.props.data.loading).to.be.false;
return null;
}
};
Expand Down
2 changes: 1 addition & 1 deletion test/react-web/client/libraries/redux.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('redux integration', () => {
if (!value) return;

expect(value).to.equal(variables.name);
if (nextProps.data.loading) return;
if (nextProps.data.loading || !nextProps.data.allPeople) return;

expect(nextProps.data.loading).to.be.false;
expect(nextProps.data.allPeople).to.deep.equal(data.allPeople);
Expand Down

0 comments on commit fe7926b

Please sign in to comment.