Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tree shaking support Compressed package size

tGQL

Description

tGQL is a TypeScript-first GraphQL schema builder heavily inspired by tRPC and Zod (and drizzle).

Example

Look in the packages/server/tests folder for more examples.

Define types

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;
 *  }
 */

Define queries

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();

Progress

  • 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

TODO

  • 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

About

TypeScript-first GraphQL schema builder heavily inspired by Zod and tRPC (and drizzle)

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages