Skip to main content

v0.23.x to v0.24.x

Removed Public ConnectionType and SortType function.#

In versions prior to v0.24.0 the ConnectionType and SortType functions could be used to get a reference to a Connection and Sort graphql implementation. In v0.24.0 there public methods were removed in favor of pulling them off of the QueryArgs.

This change was made to remove possibility of creating ConnectionTypes and SortTypes that are incompatible with the QueryArgsType.


import { ConnectionType, SortType } from '@nestjs-query/query-graphql';import { TodoItemDTO } from './dto/todo-item.dto';
export const TodoItemConnection = ConnectionType(TodoItemDTO);export const TodoItemSort = SortType(TodoItemDTO);


import { QueryArgsType } from '@nestjs-query/query-graphql';import { TodoItemDTO } from './dto/todo-item.dto';
export const TodoItemQueryArgs = QueryArgsType(TodoItemDTO)export const TodoItemConnection = TodoItemQueryArgs.ConnectionType;export const TodoItemSort = TodoItemQueryArgs.SortType;

@QueryOptions Decorator#

In previous versions you had to specify options for querying and connections in your resolver. In v0.24.0 a new @QueryOptions decorator was introduced to allow specifying all query related options along side the DTO, instead of splitting the configuration between the resolver and DTO. The new @QueryOptions provides a few benefits.

  • Better re-use across types by avoiding passing configuration options all the way through the code to each piece that may need them.
  • Decoupling query options from the resolver. This puts us in a better position to decouple the DTO definition from the transport layer (e.g. graphql)
  • Keeps DTO configuration options closer to the source.


import { NestjsQueryGraphQLModule } from '@nestjs-query/query-graphql';import { NestjsQueryTypeOrmModule } from '@nestjs-query/query-typeorm';import { Module } from '@nestjs/common';import { TodoItemDTO } from './todo-item.dto';import { TodoItemEntity } from './todo-item.entity';
@Module({  imports: [    NestjsQueryGraphQLModule.forFeature({      imports: [NestjsQueryTypeOrmModule.forFeature([TodoItemEntity])],      resolvers: [{        DTOClass: TodoItemDTO,        EntityClass: TodoItemEntity,        pagingStrategy: PagingStrategies.OFFSET,        enableTotalCount: true,        defaultResultSize: 5,        maxResultSize: 100,        defaultFilter: { completed: { is: true } },        defaultSort: [{ field: 'title', direction: SortDirection.ASC }],      }],    }),  ],})export class TodoItemModule {}


import { FilterableField, QueryOptions, PagingStrategies } from '@nestjs-query/query-graphql';import { ObjectType, ID, GraphQLISODateTime, Field } from '@nestjs/graphql';
@ObjectType('TodoItem')@QueryOptions({  pagingStrategy: PagingStrategies.OFFSET, // use offset based paging for this DTO  enableTotalCount: true, // enable querying for totalCount  defaultResultSize: 5, // return 5 records by default  maxResultSize: 100, // do not allow querying for more than 100 records at a time  defaultFilter: { completed: { is: true } }, // default filter when one is not provided  defaultSort: [{ field: 'title', direction: SortDirection.ASC }], // default sort when one is not provided.})export class TodoItemDTO {  @FilterableField(() => ID)  id!: string;
  @FilterableField()  title!: string;
  @FilterableField()  completed!: boolean;
  @FilterableField(() => GraphQLISODateTime)  created!: Date;
  @FilterableField(() => GraphQLISODateTime)  updated!: Date;}