How to use subscriptions together with preloadQuery?


What is the suggested way to mix preloadQuery and subscriptions? I’m using react-router and start fetching as soon as I navigate to the page. Also I want to subscribe to latest updates

As I can see there is subscribeToMore for regular useQuery hook but there is none in query ref handlers, only fetchMore. Am I supposed to use useSubscription?

Thanks in advance for any tips

Hi @misha-erm :wave: to my knowledge we don’t have a “preloadSubscription” feature. Since subscriptions and queries both share the normalized cache, though, you could consider using preloadQuery to populate your cache with data that you know you’ll be subscribing to.

That’s what I’m doing right now

But I know that there is this handler for pagination

const { fetchMore } = useQueryRefHandlers(queryRef);

so my initial thought was that there might also be something like

const { subscribeToMore } = useQueryRefHandlers(queryRef);

Would that subscribeToMore effectively turn the query into a subscription for the developer?

Sorry, not sure I understand, pretty new to Apollo (

I mean something like this for . For regular queries from useQuery we have fetchMore and subscribeToMore. From what I understand subscribeToMore handles merging data

But for preloaded queries we have only fetchMore

Ah okay, sorry for the confusion. I understand what you’re saying now :slight_smile: bear with me, it’s a busy week so I’m not sure when I can get back to you with a recommendation but hopefully soon!

@misha-erm the team agrees that this is something we should add. I opened a ticket here:

Thanks again for bringing it to our attention!

1 Like

Hey @JeffAuriemma , love the package and the work of the team! Just wanted to bump and keep tabs on this.

I’m currently refactoring some waterfall like components that are using useSuspenseQuery and this request would solve the issue without a doubt. We already have heaps of reducers for certain data that run through subscribeToMore and it would be awesome to be able to use those without recreating them for individual components.

1 Like