Last active
April 18, 2023 07:16
-
-
Save halfbug/b8ce568c89efff1d9de69ff95cbd2e01 to your computer and use it in GitHub Desktop.
Define a pagination input type:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@InputType() | |
export class Pagination { | |
@Field(() => Int, { defaultValue: 0 }) | |
skip: number; | |
@Field(() => Int, { defaultValue: 10 }) | |
take: number; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Args, Query, Resolver } from '@nestjs/graphql'; | |
import { PaginationInput } from './pagination.input'; | |
import { UsersService } from './users.service'; | |
@Resolver() | |
export class UsersResolver { | |
constructor(private usersService: UsersService) {} | |
@Query(() => [User]) | |
async getUsers(@Args('pagination') pagination: PaginationInput) { | |
const { skip, take } = pagination; | |
return this.usersService.getUsers(skip, take); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment