-
Notifications
You must be signed in to change notification settings - Fork 786
Add complete handler to Subscription, to handle the case when the ser… #2716
Conversation
…ver completes the subscription
Sample client and server app to test this: https://github.com/sujeetsr/subscriptions-example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @sujeetsr! Just a few small changes, then we should be pretty close here. If you're up for adding a test, similar to
react-apollo/test/client/Subscription.test.tsx
Lines 101 to 131 in 8204605
it('calls onSubscriptionData if given', done => { | |
jest.useFakeTimers(); | |
let count = 0; | |
const Component = () => ( | |
<Subscription | |
subscription={subscription} | |
onSubscriptionData={opts => { | |
expect(opts.client).toBeInstanceOf(ApolloClient); | |
const { data } = opts.subscriptionData; | |
expect(data).toEqual(results[count].result.data); | |
if (count === 3) done(); | |
count++; | |
}} | |
/> | |
); | |
wrapper = mount( | |
<ApolloProvider client={client}> | |
<Component /> | |
</ApolloProvider>, | |
); | |
const interval = setInterval(() => { | |
link.simulateResult(results[count]); | |
if (count >= 3) clearInterval(interval); | |
}, 10); | |
jest.runTimersToTime(40); | |
}); |
that would be great as well. If not, not worries - just let me know and I'll add it in (and add onSubscriptionComplete
to the docs). Thanks!
Setting the second parameter of `simulateResult` to `true` will now call the observer's `complete` function, if one is supplied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @sujeetsr!
@hwillson thanks for merging! |
Handle finite subscriptions
(apollographql/subscriptions-transport-ws#471)
Depends on
apollographql/apollo-client#4290
@hwillson - please review.