Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watchQuery directly unsubscribes from ResultObservable after first result #4322

Closed
alexstrat opened this issue Jan 17, 2019 · 3 comments
Closed

Comments

@alexstrat
Copy link

alexstrat commented Jan 17, 2019

Intended outcome:
With a link which ResultObservable emits more than 1 result, I was expecting the watchQuery to emit more than 1 value.

Actual outcome:
The resultObservable is unsubscribed directly after the first result and the watchQuery emits only the first value.

However, use the option queryDeduplication=false fixes the issue. So I guess the issue is more in the apollo-link-dedup.

How to reproduce the issue:

const { ApolloClient } = require('apollo-client');
const { InMemoryCache } = require('apollo-cache-inmemory');
const { ApolloLink, Observable } = require('apollo-link');
const gql = require('graphql-tag');

// used to mock a Link that returns a streaming observable
class MockSubscriptionLink extends ApolloLink {
  request() {
    return new Observable(observer => {
      this.observer = observer;
      return () => {
        console.log('unsubscribe')
      }
    })
  }

  simulateResult(result) {
    const { observer } = this;
    observer.next(result);
  }
}

const link = new MockSubscriptionLink();
const client = new ApolloClient({
  link: link,
  cache: new InMemoryCache(),
  // queryDeduplication: false,
});

const query = gql`
  query {
    a
  }
`;

client.watchQuery({ query })
  .subscribe(res => console.log('watchQuery.next', res));


setTimeout(() => {
  link.simulateResult({ data : { a: 1}})
}, 1000);


setTimeout(() => {
  link.simulateResult({ data: { a: 3 } })
}, 2000);
$ node test
watchQuery.next { data: { a: 1 }, loading: false, networkStatus: 7, stale: false }
unsubscribe

With the option queryDeduplication=false, here is my expected result:

$ node test
watchQuery.next { data: { a: 1 }, loading: false, networkStatus: 7, stale: false }
watchQuery.next { data: { a: 3 }, loading: false, networkStatus: 7, stale: false }

Versions


  System:
    OS: macOS 10.14.2
  Binaries:
    Node: 8.9.3 - ~/.nvm/versions/node/v8.9.3/bin/node
    Yarn: 1.10.1 - /usr/local/bin/yarn
    npm: 5.5.1 - ~/.nvm/versions/node/v8.9.3/bin/npm
  Browsers:
    Chrome: 71.0.3578.98
    Firefox: 58.0.1
    Safari: 12.0.2
  npmPackages:
    apollo-cache-inmemory: ^1.3.12 => 1.3.12
    apollo-client: ^2.4.8 => 2.4.8
    apollo-link: ^1.2.6 => 1.2.6
@benjamn
Copy link
Member

benjamn commented May 6, 2019

Sorry for the delay. Can you try the latest beta of apollo-client, 2.6.0-beta.8? We replaced the internal use of apollo-link-dedup with a new implementation in 7cd8479, and I'm hoping this bug got fixed in the process.

@benjamn benjamn added this to the Release 2.6.0 milestone May 6, 2019
@benjamn benjamn self-assigned this May 6, 2019
@benjamn benjamn added the 🏓 awaiting-contributor-response requires input from a contributor label May 6, 2019
@alexstrat
Copy link
Author

alexstrat commented May 6, 2019

@benjamn definitely, my issue seems fixed with 2.6.0-beta.8! Thx

For the reference, tested with apollo-link-reactive-schema in this sandbox.

@benjamn
Copy link
Member

benjamn commented May 21, 2019

Closing since we just published the final version of apollo-client@2.6.0 to npm, including the fix for this issue! See CHANGELOG.md if you're curious about the other changes in this release.

@benjamn benjamn closed this as completed May 21, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants