Files
supabase/apps/studio/data/content-api/docs-error-codes-query.ts
Joshen Lim b4d38fabd0 Chore/barrel files bye part 05 (#40016)
* Clean up barrel files part 4

* nit

* Part 5 of cleaning up barrel files

* Revert changes for types

* Nit
2025-10-31 13:15:31 +08:00

45 lines
1.3 KiB
TypeScript

import { useQuery, type UseQueryOptions } 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'
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
}: UseQueryOptions<ErrorCodeDescriptionsData, ErrorCodeDescriptionsError, TData> = {}
) => {
return useQuery<ErrorCodeDescriptionsData, ErrorCodeDescriptionsError, TData>({
queryKey: contentApiKeys.errorCodes(variables),
queryFn: ({ signal }) => getErrorCodeDescriptions(variables, signal),
enabled,
...options,
})
}