diff --git a/src/graphql.tsx b/src/graphql.tsx index 63632dff3d..f5dabed099 100644 --- a/src/graphql.tsx +++ b/src/graphql.tsx @@ -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({ @@ -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 */} } diff --git a/test/react-web/client/graphql/queries.tsx b/test/react-web/client/graphql/queries.tsx index 38731539ca..0a708cc1a5 100644 --- a/test/react-web/client/graphql/queries.tsx +++ b/test/react-web/client/graphql/queries.tsx @@ -432,6 +432,7 @@ describe('queries', () => { queryExecuted = true; } render() { + expect(this.props.data.loading).to.be.false; return null; } }; diff --git a/test/react-web/client/graphql/shared-operations.tsx b/test/react-web/client/graphql/shared-operations.tsx index d75274047f..16f9565368 100644 --- a/test/react-web/client/graphql/shared-operations.tsx +++ b/test/react-web/client/graphql/shared-operations.tsx @@ -186,6 +186,7 @@ describe('shared opertations', () => { queryExecuted = true; } render() { + expect(this.props.data.loading).to.be.false; return null; } }; diff --git a/test/react-web/client/libraries/redux.tsx b/test/react-web/client/libraries/redux.tsx index 034769472f..9f884726b2 100644 --- a/test/react-web/client/libraries/redux.tsx +++ b/test/react-web/client/libraries/redux.tsx @@ -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);