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

useSubscription hook has no subscribeToMore #203

Open
FluorescentHallucinogen opened this issue Nov 12, 2021 · 4 comments
Open

useSubscription hook has no subscribeToMore #203

FluorescentHallucinogen opened this issue Nov 12, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@FluorescentHallucinogen
Copy link
Contributor

See apollographql/apollo-client#8727.

@bennypowers Is it possible to fix/implement it in Apollo Elements before it will be fixed/implemented in Apollo Client?

@FluorescentHallucinogen FluorescentHallucinogen added the bug Something isn't working label Nov 12, 2021
@bennypowers
Copy link
Member

Sounds like a nice feature. I'd be hesitant to implement this in Apollo elements, in case the API diverges from upstream at any point

As a workaround, have you considered using a query first and calling subscribeToMore on it? You could use a graphql fragment to reduce duplication between the query and subscription documents

@FluorescentHallucinogen
Copy link
Contributor Author

FluorescentHallucinogen commented Nov 16, 2021

As a workaround, have you considered using a query first and calling subscribeToMore on it? You could use a graphql fragment to reduce duplication between the query and subscription documents

The idea is to prevent exactly that, because Hasura subscriptions return the initial data (current state) once you subscribes. After that Hasura subscriptions return the new data (new state), not the patches (individual events).

@bennypowers
Copy link
Member

🤔

If that's the case, could you write a typePolicy to handle the merge for you?

@FluorescentHallucinogen
Copy link
Contributor Author

If that's the case, could you write a typePolicy to handle the merge for you?

relayStylePagination fits perfectly.

But the problem is that typePolicy works with queries and fetchMore, but don't work with subscriptions and subscribeToMore. See apollographql/apollo-client#7557 for more info. As you can see, that's point 2 in my issue apollographql/apollo-client#8727.

What about point 1 — adding subscribeToMore to useSubscription hook?

The point 2 (typePolicy), as a workaround, can be replaced by updateQuery function for subscribeToMore. This updateQuery function will be almost the same as relayStylePagination function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants