graphql-pokemon icon indicating copy to clipboard operation
graphql-pokemon copied to clipboard

request: paginate the response of `getAllPokemon` to allow for further nesting of data

Open favna opened this issue 8 months ago • 0 comments

Is there an existing issue or pull request for this?

  • [X] I have searched the existing issues and pull requests

Feature description

Currently the response of getAllPokemon is, by default, not paginated. This sets a hard limit on how much data can be returned defined by the string limit that the v8 engine can handle (~1GB). At the time of writing (2023-15-12) with the data from Scarlet & Violet Indigo Disk the full JSON is ~524 MB. This size will ever only increase as time goes on and more Pokémon are released. Furthermore, this limit also blocks the expansion of further nesting data, such as changing otherFormes to be proper Pokemon references as opposed to just species strings.

[!IMPORTANT] This change would be a breaking change because the response of getAllPokemon would drastically change.

Desired solution

To resolve this issue the response from getAllPokemon should be paginated by default. The following rules will be applied:

  • If no pagination options are provided by the user the default amount per page of 250 is used
  • Input validation will ensure the user can never request more than 250 Pokémon per page
  • The following interface will be used for a paged response:
interface PaginatedResponse {
  data: TheOldDataObject;
  totalCount: number; // The total count of results
  pages: number; // The total amount of pages based on taken and totalCount
  page: number; // The current page number
  offsetForCurrentPage: number; // The offset provided for this request
  offsetNextPage: number; // The offset to provide to jump to the next page
  taken: number; // The amount taken (length of data)
}

Alternatives considered

  • Migrating to a different programming language than TypeScript that doesn't have the 1GB limit that v8 does. This however is only delaying the inevitable because at some point any programming language is going to run out of space.

Additional context

#899 where otherFormes nesting was added as an attempt to provide more data to the end-user

favna avatar Dec 15 '23 21:12 favna