From e9f944a8024b140fbb59eb5ed315350c4af0a249 Mon Sep 17 00:00:00 2001 From: guen Date: Thu, 30 Oct 2025 21:01:48 +0700 Subject: [PATCH 1/4] feat(core): add `useApolloClients` composable for managing multiple Apollo clients - Exported `useApolloClients` from the core package. - Updated README with composables overview and added details for `useApolloClients`. --- packages/core/README.md | 15 ++++---- .../core/src/composables/useApolloClients.ts | 35 +++++++++++++++++++ packages/core/src/index.ts | 2 ++ 3 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 packages/core/src/composables/useApolloClients.ts diff --git a/packages/core/README.md b/packages/core/README.md index 86188dd..dd37e12 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -94,14 +94,13 @@ const { error, loading, result } = useQuery(GET_POSTS) ## 🧠 Composables Overview -| Composable | Description | -|-------------|--------------| -| `useQuery` | Reactive GraphQL query | -| `useLazyQuery` | Run query on demand | -| `useMutation` | Execute GraphQL mutations | -| `useSubscription` | Subscribe to GraphQL streams | -| `useApolloClient` | Access current Apollo client | -| `provideApolloClients` / `useApolloClients` | Manage multiple clients | +| Composable | Description | +|-------------------|------------------------------------------------| +| `useQuery` | Reactive GraphQL query | +| `useMutation` | Execute GraphQL mutations | +| `useSubscription` | Subscribe to GraphQL streams | +| `useFragment` | Retrieve and manage normalized cache fragments | +| `useApolloClient` | Access current Apollo client | See the [full API reference](https://vue3-apollo.guen.dev/core/composables/use-query) for details. diff --git a/packages/core/src/composables/useApolloClients.ts b/packages/core/src/composables/useApolloClients.ts new file mode 100644 index 0000000..67b0ef2 --- /dev/null +++ b/packages/core/src/composables/useApolloClients.ts @@ -0,0 +1,35 @@ +import { inject } from 'vue' + +import { APOLLO_CLIENTS_KEY } from '../constants/apollo' + +/** + * Get all Apollo client instances + * + * @returns Object containing all registered Apollo clients + * + * @example + * ```ts + * // Get all clients + * const clients = useApolloClients() + * + * // Access specific client + * const defaultClient = clients.default + * const analyticsClient = clients.analytics + * + * // Iterate over all clients + * Object.entries(clients).forEach(([id, client]) => { + * console.log(`Client ${id}:`, client) + * }) + * ``` + */ +export function useApolloClients() { + const apolloClients = inject(APOLLO_CLIENTS_KEY) + + if (!apolloClients) { + throw new Error( + '[useApolloClients] Apollo clients registry not found. Did you forget to install ApolloPlugin?' + ) + } + + return apolloClients +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index c6141c6..cb0df2e 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,4 +1,6 @@ export * from './composables/useApolloClient' +export * from './composables/useApolloClients' + export * from './composables/useFragment' export * from './composables/useMutation' export * from './composables/useQuery' From 1fb5a538cd10bea5d11cae28e70ab0f9f35fc8f8 Mon Sep 17 00:00:00 2001 From: guen Date: Thu, 30 Oct 2025 21:05:28 +0700 Subject: [PATCH 2/4] docs(core): update README to include `useApolloClients` in composables overview --- packages/core/README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/core/README.md b/packages/core/README.md index dd37e12..b94a571 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -94,13 +94,14 @@ const { error, loading, result } = useQuery(GET_POSTS) ## 🧠 Composables Overview -| Composable | Description | -|-------------------|------------------------------------------------| -| `useQuery` | Reactive GraphQL query | -| `useMutation` | Execute GraphQL mutations | -| `useSubscription` | Subscribe to GraphQL streams | -| `useFragment` | Retrieve and manage normalized cache fragments | -| `useApolloClient` | Access current Apollo client | +| Composable | Description | +|--------------------|------------------------------------------------| +| `useQuery` | Reactive GraphQL query | +| `useMutation` | Execute GraphQL mutations | +| `useSubscription` | Subscribe to GraphQL streams | +| `useFragment` | Retrieve and manage normalized cache fragments | +| `useApolloClient` | Access current Apollo client | +| `useApolloClients` | Access Apollo clients | See the [full API reference](https://vue3-apollo.guen.dev/core/composables/use-query) for details. From 35c742119dfa486e4f7d903ddc7faf4a9aa689c4 Mon Sep 17 00:00:00 2001 From: guen Date: Thu, 30 Oct 2025 21:05:34 +0700 Subject: [PATCH 3/4] feat(nuxt): export `useApolloClients` in module setup --- packages/nuxt/src/module.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/nuxt/src/module.ts b/packages/nuxt/src/module.ts index 371b59e..42248da 100644 --- a/packages/nuxt/src/module.ts +++ b/packages/nuxt/src/module.ts @@ -36,6 +36,7 @@ export default defineNuxtModule({ from: '@vue3-apollo/core', imports: [ // composables + 'useApolloClients', 'useApolloClient', 'useFragment', 'useMutation', From 72da2d649f15309ab2349d45869c9703060d6a33 Mon Sep 17 00:00:00 2001 From: guen Date: Thu, 30 Oct 2025 21:10:49 +0700 Subject: [PATCH 4/4] docs(composables): add note for `useApolloClients` usage in `useApolloClient` example --- packages/docs/composables/useApolloClient.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/docs/composables/useApolloClient.md b/packages/docs/composables/useApolloClient.md index 4a981b8..64a9591 100644 --- a/packages/docs/composables/useApolloClient.md +++ b/packages/docs/composables/useApolloClient.md @@ -14,6 +14,7 @@ const result = await client.query({ query: GET_USERS, }) ``` +> Use `useApolloClients()` to get all clients. ## API @@ -22,4 +23,4 @@ const result = await client.query({ - If omitted, returns the first available client (usually the `default` one). ### Returns -- **`ApolloClient`** – the Apollo client instance. +- **`ApolloClient`** – the Apollo client instance. \ No newline at end of file