Build type-safe GraphQL APIs using the code-first approach. Define your schema using decorators.
Generate schema from TypeScript classes.
Types are shared between code and schema.
Build a data graph across services.
Class-based resolvers with DI.
1import { createApp, GraphQLModule } from "canxjs";23const app = createApp({4imports: [5GraphQLModule.forRoot({6autoSchemaFile: 'schema.gql', // Code-first7sortSchema: true,8playground: true9})10]11});
1import { ObjectType, Field, ID } from "canxjs";23@ObjectType()4export class User {5@Field({ type: ID })6id: string;78@Field()9name: string;1011@Field({ nullable: true })12email?: string;13}
1import { Resolver, Query, Mutation, Args, ID } from "canxjs";23@Resolver(User)4export class UserResolver {5constructor(private userService: UserService) {}67@Query({ type: User })8async user(@Args({ name: 'id', type: ID }) id: string) {9return this.userService.findOne(id);10}1112@Mutation({ type: User })13async createUser(@Args({ name: 'name' }) name: string) {14return this.userService.create({ name });15}16}