apollo icon indicating copy to clipboard operation
apollo copied to clipboard

[Question] Get loading state of query in another component

Open MrSnoozles opened this issue 4 years ago • 2 comments

Hello,

I wanted to ask if it is possible to get the loading-state of a query that's executed in another component.

Example: Dashboard and Login are handled in different components. Now I would like to show a loading state on the dashboard when doing the login / fetching the current user.

This could done with Vue events (sending an event from the Login component when loading starts and another one when loading end), but I fear that's going to more difficult to maintain. Especially if it's used not just in the dashboard.

So my ideal solution would be: Having access to a query from another component. If I could use this.$apollo.queries.CurrentUser.loading from the Dashboard this would allow to easily watch for changes in that query.

Is there a way to register queries on the $apollo property for all instances?

MrSnoozles avatar Mar 29 '21 15:03 MrSnoozles

In Composition API you can just pass whole useQuery / useMutation object as component prop and use it in other's component template. I don't know how it works in Options API though.

JoJk0 avatar Apr 08 '21 13:04 JoJk0

I have the same case:

I have a dashboard, I'm loading many data. I would like to show loader for Dashboard, but at the same time, I'm loading data inside of Sections.

Yes, you load data on Dashboard and pass to sections but, then I have separate pages, where the same section components are used. I know, hard to visualize but basically, I need the same access to query

lasharela avatar Sep 02 '22 06:09 lasharela