create-gql-api
Simplify GQL typing and consumption
Get Started
npx create-gql-api https://example.domain/graphql gql_api.ts
This generates a gql_api.ts
file in your project.
import {
createRequester,
createSubscriber,
createQuery,
createMutation,
createSubscription,
} from "./gql_api.ts";
const query = createRequester((query, variables) => {
return new Promise(() => {});
});
const subscribe = createSubscriber((query, variables, onMessage) => {
return () => {};
});
export const queryFoo = createQuery("Foo", {
foo: {
name: true,
email: true,
},
});
query(queryFoo);
export const queryBar = api.createQuery("Bar", {
bar: [{ unit: "FOOTER" }],
});
query(queryBar);
export const queryBaz = api.createQuery("Baz", {
baz: [
{ id: "123" },
{
id: true,
},
],
});
query(queryBaz);
export const queryBazWithVars = createQuery(
"BazWithVars",
(vars: { id: string }) => ({
baz: [
{ id: vars.id },
{
id: true,
},
],
}),
);
query(queryBazWithVars, { id: "123" });
export const mutateSomething = createMutation("Something", () => ({
something: [{}],
}));
query(mutateSomething);
export const subscribeSomething = createSubscription(
"Something",
(vars: { id: string }) => ({
something: [{ id: vars.id }],
}),
);
subscribe(
subscribeSomething,
(data) => {
},
{ id: "123" },
);