Files
webapp/app/composables/useServerQuery.ts
2026-01-07 09:10:35 +07:00

21 lines
777 B
TypeScript

import type { TypedDocumentNode } from '@graphql-typed-document-node/core'
/**
* SSR-friendly обёртка над useGraphQL.execute.
* Выполняет запрос на сервере (и на клиенте при навигации), возвращает useAsyncData-результат.
*/
export const useServerQuery = async <TResult, TVariables extends Record<string, unknown>>(
key: string,
document: TypedDocumentNode<TResult, TVariables>,
variables: TVariables,
endpoint: 'user' | 'team' | 'public',
api: 'teams' | 'exchange' | 'kyc' | 'orders' | 'geo' | 'billing'
) => {
const { execute } = useGraphQL()
return useAsyncData(key, () => execute(document, variables, endpoint, api), {
server: true,
lazy: false,
immediate: true
})
}