mirror of
https://github.com/supabase/supabase.git
synced 2026-06-20 11:22:25 +08:00
* Add custom types for queries, mutations and infinite queries. * Migrate all queries to use the new type. * Migrate all infinite queries to useCustomInfiniteQueryOptions. * Migrate all mutations to use useCustomMutationOptions. * Add type to all imports in `types` folder.
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { get, handleError } from 'data/fetchers'
|
|
import { IS_PLATFORM } from 'lib/constants'
|
|
import type { ResponseError, UseCustomQueryOptions } from 'types'
|
|
import { databaseKeys } from './keys'
|
|
|
|
type SupavisorConfigurationVariables = {
|
|
projectRef?: string
|
|
}
|
|
|
|
export async function getSupavisorConfiguration(
|
|
{ projectRef }: SupavisorConfigurationVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('Project ref is required')
|
|
|
|
const { data, error } = await get(`/platform/projects/{ref}/config/supavisor`, {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type SupavisorConfigurationData = Awaited<ReturnType<typeof getSupavisorConfiguration>>
|
|
export type SupavisorConfigurationError = ResponseError
|
|
|
|
export const useSupavisorConfigurationQuery = <TData = SupavisorConfigurationData>(
|
|
{ projectRef }: SupavisorConfigurationVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<SupavisorConfigurationData, SupavisorConfigurationError, TData> = {}
|
|
) =>
|
|
useQuery<SupavisorConfigurationData, SupavisorConfigurationError, TData>({
|
|
queryKey: databaseKeys.poolingConfiguration(projectRef),
|
|
queryFn: ({ signal }) => getSupavisorConfiguration({ projectRef }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined' && IS_PLATFORM,
|
|
...options,
|
|
})
|