Skip to content

Instantly share code, notes, and snippets.

@halfbug
Last active April 18, 2023 07:16
Show Gist options
  • Save halfbug/b8ce568c89efff1d9de69ff95cbd2e01 to your computer and use it in GitHub Desktop.
Save halfbug/b8ce568c89efff1d9de69ff95cbd2e01 to your computer and use it in GitHub Desktop.
Define a pagination input type:
@InputType()
export class Pagination {
@Field(() => Int, { defaultValue: 0 })
skip: number;
@Field(() => Int, { defaultValue: 10 })
take: number;
}
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