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

fix: cache value false to rewrite default cache policy #625

Open
wants to merge 1 commit into
base: improve/async-query
Choose a base branch
from
Open
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
fix: cache value false to rewrite default cache policy
  • Loading branch information
Stanislavsonder committed Jun 16, 2024
commit 49b417e9e7eb78974934f02b18201e3287aef53f
6 changes: 4 additions & 2 deletions src/runtime/composables.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -165,10 +165,12 @@ const prep = <T> (...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<T>({
query,
variables: variables || undefined,
...(cache && { fetchPolicy: 'cache-first' }),
...fetchPolicy,
context
}).then(r => r.data)

Expand Down