apollo-link-state
apollo-link-state copied to clipboard
Doesn't work with subscriptions properly
When I use apollo-link-state and a client-only field with a @client directive which is mixed with subscription data as described here (a value actually comes from state link defaults), apollo-link-state unsubscribes a subscription silently after the first response.
I found the following code into the index.ts file:
.then(nextData => {
observer.next({
data: nextData,
errors,
});
observer.complete();
})
https://github.com/apollographql/apollo-link-state/blob/404b6a1dce5ea1f73679d2dcb96ec88332ec9238/packages/apollo-link-state/src/index.ts#L109
When I replaced this code with the followed one
.then(nextData => {
observer.next({
data: nextData,
errors,
});
if (type !== 'Subscription') {
observer.complete();
}
})
a subscription starts working as expected.
I tried to use this patch above (built a package from a master branch) but got an error:
TypeError: obs.flatMap is not a function
I've realized that it is more than likely that one of the links in the links chain returns ObservableLike object instead of an Observable.
Related to https://github.com/apollographql/apollo-link-state/issues/138.