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

Commit

Permalink
Fix issue with changing outer props *and not changing variables*
Browse files Browse the repository at this point in the history
Ultimately caused by apollographql/apollo-client#694
  • Loading branch information
tmeasday committed Oct 14, 2016
1 parent 62261a7 commit 93bf1a2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Expect active development and potentially significant breaking changes in the `0

### vNext

### v0.5.10

- Bug: Fix issue with changing outer props *and not changing variables*, ultimately caused by https://github.com/apollostack/apollo-client/pull/694

### v0.5.9

- Bug: Fix and test some subtle bugs around skipping and subscriptions. [#260](https://github.com/apollostack/react-apollo/pull/260)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-apollo",
"version": "0.5.9",
"version": "0.5.10",
"description": "React data container for Apollo Client",
"main": "index.js",
"typings": "index.d.ts",
Expand Down Expand Up @@ -50,7 +50,7 @@
"peerDependencies": {
"react": "0.14.x || 15.* || ^15.0.0",
"redux": "^2.0.0 || ^3.0.0",
"apollo-client": "^0.4.20"
"apollo-client": "^0.4.21"
},
"devDependencies": {
"@types/chai": "^3.4.33",
Expand All @@ -69,7 +69,7 @@
"@types/redux-form": "^4.0.29",
"@types/redux-immutable": "^3.0.30",
"@types/sinon": "^1.16.29",
"apollo-client": "^0.4.20",
"apollo-client": "^0.4.21",
"babel-jest": "^14.1.0",
"babel-preset-react-native": "^1.9.0",
"browserify": "^13.0.0",
Expand Down
4 changes: 3 additions & 1 deletion src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ export default function graphql(
// We've subscribed already, just update with our new options and
// take the latest result
if (this.querySubscription) {
this.queryObservable.setOptions(opts);
// Since we don't care about the result, use a hacky version to
// work around https://github.com/apollostack/apollo-client/pull/694
this.queryObservable._setOptionsNoResult(opts);

// Ensure we are up-to-date with the latest state of the world
assign(this.data,
Expand Down
52 changes: 52 additions & 0 deletions test/react-web/client/graphql/queries-1.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,58 @@ describe('queries', () => {
renderer.create(<ProviderMock client={client}><ChangingProps /></ProviderMock>);
});

it('stays subscribed to updates after irrelevant prop changes', (done) => {
const query = gql`query people($first: Int) { allPeople(first: $first) { people { name } } }`;
const variables = { first: 1 };
const data1 = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } };
const data2 = { allPeople: { people: [ { name: 'Leia Skywalker' } ] } };
const networkInterface = mockNetworkInterface(
{ request: { query, variables }, result: { data: data1 } },
{ request: { query, variables }, result: { data: data2 } },
);
const client = new ApolloClient({ networkInterface });

let count = 0;
@graphql(query, { options() { return { variables }; } })
class Container extends React.Component<any, any> {8
componentWillReceiveProps(props) {
count += 1;

if (count == 1) {
expect(props.foo).toEqual(42);
expect(props.data.loading).toEqual(false);
expect(props.data.allPeople).toEqual(data1.allPeople);
props.changeState();
} else if (count == 2) {
expect(props.foo).toEqual(43);
expect(props.data.loading).toEqual(false);
expect(props.data.allPeople).toEqual(data1.allPeople);
props.data.refetch();
} else if (count == 3) {
expect(props.foo).toEqual(43);
expect(props.data.loading).toEqual(false);
expect(props.data.allPeople).toEqual(data2.allPeople);
done();
}
}
render() {
return null;
}
};

class Parent extends React.Component<any, any> {
constructor() {
super();
this.state = { foo: 42 };
}
render() {
return <Container foo={this.state.foo} changeState={() => this.setState({ foo: 43 })}/>;
}
};

renderer.create(<ProviderMock client={client}><Parent /></ProviderMock>);
});

it('exposes refetch as part of the props api', (done) => {
const query = gql`query people($first: Int) { allPeople(first: $first) { people { name } } }`;
const variables = { first: 1 };
Expand Down

0 comments on commit 93bf1a2

Please sign in to comment.