From 7879187b60013c5ee9e513968f613a8cf624effb Mon Sep 17 00:00:00 2001 From: Rebecca Richards Date: Thu, 26 Oct 2023 22:31:05 +0100 Subject: [PATCH] feat: add support for queryDeduplication apollo config option --- README.md | 1 + docs/content/1.getting-started/2.configuration.md | 1 + src/module.ts | 7 +++++-- src/runtime/plugin.ts | 3 ++- src/types.d.ts | 8 ++++++++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index baa0d7d..4b54976 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/content/1.getting-started/2.configuration.md b/docs/content/1.getting-started/2.configuration.md index 076be71..1228690 100644 --- a/docs/content/1.getting-started/2.configuration.md +++ b/docs/content/1.getting-started/2.configuration.md @@ -16,6 +16,7 @@ export default defineNuxtConfig({ authHeader: 'Authorization', tokenStorage: 'cookie', proxyCookies: true, + queryDeduplication: true, clients: {} } }) diff --git a/src/module.ts b/src/module.ts index 51eb1f1..6725048 100644 --- a/src/module.ts +++ b/src/module.ts @@ -36,7 +36,8 @@ export default defineNuxtModule>({ maxAge: 60 * 60 * 24 * 7, secure: process.env.NODE_ENV === 'production' }, - clientAwareness: false + clientAwareness: false, + queryDeduplication: true }, async setup (options, nuxt) { if (!options.clients || !Object.keys(options.clients).length) { @@ -95,9 +96,10 @@ export default defineNuxtModule>({ 'import type { ClientConfig } from "@nuxtjs/apollo"', 'declare const clients: Record', 'declare const clientAwareness: boolean', + 'declare const queryDeduplication: boolean', 'declare const proxyCookies: boolean', 'declare const cookieAttributes: ClientConfig[\'cookieAttributes\']', - 'export default { clients, clientAwareness, proxyCookies, cookieAttributes }' + 'export default { clients, clientAwareness, queryDeduplication, proxyCookies, cookieAttributes }' ].join('\n') }) @@ -107,6 +109,7 @@ export default defineNuxtModule>({ 'export default {', ` proxyCookies: ${options.proxyCookies},`, ` clientAwareness: ${options.clientAwareness},`, + ` queryDeduplication: ${options.queryDeduplication},`, ` cookieAttributes: ${JSON.stringify(options.cookieAttributes)},`, ` clients: ${JSON.stringify(clients)}`, '}' diff --git a/src/runtime/plugin.ts b/src/runtime/plugin.ts index 269241a..9ee263d 100644 --- a/src/runtime/plugin.ts +++ b/src/runtime/plugin.ts @@ -116,7 +116,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]) { diff --git a/src/types.d.ts b/src/types.d.ts index 11771b2..da777eb 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -170,4 +170,12 @@ export interface NuxtApolloConfig { * @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; }