Decorators

@system-inc/base-foundation · 515c140 · 14 symbols

@GqlArgument

decorator

Defines a named argument to a GraphQL operation, injected into the resolver method's parameter.

GqlArgument: (name: string, options?: ArgOptions) => ParameterDecorator
@GqlQuery(() => Book)
async book(@GqlArgument('id', () => String) id: string): Promise<Book> { ... }

View source ↗

@GqlArguments

decorator

Injects all of a GraphQL operation's arguments as one object, typed by a @GqlArgumentsType class.

GqlArguments: () => ParameterDecorator
@GqlQuery(() => [Book])
async books(@GqlArguments() args: ListBooksArguments): Promise<Book[]> { ... }

View source ↗

An object that can be created from the input to a GraphQL operation. This is a virtual object and will not be created in the GraphQL schema — its fields become individual arguments of the operation. Inject it with @GqlArguments().

GqlArgumentsType: () => ClassDecorator
@GqlArgumentsType()
export class ListBooksArguments {
    @GqlField(() => Number)
    limit: number;

    @GqlField(() => String, { nullable: true })
    genre: string | null;
}

View source ↗

@GqlField

decorator

A field in a @GqlObjectType or @GqlInputType, exposed in the GraphQL schema.

GqlField: () => MethodAndPropDecorator
@GqlObjectType()
export class Book {
    @GqlField(() => String)
    title: string;

    @GqlField(() => Number, { nullable: true })
    year: number | null;
}

View source ↗

Defines a computed field on the resolver's object type, resolved per request. Inject the parent object with @GqlRootObject().

GqlFieldResolver: () => MethodDecorator
@GqlResolver(() => Book)
export class BookResolver {
    @GqlFieldResolver(() => String)
    displayTitle(@GqlRootObject() book: Book): string {
        return `${book.title} (${book.year})`;
    }
}

View source ↗

@GqlInputType

decorator

An object that can be created from the input to a GraphQL operation. This will also create the input in the GraphQL schema.

GqlInputType: () => ClassDecorator
@GqlInputType()
export class BookCreateInput {
    @GqlField(() => String)
    title: string;
}

View source ↗

Defines an interface type in the GraphQL schema, implemented by object types.

GqlInterfaceType: () => ClassDecorator
@GqlInterfaceType()
export abstract class Node {
    @GqlField(() => String)
    id: string;
}

@GqlObjectType({ implements: Node })
export class Book extends Node { ... }

View source ↗

@GqlMutation

decorator

Marks a method as a mutation operation and exposes it in the GraphQL schema.

GqlMutation: () => MethodDecorator
@GqlMutation(() => Book)
async bookCreate(
    @GqlArgument('input', () => BookCreateInput) input: BookCreateInput,
): Promise<Book> { ... }

View source ↗

An object that can be returned from a GraphQL resolver. Creates the type in the GraphQL schema; its @GqlField properties become the type's fields.

GqlObjectType: () => ClassDecorator
@GqlObjectType()
export class Book {
    @GqlField(() => String)
    title: string;
}

View source ↗

@GqlQuery

decorator

Marks a method as a query operation and exposes it in the GraphQL schema.

GqlQuery: () => MethodDecorator
@GqlQuery(() => [Book])
async books(): Promise<Book[]> {
    return await this.bookRepository.find({});
}

View source ↗

@GqlResolver

decorator

A decorator that can be used to define a GraphQL Resolver. This is a service that exposes operations to the GraphQL schema.

Wraps type-graphql's Resolver so the class is recorded in the DecoratorRegistry for boot-time settings validation.

GqlResolver(): ClassDecorator
GqlResolver(typeFunc: ClassTypeResolver): ClassDecorator
GqlResolver(objectType: ClassType): ClassDecorator
@Injectable()
@GqlResolver(() => Book)
export class BookResolver {
    @GqlQuery(() => Book)
    async book(@GqlArgument('id', () => String) id: string): Promise<Book> { ... }
}

View source ↗

Injects the parent (root) object of the operation into a resolver method parameter — typically used inside a @GqlFieldResolver.

GqlRootObject: (propertyName?: string) => ParameterDecorator
@GqlFieldResolver(() => String)
displayTitle(@GqlRootObject() book: Book): string {
    return `${book.title} (${book.year})`;
}

View source ↗

Injects the GqlOperationContext for the surrounding GraphQL operation. The decorated parameter must be typed as a GqlOperationContext<T>; the base/inject-type-matches-parameter lint rule enforces this at compile time.

Pass an explicit generic argument (e.g. @InjectGqlOperationContext<OpContextResult>()) to additionally pin the selection-set element type. With no argument the parameter may be any GqlOperationContext<...>.

InjectGqlOperationContext(): TypedParameterDecorator<GqlOperationContext<T>>
@GqlQuery(() => OperationInfo)
async operationInfo(
    @InjectGqlOperationContext()
    operationContext: GqlOperationContext<OperationInfo>,
): Promise<OperationInfo> {
    return {
        operationType: operationContext.type,
        selectedFields: Object.keys(operationContext.selectionSet),
    };
}

View source ↗

Declares a pagination input type for one operation (or a family of operations sharing the same exposure): which of entity's columns a client may filter and order by.

Apply to a subclass of PaginationInput. The decorator registers the subclass as a named GraphQL input type and synthesizes enum-typed filters/orderBy fields from the declared columns, so the allowlist is part of the schema — an invalid column fails GraphQL validation before resolver code runs — and flows into frontend codegen. The ORM bridge (OrmPaginationInput.from) reads the same declaration to enforce the allowlists at runtime, so vetting cannot be forgotten at a call site.

A bare PaginationInput argument remains the right choice for plain pagination: it accepts page inputs only and rejects client filters and ordering. This decorator is the single opt-in to client-driven filtering/ordering, and the declaration is deliberately explicit — the columns listed here are a statement that the operation's queries were planned for them (see the base check index cross-reference).

Column names are typed as keys of entity (a typo is a compile error at the declaration site) and validated against the entity's ORM metadata at class definition time — the runtime gate still matters because a class property need not be a column (and metadata can drift from types), so a non-column property throws at import, not at first request.

PaginationInputFor(entity: Constructor<Entity>, options: PaginationInputForOptions<Entity>): (target: Constructor<PaginationInput>) => void

View source ↗