absinthe-graphql / absinthe_relay

Absinthe support for the Relay framework
MIT License
182 stars 88 forks source link

Use connection with subscriptions #104

Closed chengyin closed 6 years ago

chengyin commented 6 years ago

I'm seeking for some suggestions on how to use connections with subscriptions. I'm using Apollo as the client, but I do not think Relay (modern) behaviors differently on this topic.

We have a Notification type and with that we generated NotificationConnection and NotificationEdge types. On User object there is notifications field that utilizes NotificationConnection type for pagination. So far so good.

Now we want to add realtime notification using subscription. With the subscription we will get a new Notification object, which we need to manually insert to the beginning of user.notifications cache on the client-side. The difficulty is user.notifications is a connection type but the subscription is giving the node object itself. Now to update the client-side cache properly we need to:

Is this the right approach? It's quite a bit logic in the frontend to maintain its state, but I couldn't come up with a way to avoid this. Relay's document seems to imply this is the right approach. Although I don't think relay generated client id is recognizable by absinthe.

ssomnoremac commented 6 years ago

@chengyin do you still need assistance with this? If you are using Relay Modern my post explains how to update connections in the client store.