Subscriptions with Existing Subscription Data

prisma

#1

Greetings,

Currently when I create a subscription I am able to see data as mutations happen.
I would like to create subscriptions in a way where I also get the initial query data as well within the same subscription feed.

For example, if I am creating a chat application where I am creating realtime messages.
If a user enters a chat or thread, I’d like that user to already have the preexisting messages from the conversation returned in the subscription.

Currently, a user would enter a chat and only the new messages would be displayed in realtime,
but I would like to display perhaps the first or last 10 messages along with the subscription.

Of course one could query the database then provide a subscription with new incoming data, but that doesn’t seem like the right way to go.

Any help would be greatly appreciated.


#2

Hi,

The use of subscription is to get updates for the data. You can achieve the initial data loading you are asking by making a query.

I guess we will not be able to implement such a feature as this as is not the use case of subscription . You may able to do that but that would be very hard. Please try to understand and use a query to load the initial data. Many library like apollo client provide a subscribe to more in the query method they provide.

If you are using apollo make your chat app you will do achieve that by using https://www.apollographql.com/docs/react/advanced/subscriptions.html#subscribe-to-more

Hope this will help you :slightly_smiling_face: