1
1
import { hash } from 'ohash'
2
2
import { print } from 'graphql'
3
- import type { OperationVariables , QueryOptions } from '@apollo/client'
3
+ import type { OperationVariables , QueryOptions , DefaultContext } from '@apollo/client'
4
4
import type { AsyncData } from 'nuxt/dist/app/composables'
5
5
import type { NuxtAppApollo } from '../types'
6
6
import { ref , useCookie , useNuxtApp , useAsyncData } from '#imports'
@@ -18,7 +18,7 @@ type TAsyncQuery<T> = {
18
18
19
19
export function useAsyncQuery < T > ( opts : TAsyncQuery < T > ) : AsyncData < T , Error >
20
20
export function useAsyncQuery < T > ( query : TQuery < T > , clientId ?: string ) : AsyncData < T , Error >
21
- export function useAsyncQuery < T > ( query : TQuery < T > , variables ?: TVariables < T > , clientId ?: string ) : AsyncData < T , Error >
21
+ export function useAsyncQuery < T > ( query : TQuery < T > , variables ?: TVariables < T > , clientId ?: string , context ?: DefaultContext ) : AsyncData < T , Error >
22
22
23
23
export function useAsyncQuery < T > ( ...args : any ) {
24
24
const { key, fn } = prep ( ...args )
@@ -27,7 +27,7 @@ export function useAsyncQuery <T> (...args: any) {
27
27
28
28
export function useLazyAsyncQuery < T > ( opts : TAsyncQuery < T > ) : AsyncData < T , Error >
29
29
export function useLazyAsyncQuery < T > ( query : TQuery < T > , clientId ?: string ) : AsyncData < T , Error >
30
- export function useLazyAsyncQuery < T > ( query : TQuery < T > , variables ?: TVariables < T > , clientId ?: string ) : AsyncData < T , Error >
30
+ export function useLazyAsyncQuery < T > ( query : TQuery < T > , variables ?: TVariables < T > , clientId ?: string , context ?: DefaultContext ) : AsyncData < T , Error >
31
31
32
32
export function useLazyAsyncQuery < T > ( ...args : any ) {
33
33
const { key, fn } = prep ( ...args )
@@ -40,6 +40,7 @@ const prep = (...args: any) => {
40
40
const query = args ?. [ 0 ] ?. query || args ?. [ 0 ]
41
41
const cache = args ?. [ 0 ] ?. cache ?? true
42
42
const variables = args ?. [ 0 ] ?. variables || ( typeof args ?. [ 1 ] !== 'string' && args ?. [ 1 ] ) || undefined
43
+ const context = args ?. [ 0 ] ?. context
43
44
let clientId = args ?. [ 0 ] ?. clientId || ( typeof args ?. [ 1 ] === 'string' && args ?. [ 1 ] ) || undefined
44
45
45
46
if ( ! clientId || ! clients ?. [ clientId ] ) {
@@ -48,7 +49,7 @@ const prep = (...args: any) => {
48
49
49
50
const key = args ?. [ 0 ] ?. key || hash ( { query : print ( query ) , variables, clientId } )
50
51
51
- const fn = ( ) => clients ! [ clientId ] ?. query ( { query, variables, fetchPolicy : 'no-cache' } ) . then ( r => r . data )
52
+ const fn = ( ) => clients ! [ clientId ] ?. query ( { query, variables, fetchPolicy : 'no-cache' , context } ) . then ( r => r . data )
52
53
53
54
return { key, query, clientId, variables, fn }
54
55
}
0 commit comments