chunker ui redo
This commit is contained in:
24
ui/common/api/graphql.ts
Normal file
24
ui/common/api/graphql.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Shared GraphQL client for all MPR UI apps.
|
||||
*/
|
||||
|
||||
const GRAPHQL_URL = "/api/graphql";
|
||||
|
||||
export async function gql<T>(
|
||||
query: string,
|
||||
variables?: Record<string, unknown>,
|
||||
): Promise<T> {
|
||||
const response = await fetch(GRAPHQL_URL, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ query, variables }),
|
||||
});
|
||||
|
||||
const json = await response.json();
|
||||
|
||||
if (json.errors?.length) {
|
||||
throw new Error(json.errors[0].message);
|
||||
}
|
||||
|
||||
return json.data as T;
|
||||
}
|
||||
Reference in New Issue
Block a user