@nl-framework/graphql
v0.3.5
Published
GraphQL module for nl-framework with code-first schema generation and Apollo Federation support.
Maintainers
Readme
@nl-framework/graphql
Code-first GraphQL layer for the Nael Framework with resolver decorators, schema generation, and Apollo Federation support.
Installation
bun add @nl-framework/graphql graphqlHighlights
- Resolver decorators – annotate queries, mutations, subscriptions, and field resolvers with expressive decorators.
- Schema tooling – generate SDL from TypeScript metadata or stitch existing schemas with federation directives.
- Input sanitization – arguments decorated with class-validator rules are transformed via
class-transformerbefore resolvers execute, rejecting invalid payloads withBAD_USER_INPUTerrors. - Module integration – register resolvers alongside providers using standard Nael modules.
Quick start
import { Module } from '@nl-framework/core';
import { Resolver, Query, Mutation, Args, InputType, Field } from '@nl-framework/graphql';
import { NaelFactory } from '@nl-framework/platform';
import { IsEmail, IsOptional, IsString, MinLength } from 'class-validator';
@InputType()
class CreateUserInput {
@Field()
@IsEmail()
email!: string;
@Field({ nullable: true })
@IsOptional()
@IsString()
@MinLength(2)
name?: string;
}
@Resolver('User')
class UsersResolver {
private readonly users = new Map<string, { id: string; email: string; name?: string }>();
@Query(() => [String])
users() {
return Array.from(this.users.values());
}
@Mutation(() => String)
createUser(@Args('input', () => CreateUserInput) input: CreateUserInput) {
const id = crypto.randomUUID();
this.users.set(id, { id, email: input.email, name: input.name });
return id;
}
}
@Module({
providers: [UsersResolver],
resolvers: [UsersResolver],
})
class GraphqlModule {}
const app = await NaelFactory.create(GraphqlModule);
const { graphql } = await app.listen({ http: 4000 });
console.log('GraphQL ready at', graphql?.url ?? 'http://localhost:4000/graphql');License
Apache-2.0
