MichalLytek / MichalLytek/type-graphql

Pagination model

Open
#142 39 comments 59 reactions 1 assignee View on GitHub

@MichalLytek is already working on this.

Since Oct 24, 2018.

Discussion :speech_balloon: Enhancement :new:
Dominant language
TypeScript
Stars
8.1k
Forks
672
PR merge metrics
No merged PRs in 30d

Description

I think it might be nice to have a pagination model that will allow to create universal resolvers, types definitions, etc. for collections.

For now I am going to expose two types of models:

Simple pagination

Like with standard rest apis - only offset (skip), limit (take), count and items.

@Resolver()
class SampleResolver {
  @Query(returns => [Type])
  paginatedQuery(
    @PaginationArgs() { offset, limit }: PaginationArgs,
  ): PaginationResponse<Type> {
    // ...
    return [data, count];
  }
}

By using @PaginationArgs() it will detect that the query is being paginated, so the returned tuple [TData, number] will be converted into an object with page info (hasNextPage, etc.), data and total properties.

Relay connection

Using cursor model, which is better for highly dynamic collections:
https://facebook.github.io/relay/graphql/connections.htm

API - TBD.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.