import { useQuery } from '@tanstack/react-query' import { contentApiKeys } from './keys' import { executeGraphQL } from '@/data/graphql/execute' import { graphql } from '@/data/graphql/gql' import { Service } from '@/data/graphql/graphql' 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> type ErrorCodeDescriptionsError = unknown export const useErrorCodesQuery = ( variables: Variables, { enabled = true, ...options }: UseCustomQueryOptions = {} ) => { return useQuery({ queryKey: contentApiKeys.errorCodes(variables), queryFn: ({ signal }) => getErrorCodeDescriptions(variables, signal), enabled, retry: false, staleTime: Infinity, ...options, }) }