Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for queryDeduplication apollo config option #559

Open
wants to merge 2 commits into
base: v5
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- Ensure you have the latest LTS version of Node.js installed
- Run `corepack enable`
- Install dependencies using `pnpm install`
- Build the module and prepare the playground `pnpm dev:prepare`
- Start playground with `pnpm dev`

## License
Expand Down
1 change: 1 addition & 0 deletions docs/content/1.getting-started/2.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineNuxtConfig({
authHeader: 'Authorization',
tokenStorage: 'cookie',
proxyCookies: true,
queryDeduplication: true,
clients: {}
}
})
Expand Down
7 changes: 5 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export default defineNuxtModule<ModuleOptions>({
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax'
},
clientAwareness: false
clientAwareness: false,
queryDeduplication: true
},
async setup (options, nuxt) {
if (!options.clients || !Object.keys(options.clients).length) {
Expand Down Expand Up @@ -102,6 +103,7 @@ export default defineNuxtModule<ModuleOptions>({
' export const NuxtApollo: {',
' clients: Record<ApolloClientKeys, ClientConfig>',
' clientAwareness: boolean',
' queryDeduplication: boolean',
' proxyCookies: boolean',
' cookieAttributes: ClientConfig[\'cookieAttributes\']',
' }',
Expand All @@ -115,8 +117,9 @@ export default defineNuxtModule<ModuleOptions>({
'export const NuxtApollo = {',
` proxyCookies: ${options.proxyCookies},`,
` clientAwareness: ${options.clientAwareness},`,
` queryDeduplication: ${options.queryDeduplication},`,
` cookieAttributes: ${serializeConfig(options.cookieAttributes)},`,
` clients: ${serializeConfig(clients)}`,
` clients: ${serializeConfig(clients)}`
'}'
].join('\n')
})
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export default defineNuxtPlugin((nuxtApp) => {
? { ssrMode: true }
: { ssrForceFetchDelay: 100 }),
connectToDevTools: clientConfig.connectToDevTools || false,
defaultOptions: clientConfig?.defaultOptions
defaultOptions: clientConfig?.defaultOptions,
queryDeduplication: NuxtApollo.queryDeduplication
})

if (!clients?.default && !NuxtApollo?.clients?.default && key === Object.keys(NuxtApollo.clients)[0]) {
Expand Down
8 changes: 8 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,12 @@ export interface NuxtApolloConfig<T = false> {
* @default false
*/
clientAwareness?: boolean

/**
* If false, Apollo Client sends every created query to the server,
* even if a completely identical query is already in flight.
* @type {boolean}
* @default true
**/
queryDeduplication?: boolean;
}