apollographql / apollo-link

:link: Interface for fetching and modifying control flow of GraphQL requests
https://www.apollographql.com/docs/link/
MIT License
1.44k stars 344 forks source link

apollo-link-dedup - subscribeToMore will unsubscribe after first data | bug #259

Open seeden opened 6 years ago

seeden commented 6 years ago

I found that I am automatically unsubscribed when I receive first data with subscribeToMore or subscribe. The problem is in the apollo-link-dedup (https://github.com/apollographql/apollo-link/blob/master/packages/apollo-link-dedup/src/dedupLink.ts#L73)

More info about this issue you can find here: https://github.com/apollographql/apollo-client/issues/2581

    "apollo-cache-inmemory": "^1.1.1",
    "apollo-client": "^2.0.3",
    "apollo-link": "^1.0.3",
    "apollo-link-http": "^1.2.0",
    "apollo-link-batch-http": "^1.0.1",
    "apollo-link-retry": "^1.0.1",
    "apollo-link-dedup": "^1.0.2",
    "apollo-link-ws": "^1.0.1",
    "apollo-utilities": "^1.0.2",
azazdeaz commented 6 years ago

As i see it closes the regular queries as well after the first response.

If i roll back to apollo-link-dedup@1.0.0 (from 1.0.2) everything works properly again.

I do not fully understand the logic of dedupLink but the root of the issue is maybe here where it calls observer.complete after the first next() call.

cc @jbaxleyiii

seeden commented 6 years ago

I tried apollo-link-dedup@1.0.0 and it is working for me too.

jbaxleyiii commented 6 years ago

@seeden that is no good at all! I'll see about writing a failing test, would you be able to help with that?

seeden commented 6 years ago

@jbaxleyiii failing test case is very simple. Use graphql decorator from react-apollo and call subscribeToMore in the componentDidMount when data.loaded is true. You will be automatically unsubscribed when you receive first data from subscription. My example is here https://github.com/apollographql/apollo-client/issues/2581

azazdeaz commented 6 years ago

@jbaxleyiii I'm trying to understand how it works to write a failing test. Can you help me why does it have to complete all the subscribers (here) when the first piece of data arrives ?

schavaLogi commented 6 years ago

Any update on this, this is effecting apolli-link-ws subscriptions

seeden commented 6 years ago

I am still using version 1.0.0

seeden commented 6 years ago

any update ?

typical000 commented 6 years ago

After upgrading all apollo* dependencies to latest version solved the issue (in my case :))