Skip to content

Commit

Permalink
chore(): Update typegoose example to use QueryOptions decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed Mar 11, 2021
1 parent e25d3f7 commit ccc2abe
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion examples/typegoose/src/sub-task/dto/sub-task.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { FilterableField, KeySet, Relation } from '@nestjs-query/query-graphql';
import { FilterableField, KeySet, QueryOptions, Relation } from '@nestjs-query/query-graphql';
import { ObjectType, ID, GraphQLISODateTime } from '@nestjs/graphql';
import { TodoItemDTO } from '../../todo-item/dto/todo-item.dto';

@ObjectType('SubTask')
@KeySet(['id'])
@QueryOptions({ enableTotalCount: true })
@Relation('todoItem', () => TodoItemDTO, { disableRemove: true })
export class SubTaskDTO {
@FilterableField(() => ID)
Expand Down
1 change: 0 additions & 1 deletion examples/typegoose/src/sub-task/sub-task.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { SubTaskEntity } from './sub-task.entity';
EntityClass: SubTaskEntity,
CreateDTOClass: CreateSubTaskDTO,
UpdateDTOClass: SubTaskUpdateDTO,
enableTotalCount: true,
enableAggregate: true,
},
],
Expand Down
2 changes: 2 additions & 0 deletions examples/typegoose/src/tag/dto/tag.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
UpdateManyInputType,
KeySet,
CursorConnection,
QueryOptions,
} from '@nestjs-query/query-graphql';
import { ObjectType, ID, GraphQLISODateTime } from '@nestjs/graphql';
import { TodoItemDTO } from '../../todo-item/dto/todo-item.dto';
Expand All @@ -19,6 +20,7 @@ import { getUserName } from '../../helpers';

@ObjectType('Tag')
@KeySet(['id'])
@QueryOptions({ enableTotalCount: true })
@CursorConnection('todoItems', () => TodoItemDTO, { disableUpdate: true, disableRemove: true })
@BeforeCreateOne((input: CreateOneInputType<TagDTO>, context: GqlContext) => {
input.input.createdBy = getUserName(context);
Expand Down
1 change: 0 additions & 1 deletion examples/typegoose/src/tag/tag.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { TagEntity } from './tag.entity';
EntityClass: TagEntity,
CreateDTOClass: TagInputDTO,
UpdateDTOClass: TagInputDTO,
enableTotalCount: true,
enableAggregate: true,
},
],
Expand Down
3 changes: 2 additions & 1 deletion examples/typegoose/src/todo-item/dto/todo-item.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { FilterableField, KeySet, CursorConnection } from '@nestjs-query/query-graphql';
import { FilterableField, KeySet, CursorConnection, QueryOptions } from '@nestjs-query/query-graphql';
import { ObjectType, ID, GraphQLISODateTime, Field } from '@nestjs/graphql';
import { AuthGuard } from '../../auth.guard';
import { SubTaskDTO } from '../../sub-task/dto/sub-task.dto';
import { TagDTO } from '../../tag/dto/tag.dto';

@ObjectType('TodoItem')
@KeySet(['id'])
@QueryOptions({ enableTotalCount: true })
@CursorConnection('subTasks', () => SubTaskDTO, { disableRemove: true, guards: [AuthGuard] })
@CursorConnection('tags', () => TagDTO, { guards: [AuthGuard] })
export class TodoItemDTO {
Expand Down
1 change: 0 additions & 1 deletion examples/typegoose/src/todo-item/todo-item.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const guards = [AuthGuard];
AssemblerClass: TodoItemAssembler,
CreateDTOClass: TodoItemInputDTO,
UpdateDTOClass: TodoItemUpdateDTO,
enableTotalCount: true,
enableAggregate: true,
aggregate: { guards },
create: { guards },
Expand Down
8 changes: 4 additions & 4 deletions examples/typegoose/src/todo-item/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ConnectionType, QueryArgsType } from '@nestjs-query/query-graphql';
import { QueryArgsType } from '@nestjs-query/query-graphql';
import { ArgsType } from '@nestjs/graphql';
import { TodoItemDTO } from './dto/todo-item.dto';

export const TodoItemConnection = ConnectionType(TodoItemDTO, { enableTotalCount: true });

@ArgsType()
export class TodoItemQuery extends QueryArgsType(TodoItemDTO, { defaultResultSize: 2 }) {}
export class TodoItemQuery extends QueryArgsType(TodoItemDTO) {}

export const TodoItemConnection = TodoItemQuery.ConnectionType;

0 comments on commit ccc2abe

Please sign in to comment.