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

Commit

Permalink
Fix/804 (#865)
Browse files Browse the repository at this point in the history
* test for #804

* fix for #804

* changelog for #804
  • Loading branch information
akomm authored and James Baxley committed Jul 19, 2017
1 parent 609b055 commit d2bac92
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change log

### vNext
- Fix: Fix issue where `withRef`-option of `graphql` did not work when the query was skipped [#865](https://github.com/apollographql/react-apollo/pull/865)

### 1.4.5
- Fix: export all types from main type file
Expand Down
6 changes: 6 additions & 0 deletions src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,12 @@ export default function graphql<

render() {
if (this.shouldSkip()) {
if (operationOptions.withRef) {
return createElement(
WrappedComponent,
assign({}, this.props, { ref: 'wrappedInstance' }),
);
}
return createElement(WrappedComponent, this.props);
}

Expand Down
47 changes: 47 additions & 0 deletions test/react-web/client/graphql/shared-operations.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ describe('shared operations', () => {
expect((decorated as any).refs.wrappedInstance.someMethod()).toEqual(
testData,
);

const DecoratedWithSkip = withApollo(Container, {
withRef: true,
skip: true,
});

const treeWithSkip = TestUtils.renderIntoDocument(
<ApolloProvider client={client}>
<DecoratedWithSkip />
</ApolloProvider>,
) as any;

const decoratedWithSkip = TestUtils.findRenderedComponentWithType(
treeWithSkip,
DecoratedWithSkip,
);

expect(() => (decoratedWithSkip as any).someMethod()).toThrow();
expect(
(decoratedWithSkip as any).getWrappedInstance().someMethod(),
).toEqual(testData);
expect(
(decoratedWithSkip as any).refs.wrappedInstance.someMethod(),
).toEqual(testData);
});
});

Expand Down Expand Up @@ -280,6 +304,29 @@ describe('shared operations', () => {
expect((decorated as any).refs.wrappedInstance.someMethod()).toEqual(
testData,
);

const DecoratedWithSkip = graphql(query, { withRef: true, skip: true })(
Container,
);

const treeWithSkip = TestUtils.renderIntoDocument(
<ApolloProvider client={client}>
<DecoratedWithSkip />
</ApolloProvider>,
) as any;

const decoratedWithSkip = TestUtils.findRenderedComponentWithType(
treeWithSkip,
DecoratedWithSkip,
);

expect(() => (decoratedWithSkip as any).someMethod()).toThrow();
expect(
(decoratedWithSkip as any).getWrappedInstance().someMethod(),
).toEqual(testData);
expect(
(decoratedWithSkip as any).refs.wrappedInstance.someMethod(),
).toEqual(testData);
});

it('allows options to take an object', done => {
Expand Down

0 comments on commit d2bac92

Please sign in to comment.