Skip to content

Commit d2bac92

Browse files
akommJames Baxley
authored andcommitted
* test for apollographql#804 * fix for apollographql#804 * changelog for apollographql#804
1 parent 609b055 commit d2bac92

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change log
22

33
### vNext
4+
- 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)
45

56
### 1.4.5
67
- Fix: export all types from main type file

src/graphql.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,12 @@ export default function graphql<
560560

561561
render() {
562562
if (this.shouldSkip()) {
563+
if (operationOptions.withRef) {
564+
return createElement(
565+
WrappedComponent,
566+
assign({}, this.props, { ref: 'wrappedInstance' }),
567+
);
568+
}
563569
return createElement(WrappedComponent, this.props);
564570
}
565571

test/react-web/client/graphql/shared-operations.test.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,30 @@ describe('shared operations', () => {
6767
expect((decorated as any).refs.wrappedInstance.someMethod()).toEqual(
6868
testData,
6969
);
70+
71+
const DecoratedWithSkip = withApollo(Container, {
72+
withRef: true,
73+
skip: true,
74+
});
75+
76+
const treeWithSkip = TestUtils.renderIntoDocument(
77+
<ApolloProvider client={client}>
78+
<DecoratedWithSkip />
79+
</ApolloProvider>,
80+
) as any;
81+
82+
const decoratedWithSkip = TestUtils.findRenderedComponentWithType(
83+
treeWithSkip,
84+
DecoratedWithSkip,
85+
);
86+
87+
expect(() => (decoratedWithSkip as any).someMethod()).toThrow();
88+
expect(
89+
(decoratedWithSkip as any).getWrappedInstance().someMethod(),
90+
).toEqual(testData);
91+
expect(
92+
(decoratedWithSkip as any).refs.wrappedInstance.someMethod(),
93+
).toEqual(testData);
7094
});
7195
});
7296

@@ -280,6 +304,29 @@ describe('shared operations', () => {
280304
expect((decorated as any).refs.wrappedInstance.someMethod()).toEqual(
281305
testData,
282306
);
307+
308+
const DecoratedWithSkip = graphql(query, { withRef: true, skip: true })(
309+
Container,
310+
);
311+
312+
const treeWithSkip = TestUtils.renderIntoDocument(
313+
<ApolloProvider client={client}>
314+
<DecoratedWithSkip />
315+
</ApolloProvider>,
316+
) as any;
317+
318+
const decoratedWithSkip = TestUtils.findRenderedComponentWithType(
319+
treeWithSkip,
320+
DecoratedWithSkip,
321+
);
322+
323+
expect(() => (decoratedWithSkip as any).someMethod()).toThrow();
324+
expect(
325+
(decoratedWithSkip as any).getWrappedInstance().someMethod(),
326+
).toEqual(testData);
327+
expect(
328+
(decoratedWithSkip as any).refs.wrappedInstance.someMethod(),
329+
).toEqual(testData);
283330
});
284331

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

0 commit comments

Comments
 (0)