Files
supabase/apps/studio/data/content-api/docs-error-codes-query.ts
Ivan Vasilov 8b657165b5 chore: Migrate to use custom type for ReactQuery queries and mutations (#40073)
* 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.
2025-11-03 13:18:13 +01:00

46 lines
1.3 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { executeGraphQL } from 'data/graphql/execute'
import { graphql } from 'data/graphql/gql'
import { Service } from 'data/graphql/graphql'
import { contentApiKeys } from './keys'
import { UseCustomQueryOptions } from 'types'
const ErrorCodeQuery = graphql(`
query ErrorCodeQuery($code: String!, $service: Service) {
errors(code: $code, service: $service) {
nodes {
code
service
message
}
}
}
`)
interface Variables {
code: string
service?: Service
}
async function getErrorCodeDescriptions({ code, service }: Variables, signal?: AbortSignal) {
return await executeGraphQL(ErrorCodeQuery, { variables: { code, service }, signal })
}
type ErrorCodeDescriptionsData = Awaited<ReturnType<typeof getErrorCodeDescriptions>>
type ErrorCodeDescriptionsError = unknown
export const useErrorCodesQuery = <TData = ErrorCodeDescriptionsData>(
variables: Variables,
{
enabled = true,
...options
}: UseCustomQueryOptions<ErrorCodeDescriptionsData, ErrorCodeDescriptionsError, TData> = {}
) => {
return useQuery<ErrorCodeDescriptionsData, ErrorCodeDescriptionsError, TData>({
queryKey: contentApiKeys.errorCodes(variables),
queryFn: ({ signal }) => getErrorCodeDescriptions(variables, signal),
enabled,
...options,
})
}