Skip to content

Commit

Permalink
fix: allow variables to be getter or ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Teages committed Apr 5, 2024
1 parent 5e18976 commit 747d9ed
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/runtime/composables-codegen/urql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { hash } from 'ohash'
import type { KeysOf, PickFrom } from '#app/composables/asyncData'
import { type AsyncData, type AsyncDataOptions, useAsyncData, useNuxtApp } from '#app'
import type { ClientName } from '#build/urql-client/options'
import { type MaybeRefOrGetter, toValue } from '#imports'

export function useUrql(): { client: Client }
export function useUrql(id: ClientName): { client: Client }
Expand Down Expand Up @@ -59,7 +60,7 @@ export function useAsyncQuery<
DefaultT = null,
>(
document: DocumentInput<Data, Variables>,
variables?: Variables,
variables?: MaybeRefOrGetter<Variables>,
options?: AsyncDataOptions<Data | undefined, DataT, PickKeys, DefaultT> & { context?: Partial<OperationContext> },
): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, CombinedError | null>
export function useAsyncQuery<
Expand All @@ -70,7 +71,7 @@ export function useAsyncQuery<
DefaultT = DataT,
>(
document: DocumentInput<Data, Variables>,
variables?: Variables,
variables?: MaybeRefOrGetter<Variables>,
options?: AsyncDataOptions<Data | undefined, DataT, PickKeys, DefaultT> & { context?: Partial<OperationContext> },
): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, CombinedError | null> {
const key = hash({ document, variables })
Expand All @@ -90,7 +91,7 @@ export function useLazyAsyncQuery<
DefaultT = null,
>(
document: DocumentInput<ResT, Variables>,
variables?: Variables,
variables?: MaybeRefOrGetter<Variables>,
options?: AsyncDataOptions<ResT | undefined, DataT, PickKeys, DefaultT> & { context?: Partial<OperationContext> },
): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, CombinedError | null>
export function useLazyAsyncQuery<
Expand All @@ -101,7 +102,7 @@ export function useLazyAsyncQuery<
DefaultT = DataT,
>(
document: DocumentInput<ResT, Variables>,
variables?: Variables,
variables?: MaybeRefOrGetter<Variables>,
options?: AsyncDataOptions<ResT | undefined, DataT, PickKeys, DefaultT> & { context?: Partial<OperationContext> },
): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, CombinedError | null> {
const key = hash({ document, variables })
Expand All @@ -110,7 +111,7 @@ export function useLazyAsyncQuery<
requestPolicy: 'network-only',
...options?.context,
}
return useAsyncData(key, () => useQuery(document, variables, context), {
return useAsyncData(key, () => useQuery(document, toValue(variables), context), {
lazy: true,
...options,
})
Expand Down

0 comments on commit 747d9ed

Please sign in to comment.