Initial commit from monorepo
This commit is contained in:
20
app/composables/useServerQuery.ts
Normal file
20
app/composables/useServerQuery.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user