apollo-link-state icon indicating copy to clipboard operation
apollo-link-state copied to clipboard

Doesn't work with subscriptions properly

Open DmitryVlaznev opened this issue 7 years ago • 2 comments

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.

DmitryVlaznev avatar May 18 '18 09:05 DmitryVlaznev

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.

DmitryVlaznev avatar Jun 05 '18 14:06 DmitryVlaznev

Related to https://github.com/apollographql/apollo-link-state/issues/138.

hwillson avatar Jun 20 '18 16:06 hwillson