Files
supabase/apps/studio/data/graphql/execute.ts
Charis d122f289df feat(api gateway logs): add error code explanation (#36315)
Add the ability to look up error code explanation in API Gateway logs.
Also a bunch of GraphQL-related utilities and generated types for
calling the Content API.
2025-06-24 13:18:12 -04:00

37 lines
863 B
TypeScript

import { handleError } from 'data/fetchers'
import type { TypedDocumentString } from './graphql'
const CONTENT_API_URL = process.env.NEXT_PUBLIC_CONTENT_API_URL!
export async function executeGraphQL<TResult, TVariables>(
query: TypedDocumentString<TResult, TVariables>,
{ variables, signal }: { variables?: TVariables; signal?: AbortSignal }
) {
try {
const response = await fetch(CONTENT_API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query,
variables,
}),
signal,
})
if (!response.ok) {
throw new Error('Failed network response from Content API')
}
const { data, errors } = await response.json()
if (errors) {
throw errors
}
return data as TResult
} catch (err) {
handleError(err)
}
}