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

Support subscriptions #15

Open
akotlar opened this issue Dec 20, 2018 · 8 comments
Open

Support subscriptions #15

akotlar opened this issue Dec 20, 2018 · 8 comments
Labels
enhancement New feature or request

Comments

@akotlar
Copy link

akotlar commented Dec 20, 2018

Great library, and mostly fits my design goals. Really like the hash-based cache choice, easiness of having non-singleton configuration, and most of all library size.

I was wondering if you have given any further thought to subscriptions. This is something I would like to have, and am thinking around writing an integration when the time comes. You know the GraphQL ecosystem better than I, and so was wondering if you had any thoughts.

Thanks!

edit: One simple way of doing this would be to rely on prop-mutation-based refetch (send a simple websocket notification with say a hash of the query, mutate a prop, and cause graphql-react to refetch), but that seems mostly wasteful. I want to be able to send a diff, and reconcile with the data already stored in grahpql-react. It's certainly possible to do this completely outside the graphql ecosystem, which is what I have previously implemented (a bit like graphql, in that I send a json object containing the dag representing the diff, and reconcile that dag with the client-stored stale data, by walking the shared portions of these two graphs and updating the leaves on the client store).

@akotlar akotlar changed the title Integration with subscription-transport-ws Integration with subscriptions-transport-ws Dec 20, 2018
@jaydenseric jaydenseric added the enhancement New feature or request label Dec 20, 2018
@jaydenseric
Copy link
Owner

A friend looked into subscriptions a while ago: https://github.com/pur3miish/graphql-react-subscription

I haven't needed subscriptions for any of my my own projects, so have not given the problem space due thought yet.

@jaydenseric jaydenseric changed the title Integration with subscriptions-transport-ws Support subscriptions Dec 26, 2018
@ca-miked
Copy link

+1 !

@oogxdd
Copy link

oogxdd commented Nov 1, 2019

++

@timeshift92
Copy link

++

@timeshift92
Copy link

Hello everyone, I did a subscription without caching. Does anyone care?

@jaydenseric
Copy link
Owner

An update…

On a few occasions I dove really deep into GraphQL WebSocket protocols, and was dissatisfied with Apollo's protocol (which has actually changed a few times) but it seems to be the only widely adopted protocol. I got started writing my own WebSocket related packages but ran out of motivation at the point of writing tests.

In the end, for me even in projects using Apollo Client where subscriptions are supported, polling has consistently been a better solution than subscriptions anyway. Somes advantages of polling are that it works without special setup, and it doesn't prevent you from using a serverless deployment for the GraphQL API.

I'll continue exploring subscriptions once there is a robust GraphQL WebSocket protocol endorsed by the GraphQL Foundation, which might be years away unfortunately. I'm in the GraphQL Foundation’s GraphQL over HTTP working group, and even a basic HTTP spec is taking a while to sort out.

@jthegedus
Copy link

So there's not just one voice on this, I 100% agree with @jaydenseric here. Polling has always given the benefit I was after, without the significant engineering overhead of managing sockets, correctly managing socket errors and the backend architecture to support sockets and scaling of the infra the message propagation is hosted on.

Simple polling with serverless deployment of the API gateway is by far the least amount of engineering to use GraphQL with close to "realtime" updates.

@jaydenseric
Copy link
Owner

A React hook for GraphQL subscriptions is now quite feasible:

  1. graphql-ws is well maintained, and implements a protocol on track to be standardized by the GraphQL Foundation.
  2. The new graphql-react v13 API has a very modular design, allowing custom React hooks to easily access and manipulate the cache.

Although this is not something I will get around to in the short term (unless I need subscriptions for a particular project) I'm happy to offer advice here to anyone that would like to create a custom React hook leveraging the new graphql-react API.

Maybe a GraphQL subscription hook should be designed to be used next to the useLoadGraphQL and useAutoLoad hooks, which would handle the loading for SSR, on mount, etc. as normal and the subscription hook would just update the same cache entry when subscription messages are received, skipping the Loading system in React context that is more useful for request/response type loading promises.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants