From 7c5980a9594b6015451c3178076293a2dcf57efa Mon Sep 17 00:00:00 2001 From: James Baxley Date: Sun, 14 Aug 2016 10:55:30 -0400 Subject: [PATCH] fix issue with variable merging (#139) * fix issue with variable merging * update changelog and version * fix version numbers --- Changelog.md | 11 ++++++++--- package.json | 2 +- src/graphql.tsx | 6 +++--- test/react-web/client/graphql/queries.tsx | 9 +++++---- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Changelog.md b/Changelog.md index 04c03a7690..c1522e6c93 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,15 +2,20 @@ Expect active development and potentially significant breaking changes in the `0.x` track. We'll try to be diligent about releasing a `1.0` version in a timely fashion (ideally within 1 or 2 months), so that we can take advantage of SemVer to signify breaking changes from that point on. -### v4.0.3 + +### v0.4.4 + +- Bug: Fixed issue with variable merging [#139](https://github.com/apollostack/react-apollo/pull/139) + +### v0.4.3 - Feature: Support a different store in the tree that is immutable (support immutable redux) [#137](https://github.com/apollostack/react-apollo/pull/137) -### v4.0.2 +### v0.4.2 - Bug: Fixed refetch methods when no result is returned -### v4.0.1 +### v0.4.1 - BREAKING Feature: [Brand new API! See the docs for more information](http://docs.apollostack.com/apollo-client/react.html); diff --git a/package.json b/package.json index 275f8c1bfe..2f977fede7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-apollo", - "version": "0.4.3", + "version": "0.4.4", "description": "React data container for Apollo Client", "main": "index.js", "scripts": { diff --git a/src/graphql.tsx b/src/graphql.tsx index 64b28a2194..c72d13e404 100644 --- a/src/graphql.tsx +++ b/src/graphql.tsx @@ -407,7 +407,7 @@ export default function graphql( // XXX use passed loading after https://github.com/apollostack/apollo-client/pull/467 const { queryId } = observableQuery; - const currentVariables = this.store.getState()[reduxRootKey].queries[queryId].variables; + let currentVariables = this.store.getState()[reduxRootKey].queries[queryId].variables; const resultKeyConflict: boolean = ( 'errors' in data || 'loading' in data || @@ -448,10 +448,10 @@ export default function graphql( let newVariables = vars; const newData = { loading: true } as any; if (vars && (vars.variables || vars.query || vars.updateQuery)) { - newVariables = vars.variables; + newVariables = assign({}, this.data.variables, vars.variables); + newData.variables = newVariables; } - if (newVariables) newData.variables = newVariables; this.data = assign(this.data, newData); this.hasOperationDataChanged = true; diff --git a/test/react-web/client/graphql/queries.tsx b/test/react-web/client/graphql/queries.tsx index 705866c091..57bbd3115d 100644 --- a/test/react-web/client/graphql/queries.tsx +++ b/test/react-web/client/graphql/queries.tsx @@ -515,12 +515,12 @@ describe('queries', () => { it('exposes fetchMore as part of the props api', (done) => { const query = gql` - query people($skip: Int) { allPeople(first: 1, skip: $skip) { people { name } } } + query people($skip: Int, $first: Int) { allPeople(first: 1, skip: $skip) { people { name } } } `; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const data1 = { allPeople: { people: [ { name: 'Leia Skywalker' } ] } }; - const variables = { skip: 1 }; - const variables2 = { skip: 2 }; + const variables = { skip: 1, first: 1 }; + const variables2 = { skip: 2, first: 1 }; const networkInterface = mockNetworkInterface( { request: { query, variables }, result: { data } }, @@ -536,7 +536,7 @@ describe('queries', () => { expect(props.data.fetchMore).to.be.exist; expect(props.data.fetchMore).to.be.instanceof(Function); props.data.fetchMore({ - variables: variables2, + variables: { skip: 2 }, updateQuery: (prev, { fetchMoreResult }) => ({ allPeople: { people: prev.allPeople.people.concat(fetchMoreResult.data.allPeople.people), @@ -545,6 +545,7 @@ describe('queries', () => { }); // XXX add a test for the result here when #508 is merged and released } else if (count === 1) { + expect(props.data.variables).to.deep.equal(variables2); expect(props.data.loading).to.be.true; expect(props.data.allPeople).to.deep.equal(data.allPeople); } else if (count === 2) {