From 49b417e9e7eb78974934f02b18201e3287aef53f Mon Sep 17 00:00:00 2001 From: Stanislavsonder Date: Sun, 16 Jun 2024 19:59:26 -0400 Subject: [PATCH] fix: cache value false to rewrite default cache policy --- src/runtime/composables.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runtime/composables.ts b/src/runtime/composables.ts index 7644afea..43018275 100644 --- a/src/runtime/composables.ts +++ b/src/runtime/composables.ts @@ -1,6 +1,6 @@ import { hash } from 'ohash' import { print } from 'graphql' -import type { ApolloClient, OperationVariables, QueryOptions, DefaultContext } from '@apollo/client' +import type { ApolloClient, OperationVariables, QueryOptions, DefaultContext, FetchPolicy } from '@apollo/client' import type { AsyncData, AsyncDataOptions, NuxtError } from 'nuxt/app' import type { RestartableClient } from './ws' import { ref, isRef, reactive, useCookie, useNuxtApp, useAsyncData } from '#imports' @@ -165,10 +165,12 @@ const prep = (...args: any[]) => { const key: string = args?.[0]?.key || hash({ query: print(query), variables, clientId }) + const fetchPolicy = cache === undefined && { fetchPolicy: cache ? 'cache-first' : 'no-cache' as FetchPolicy } + const fn = () => clients![clientId!]?.query({ query, variables: variables || undefined, - ...(cache && { fetchPolicy: 'cache-first' }), + ...fetchPolicy, context }).then(r => r.data)