Skip to main content

v0.5.x to v0.6.x

@InjectTypeOrmQueryService

In the v0.6.x an new decorator was added @InjectTypeOrmQueryService to auto-create a TypeOrm query service.

This means you no longer need to manually create a service in order to expose your CRUD endpoints.

To enable decorator import the NestjsQueryTypeOrmModule to your module definition

import { NestjsQueryTypeOrmModule } from '@ptc-org/nestjs-query-typeorm';
import { Module } from '@nestjs/common';
import { TodoItemEntity } from './todo-item.entity';
import { TodoItemResolver } from './todo-item.resolver';

@Module({
providers: [TodoItemResolver],
imports: [NestjsQueryTypeOrmModule.forFeature([TodoItemEntity])],
})
export class TodoItemModule {}

One you have imported the module you can inject a TypeOrmQueryService.

import { QueryService } from '@ptc-org/nestjs-query-core';
import { CRUDResolver } from '@ptc-org/nestjs-query-graphql';
import { Resolver } from '@nestjs/graphql';
import { InjectTypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm';
import { TodoItemDTO } from './dto/todo-item.dto';
import { TodoItemEntity } from './todo-item.entity';

@Resolver(() => TodoItemDTO)
export class TodoItemResolver extends CRUDResolver(TodoItemDTO) {
constructor(@InjectTypeOrmQueryService(TodoItemEntity) readonly service: QueryService<TodoItemEntity>) {
super(service);
}
}

TypeOrmQueryService

In the previous version of @nestjs-query the TypeOrmQueryService translated between the DTO and Entity. For a more in-depth description see #41

In the latest version the TypeOrmQueryService only operates on entities.

v0.5.x

import { QueryService } from '@ptc-org/nestjs-query-core';
import { TypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { TodoItemDTO } from './todo-item.dto';
import { TodoItemEntity } from './todo-item.entity';

@QueryService(TodoItemDTO)
export class TodoItemService extends TypeOrmQueryService<TodoItemDTO, TodoItemEntity> {
constructor(@InjectRepository(TodoItemEntity) readonly repo: Repository<TodoItemEntity>) {
super(repo);
}
}

v0.6.x

import { QueryService } from '@ptc-org/nestjs-query-core';
import { TypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { TodoItemEntity } from './todo-item.entity';

@QueryService(TodoItemEntity)
export class TodoItemService extends TypeOrmQueryService<TodoItemEntity> {
constructor(@InjectRepository(TodoItemEntity) readonly repo: Repository<TodoItemEntity>) {
super(repo);
}
}

AssemblerQueryService

In previous versions of nestjs-query the QueryService would automatically translate betwen your DTO and database type. This created a soft-dependecy between the persistence service and the view layer. In v0.6.0 AssemblerQueryService was introduced to handle translating between your DTO and persistence type.

import { AssemblerQueryService, QueryService } from '@ptc-org/nestjs-query-core';
import { InjectTypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm';
import { TodoItemDTO } from './todo-item.dto';
import { TodoItemAssembler } from './todo-item.assembler';
import { TodoItemEntity } from './todo-item.entity';

@QueryService(TodoItemDTO)
export class TodoItemService extends AssemblerQueryService<TodoItemDTO, TodoItemEntity> {
constructor(
assembler: TodoItemAssembler,
@InjectTypeOrmQueryService(TodoItemEntity) queryService: QueryService<TodoItemEntity>,
) {
super(assembler, queryService);
}
}