mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 13:19:09 +03: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.
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from 'types'
|
|
import { replicationKeys } from './keys'
|
|
|
|
type ReplicationSourcesParams = { projectRef?: string }
|
|
|
|
async function fetchReplicationSources(
|
|
{ projectRef }: ReplicationSourcesParams,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { data, error } = await get('/platform/replication/{ref}/sources', {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
if (error) {
|
|
handleError(error)
|
|
}
|
|
|
|
return data
|
|
}
|
|
|
|
export type ReplicationSourcesData = Awaited<ReturnType<typeof fetchReplicationSources>>
|
|
|
|
export const useReplicationSourcesQuery = <TData = ReplicationSourcesData>(
|
|
{ projectRef }: ReplicationSourcesParams,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<ReplicationSourcesData, ResponseError, TData> = {}
|
|
) =>
|
|
useQuery<ReplicationSourcesData, ResponseError, TData>({
|
|
queryKey: replicationKeys.sources(projectRef),
|
|
queryFn: ({ signal }) => fetchReplicationSources({ projectRef }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|