const GRAPHQL_URL = "https://index.bostrom.cybernode.ai/v1/graphql";
export async function graphql<T = unknown>(
query: string,
variables?: Record<string, unknown>,
): Promise<T> {
const res = await fetch(GRAPHQL_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query, variables }),
});
if (!res.ok) {
throw new Error(`GraphQL ${res.status}: ${res.statusText}`);
}
const json = (await res.json()) as { data?: T; errors?: Array<{ message: string }> };
if (json.errors?.length) {
throw new Error(`GraphQL error: ${json.errors[0].message}`);
}
return json.data as T;
}