> ## Documentation Index
> Fetch the complete documentation index at: https://www.nestjs-query.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Types

> provides a number of types. Most will be automatically generated for you when you create a resolver. However, you can use many of the types in your own code for custom endpoints.

The following examples are based on the following `TodoItemDTO`

```ts theme={null}
import { FilterableField, IDField } 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
}
```

## ArgsTypes[​](#argstypes "Direct link to ArgsTypes")

### QueryArgsType[​](#queryargstype "Direct link to QueryArgsType")

Args type used in `read` endpoints to allow `filtering`, `paging`, and `sorting`.

The `QueryArgsType` will generate an `ArgsType` that will require the user to provide three arguments.

* `filter?` - A filter that should be used to find records to update. See [FilterType](#filtertype)
* `paging?` - Options to page of result.
* `sorting?` - Optional array to allow sorting of results. See [SortType](#sorttype).

#### Usage[​](#usage "Direct link to Usage")

```ts theme={null}
import { QueryArgsType } from '@ptc-org/nestjs-query-graphql'
import { ArgsType } from '@nestjs/graphql'
import { TodoItemDTO } from './dto/todo-item.dto'

@ArgsType()
export class TodoItemQuery extends QueryArgsType(TodoItemDTO) {}
```

***

## ObjectTypes[​](#objecttypes "Direct link to ObjectTypes")

### ConnectionType[​](#connectiontype "Direct link to ConnectionType")

Implementation of [connections](https://facebook.github.io/relay/graphql/connections.htm). Useful for large result sets where the end user should be able to page through the results.

#### Usage[​](#usage-1 "Direct link to Usage")

> [tab] Code
>
> ```ts theme={null}
> import { QueryArgsType } from '@ptc-org/nestjs-query-graphql';
> import { TodoItemDTO } from './dto/todo-item.dto';
>
> export const TodoItemQueryArgs = QueryArgsType(TodoItemDTO)
> export const TodoItemConnection = TodoItemQueryArgs.ConnectionType;
> ```

> [tab] Schema
>
> ```graphql theme={null}
> scalar ConnectionCursor
> type TodoItemConnection {
>   pageInfo: PageInfo!
>   edges: [TodoItemEdge!]!
> }
> type TodoItemEdge {
>   node: TodoItem!
>   cursor: ConnectionCursor!
> }
> type PageInfo {
>   hasNextPage: Boolean
>   hasPreviousPage: Boolean
>   startCursor: ConnectionCursor
>   endCursor: ConnectionCursor
> }
> ```

***

### UpdateManyResponseType[​](#updatemanyresponsetype "Direct link to UpdateManyResponseType")

Response from `updateMany` mutations.

#### Usage[​](#usage-2 "Direct link to Usage")

> [tab] Code
>
> ```ts theme={null}
> import { UpdateManyResponseType } from '@ptc-org/nestjs-query-graphql';
>
> export const UpdateManyResponse = UpdateManyResponseType()
> ```

> [tab] Schema
>
> ```graphql theme={null}
> type UpdateManyResponse {
>   updatedCount: Int!
> }
> ```

***

### DeleteManyResponseType[​](#deletemanyresponsetype "Direct link to DeleteManyResponseType")

Response from `deleteMany` mutations.

#### Usage[​](#usage-3 "Direct link to Usage")

> [tab] Code
>
> ```ts theme={null}
> import { DeleteManyResponseType } from '@ptc-org/nestjs-query-graphql';
>
> export const UpdateManyResponse = DeleteManyResponseType()
> ```

> [tab] Schema
>
> ```graphql theme={null}
> type DeleteManyResponse {
>   deletedCount: Int!
> }
> ```

***

## InputTypes[​](#inputtypes "Direct link to InputTypes")

### FilterType[​](#filtertype "Direct link to FilterType")

GraphQL implementation of the `@ptc-org/nestjs-query-core` `Filter` type.

The `FilterType` is dynamically created based on the fields in the `DTO` annotated with [@FilterableField](https://www.nestjs-query.dev/graphql/dtos.md#filterablefield).

Along with the dynamically create fields filter also has the following static fields:

* `and` - Allows for joining multiple `Filters` with using an `AND` condition.

  For example, find all todo items that `start with 'Foo' AND end in 'Bar'`.

  ```graphql theme={null}
  todoItems(filter: {
    and: [
      {title: {like: "Foo%"}},
      {title: {like: "%Bar"}},
    ]
  }) {
    #...select your fields
  }
  ```

* `or` - Allows for joining multiple `Filters` using an `OR` condition.

  For example, find all todo items that `(are completed AND start with 'Foo') OR (are not completed and end in 'Bar')`.

  ```graphql theme={null}
  todoItems(filter: {
    or: [
      {title: {eq: "Foo"}, completed: {is: true}},
      {title: {eq: "Bar"}, completed: {is: false}},
    ]
  }) {
    #...select your fields
  }
  ```

> [tab] Code
>
> ```ts theme={null}
> import { FilterType } from '@ptc-org/nestjs-query-graphql';
> import { TodoItemDTO } from './dto/todo-item.dto';
>
> export const TodoItemFilter = FilterType(TodoItemDTO)
> ```

> [tab] Schema
>
> ```graphql theme={null}
> input TodoItemFilter {
>   and: [TodoItemFilter!]
>   or: [TodoItemFilter!]
>   id: IDFilterComparison
>   title: StringFieldComparison
>   completed: BooleanFieldComparison
>   created: DateFieldComparison
>   updated: DateFieldComparison
> }
> input IDFilterComparison {
>   is: Boolean
>   isNot: Boolean
>   eq: ID
>   neq: ID
>   gt: ID
>   gte: ID
>   lt: ID
>   lte: ID
>   like: ID
>   notLike: ID
>   iLike: ID
>   notILike: ID
>   in: [ID!]
>   notIn: [ID!]
> }
> input StringFieldComparison {
>   is: Boolean
>   isNot: Boolean
>   eq: String
>   neq: String
>   gt: String
>   gte: String
>   lt: String
>   lte: String
>   like: String
>   notLike: String
>   iLike: String
>   notILike: String
>   in: [String!]
>   notIn: [String!]
> }
> input BooleanFieldComparison {
>   is: Boolean
>   isNot: Boolean
> }
> input DateFieldComparison {
>   is: Boolean
>   isNot: Boolean
>   eq: DateTime
>   neq: DateTime
>   gt: DateTime
>   gte: DateTime
>   lt: DateTime
>   lte: DateTime
>   in: [DateTime!]
>   notIn: [DateTime!]
> }
> ```

***

### SortType[​](#sorttype "Direct link to SortType")

The `SortType` allows you to sort results.

**NOTE** This type is automatically created when using [QueryArgsType](#queryargstype).

For more comprehensive examples take a look at the [Sorting Docs](https://www.nestjs-query.dev/graphql/queries/sorting.md)

#### Fields[​](#fields "Direct link to Fields")

* `field` - The field to sort on. The is an ENUM of [@FilterableFields](https://www.nestjs-query.dev/graphql/dtos.md#filterablefield) defined in the DTO.
* `direction` - The direction to sort the field `ASC` or `DESC`.
* `nulls?` - On supported storage engines you can specify the null sort order `NULLS_FIRST`, `NULLS_LAST`

> [tab] Code
>
> ```ts theme={null}
> import { QueryArgsType } from '@ptc-org/nestjs-query-graphql';
> import { TodoItemDTO } from './dto/todo-item.dto';
>
> export const TodoItemQueryArgs = QueryArgsType(TodoItemDTO)
> export const TodoItemSort = TodoItemQueryArgs.SortType;
> ```

> [tab] Schema
>
> ```graphql theme={null}
> input TodoItemSort {
>   field: TodoItemSortFields!
>   direction: SortDirection!
>   nulls: SortNulls
> }
> enum TodoItemSortFields {
>   id
>   title
>   completed
>   created
>   updated
> }
> enum SortDirection {
>   ASC
>   DESC
> }
> enum SortNulls {
>   NULLS_FIRST
>   NULLS_LAST
> }
> ```

***

### CreateOneInputType[​](#createoneinputtype "Direct link to CreateOneInputType")

Input type for `createOne` mutations.

**NOTE** Dont forget to annotate your DTO with `@InputType()` from `@nestjs/graphql`.

**NOTE** Your DTO should be one that you want to use for input. For example you may not want to let the end user to specify the `created` or `updated` fields so you would create a new DTO just for input.

#### Usage[​](#usage-4 "Direct link to Usage")

```ts theme={null}
import { CreateOneInputType } from '@ptc-org/nestjs-query-graphql'
import { InputType } from '@nestjs/graphql'
import { TodoItemDTO } from './dto/todo-item.dto'

@InputType('TodoItemInput')
export class TodoItemInputDTO {

  @IsString()
  @Field({ nullable: true })
  title?: string

  @IsBoolean()
  @Field({ nullable: true })
  completed?: string
}

@InputType()
export class CreateOneTodoItemInput extends CreateOneInputType('todoItem', TodoItemInputDTO) {}
```

***

### CreateManyInputType[​](#createmanyinputtype "Direct link to CreateManyInputType")

Input type for `createMany` mutations.

**NOTE** Dont forget to annotate your DTO with `@InputType()` from `@nestjs/graphql`.

**NOTE** Your DTO should be one that you want to use for input. For example you may not want to let the end user to specify the `created` or `updated` fields so you would create a new DTO just for input.

#### Usage[​](#usage-5 "Direct link to Usage")

```ts theme={null}
import { CreateManyInputType } from '@ptc-org/nestjs-query-graphql'
import { InputType } from '@nestjs/graphql'
import { TodoItemDTO } from './dto/todo-item.dto'

@InputType('TodoItemInput')
export class TodoItemInputDTO {

  @IsString()
  @Field({ nullable: true })
  title?: string

  @IsBoolean()
  @Field({ nullable: true })
  completed?: string
}

@InputType()
export class CreateManyTodoItemsInput extends CreateManyInputType('todoItems', TodoItemInputDTO) {}
```

### UpdateOneInputType[​](#updateoneinputtype "Direct link to UpdateOneInputType")

InputType type for `updateOne` mutations.

The `UpdateOneInputType` will generate an `InputType` that will require the user to provide two fields.

* `id` - The id of the record to update
* `update` - A record with fields to update.

> [!NOTE]
>
> Dont forget to annotate your DTO with `@InputType()` from `@nestjs/graphql`.

> [!NOTE]
>
> Your DTO should be one that you want to use for updates. For example you may not want to let the end user to update the
> `created` or `updated` fields so you would create a new DTO just for updates.

#### Usage[​](#usage-6 "Direct link to Usage")

```ts theme={null}
import { UpdateOneInputType } from '@ptc-org/nestjs-query-graphql'
import { InputType } from '@nestjs/graphql'
import { TodoItemDTO } from './dto/todo-item.dto'

@InputType('TodoItemUpdateInput')
export class TodoItemUpdateDTO {

  @IsOptional()
  @IsString()
  @Field({ nullable: true })
  title?: string

  @IsOptional()
  @IsBoolean()
  @Field({ nullable: true })
  completed?: boolean
}

@InputType()
export class UpdateOneTodoItemInput extends UpdateOneInputType(TodoItemDTO, TodoItemUpdateDTO) {}
```

***

### UpdateManyInputType[​](#updatemanyinputtype "Direct link to UpdateManyInputType")

Input type for `updateMany` mutations.

The `UpdateOneInputType` will generate an `InputType` that will require the user to provide two arguments.

* `filter` - The filter that should be used to find records to update. See [FilterType](#filtertype)
* `update` - The update to apply to each record found.

**NOTE** Dont forget to annotate your DTO with `@InputType()` from `@nestjs/graphql`.

**NOTE** Your DTO should be one that you want to use for input. For example you may not want to let the end user to specify the `created` or `updated` fields so you would create a new DTO just for input.

#### Usage[​](#usage-7 "Direct link to Usage")

In this example we use the read DTO for the FilterType, and a different update DTO.

```ts theme={null}
import { CreateOneInputType, FilterType } from '@ptc-org/nestjs-query-graphql'
import { InputType } from '@nestjs/graphql'
import { TodoItemDTO } from './dto/todo-item.dto'

@InputType('TodoItemUpdate')
export class TodoItemUpdateDTO {

  @IsOptional()
  @IsString()
  @Field({ nullable: true })
  title?: string

  @IsOptional()
  @IsBoolean()
  @Field({ nullable: true })
  completed?: boolean
}

@InputType()
export class UpdateManyTodoItemsInput extends UpdateManyInputType(
  TodoItemDTO, // filter
  TodoItemUpdateDTO // update DTO
) {}
```

***

### DeleteOneInputType[​](#deleteoneinputtype "Direct link to DeleteOneInputType")

InputType type for `deleteOne` mutations.

The `DeleteOneInputType` will generate an `InputType` that will require the user to provide the id of the record to delete.

#### Usage[​](#usage-8 "Direct link to Usage")

```ts theme={null}
import { DeleteOneInputType } from '@ptc-org/nestjs-query-graphql'
import { InputType } from '@nestjs/graphql'
import { TodoItemDTO } from './dto/todo-item.dto'

@InputType()
export class DeleteOneTodoItemInput extends DeleteOneInputType(TodoItemDTO) {}
```

***

### DeleteManyInputType[​](#deletemanyinputtype "Direct link to DeleteManyInputType")

Input type type for `deleteMany` mutations.

The `DeleteManyInputType` will generate an `InputType` that will require the user to provide:

* `filter` - A filter used to find records to delete. See [FilterType](#filtertype)

#### Usage[​](#usage-9 "Direct link to Usage")

```ts theme={null}
import { CreateOneInputType, FilterType } from '@ptc-org/nestjs-query-graphql'
import { InputType } from '@nestjs/graphql'
import { TodoItemDTO } from './dto/todo-item.dto'

@InputType()
export class DeleteManyTodoItemsInput extends DeleteManyInputType(TodoItemDTO) {}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.