tGQL is a TypeScript-first GraphQL schema builder heavily inspired by tRPC and Zod (and drizzle).
Look in the packages/server/tests folder for more examples.
import { tgql } from 'tgql';
const Food = tgql.object('Food', {
id: tgql.id(),
name: tgql.string(),
calories: tgql.int().nullable(),
});
const User = tgql
.object('User', {
id: tgql.id(),
firstName: tgql.string(),
lastName: tgql.string(),
age: tgql.int().description('Age in years'),
weight: tgql.float().nullable(),
favoriteFoods: tgql.list(Food).nullable(),
})
.fieldResolvers((builder) => ({
fullName: builder.fieldResolver(tgql.string(), (user) => `${user.firstName} ${user.lastName}`),
}));
type UserType = tgql.Infer<typeof User>;
/**
* {
* weight?: number | undefined;
* favoriteFoods?: {
* calories?: number | undefined;
* id: string;
* name: string;
* }[] | undefined;
* id: string;
* firstName: string;
* lastName: string;
* age: number;
* fullName: string;
* }
*/const user = tgql
.query<{ currentUser: string }>()
.returns(User)
.args({ id: tgql.id() })
.resolver(async ({ args: { id }, context }) => {
return {
id,
firstName: 'first',
lastName: 'last',
age: 10,
favoriteNumbers: [1, 2],
};
});
const schema = tgql.registerResolvers({ user }).createSchema();- objects
- arrays
- enums
- input objects
- scalars
- queries
- mutations
- field resolvers
- type inference
- simple middleware
- basic schema builder
- Add support for custom scalars
- Add object to input object utility
- Add support for unions
- Add support for interfaces
- More documentation & tests
- Create client methods for tGQL
- Add support for subscriptions
- Add support for fragments
- Better error handling
- Add support for directives
- Improved resolvers system
- Update middleware implementation