!> Note: this library is under active development, breaking changes may occur
TypeGraph generates GraphQL queries from decorated TypeScript classes, eliminating the need to write both queries to get data and interfaces to describe the results.
npm install typegraph --save
Using a class instead of a typescript interface allows access during runtime
import { Entity } from 'typegraph';
@Entity({one: "company", many: "companies"})
class Company {
@Field()
id: number;
@Field()
name: string;
@Field()
industry: string;
}
You can get the query as a string using the generateQuery function.
import { generateQuery, QueryType } from 'typegraph';
const queryOne: string = generateQuery(Company, QueryType.ONE);
Produces:
{
company {
id
name
industry
}
}
import { generateQuery, QueryType } from 'typegraph';
const queryMany: string = generateQuery(Company, QueryType.MANY);
Produces:
{
companies {
id
name
industry
}
}
import { generateQuery, QueryType } from 'typegraph';
const queryOneWithProps: string = generateQuery(Company, QueryType.ONE, {name: "doge", industry: "dogs"});
Produces:
{
company(name: "doge", industry: "dogs") {
id
name
industry
}
}
- Support for mutations
- Support for params on sub fields
- Support for GraphQL Variables
- Connect components to data! See NEXT.md