Second frontend, written in Next.JS + Typescript.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
import compress from "gql-compress";
class GQLBrowserClient implements GQLClient { async post(query: string, variables?: {[x:string]: any}, operationName?: string): Promise<GQLRespone> { 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<GQLRespone> }
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;
|