Skip to main content

Endpoints

The CRUDResolver automatically exposes two query endpoints. The endpoints names will be derived from name provided to @ObjectType or the class name.

The following examples are based on the following TodoItemDTO

todo-item.dto.ts
import { FilterableField } from '@ptc-org/nestjs-query-graphql';
import { ObjectType, ID, GraphQLISODateTime } from '@nestjs/graphql';

@ObjectType('TodoItem')
export class TodoItemDTO {
@IDField(() => ID)
id!: string;

@FilterableField()
title!: string;

@FilterableField()
completed!: boolean;

@FilterableField(() => GraphQLISODateTime)
created!: Date;

@FilterableField(() => GraphQLISODateTime)
updated!: Date;
}

In the following examples you will see two endpoints referenced

  • todoItem - graphql endpoint to find a record by id.
  • todoItems - graphql endpoint to filter, page, and sort records,

Find By Id

The following example finds a TodoItem by id.

{
todoItem(id: "1") {
id
title
completed
created
updated
}
}


Querying

As described above the CRUDResolver will expose a query method called todoItems. The result will be either a connection or array depending on the paging strategy you choose

note

All examples below assume that a connection is returned but filtering and sorting work the same way for all paging strategies. To read how to page collections read the paging docs

By default if you do not provided an arguments you can query for all records.

{
todoItems{
pageInfo{
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges{
node{
id
title
completed
created
updated
}
cursor
}
}
}