import compress from "gql-compress"; class GQLBrowserClient implements GQLClient { async post(query: string, variables?: {[x:string]: any}, operationName?: string): Promise { const res = await fetch(`/api/graphql`, { method: "POST", body: JSON.stringify({query, variables, operationName}), credentials: "include", headers: { "Content-Type": "application/json", }, }) const json = await res.json(); if (json.errors) { throw new Error(`${json.errors[0].message} (${json.errors[0].path})`) } return json.data } } export interface GQLClient { post(query: string, variables?: {[x:string]: any}, operationName?: string): Promise } export interface GQLRespone {[x:string]: any} export interface GQLError { message: string path: string[] } export function gql(a: TemplateStringsArray): string { return compress(a.join("")) as string; } const gqlBrowserClient = new GQLBrowserClient(); export default gqlBrowserClient;