How to use subscriptions together with preloadQuery?

Hello,

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 https://www.apollographql.com/docs/react/development-testing/static-typing/#fetchmore-and-subscribetomore . 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