Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ 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 |
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table removed useLazyQuery which was present in the original version. If this composable still exists in the codebase, it should remain in the documentation table.

Suggested change
| `useQuery` | Reactive GraphQL query |
| `useQuery` | Reactive GraphQL query |
| `useLazyQuery` | Imperative GraphQL query (fetch on demand) |

Copilot uses AI. Check for mistakes.
| `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 |
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description 'Access Apollo clients' is inconsistent with useApolloClient's description. Consider 'Access all Apollo clients' to clarify that this composable returns all clients, not just one.

Suggested change
| `useApolloClients` | Access Apollo clients |
| `useApolloClients` | Access all Apollo clients |

Copilot uses AI. Check for mistakes.

See the [full API reference](https://vue3-apollo.guen.dev/core/composables/use-query) for details.

Expand Down
35 changes: 35 additions & 0 deletions packages/core/src/composables/useApolloClients.ts
Original file line number Diff line number Diff line change
@@ -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() {
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is missing an explicit return type annotation. Add : Record<string, ApolloClient<any>> to match the type from APOLLO_CLIENTS_KEY and improve type safety.

Copilot uses AI. Check for mistakes.
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
}
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export * from './composables/useApolloClient'
export * from './composables/useApolloClients'

export * from './composables/useFragment'
export * from './composables/useMutation'
export * from './composables/useQuery'
Expand Down
3 changes: 2 additions & 1 deletion packages/docs/composables/useApolloClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const result = await client.query({
query: GET_USERS,
})
```
> Use `useApolloClients()` to get all clients.

## API

Expand All @@ -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.
1 change: 1 addition & 0 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default defineNuxtModule<ApolloModuleOptions>({
from: '@vue3-apollo/core',
imports: [
// composables
'useApolloClients',
'useApolloClient',
'useFragment',
'useMutation',
Expand Down
Loading