// Небольшой fetch-клиент для GraphQL (без зависимостей)
export async function gql<T>(
  query: string,
  variables?: Record<string, any>
): Promise<T> {
  const res = await fetch("/api/graphql", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    credentials: "include",
    body: JSON.stringify({ query, variables }),
  });

  const json = await res.json();
  if (!res.ok || json.errors) {
    const msg = json?.errors?.map((e: any) => e.message).join("\n") || res.statusText;
    throw new Error(msg);
  }
  return json.data as T;
}
