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:
Generate a notification edge with the notification. This requires we generate a cursor for the edge on the client-side.
Update pageInfo's cursor info
Since absinthe-relay generates an offset-based cursor, we will need to update all the existing edges to a new cursor with their new offset (old offset + 1)
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.
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 generatedNotificationConnection
andNotificationEdge
types. OnUser
object there isnotifications
field that utilizesNotificationConnection
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 ofuser.notifications
cache on the client-side. The difficulty isuser.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:pageInfo
's cursor infoIs 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.