{"id":18895878,"url":"https://github.com/echobind/nexus-pagination-plugin","last_synced_at":"2026-02-28T01:30:18.656Z","repository":{"id":98472083,"uuid":"434004070","full_name":"echobind/nexus-pagination-plugin","owner":"echobind","description":"A plugin for adding offset-based pagination to your nexus types","archived":false,"fork":false,"pushed_at":"2022-03-15T19:08:15.000Z","size":53,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-16T12:13:56.175Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/echobind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-01T22:23:36.000Z","updated_at":"2022-01-04T19:39:37.000Z","dependencies_parsed_at":"2023-06-01T21:30:56.921Z","dependency_job_id":null,"html_url":"https://github.com/echobind/nexus-pagination-plugin","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"b8b98ccdfc8bab5007ea918d10e36a12e945cf26"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echobind%2Fnexus-pagination-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echobind%2Fnexus-pagination-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echobind%2Fnexus-pagination-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echobind%2Fnexus-pagination-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/echobind","download_url":"https://codeload.github.com/echobind/nexus-pagination-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239870516,"owners_count":19710736,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T08:30:57.719Z","updated_at":"2026-02-28T01:30:18.611Z","avatar_url":"https://github.com/echobind.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nexus-pagination-plugin\n\n\u003cbr /\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://echobind.com\"\u003e\n    \u003cimg src=\"https://camo.githubusercontent.com/d22763c73585cf5d4cf87534659689c2a6b3f214/68747470733a2f2f7265732d332e636c6f7564696e6172792e636f6d2f6372756e6368626173652d70726f64756374696f6e2f696d6167652f75706c6f61642f635f6c7061642c685f3235362c775f3235362c665f6175746f2c715f6175746f3a65636f2f76313439393437333135312f68326b3233696f6f3479687230676a746f636d792e6a7067\" alt=\"Logo\" width=\"80\" height=\"80\"\u003e\n  \u003c/a\u003e\n\n  \u003ch3 align=\"center\"\u003enexus-pagination-plugin\u003c/h3\u003e\n\u003c/p\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/nexus-pagination-plugin\"\u003e\n    \u003cimg alt=\"NPM version.\" src=\"https://img.shields.io/npm/v/nexus-pagination-plugin\" /\u003e\n  \u003c/a\u003e\n  \u003cimg alt=\"License.\" src=\"https://img.shields.io/github/license/echobind/react-native-template\"\u003e\n\u003c/div\u003e\n\u003chr style=\"margin-bottom:30px;\" \u003e\n\nThis pagination plugin provides a new method on the object definition builder, enabling paginated associations between types, following the offset-based pagination standard defined below.\n\n## Offset-Based Pagination Standard\n\nA paginated query field should receive two arguments:\n\n* `page`\n  * The current page being request. Defaults to 1\n* `pageSize`\n  * The size of pages being used. Defaults to 25\n\nA paginated query field should return a type that contains the following:\n\n* `results`\n  * A collection of the data requested\n* `pageInfo`\n  * A type that contains information about the pagination\n  * `page`\n  * `nextPage`\n  * `totalPages`\n\n## Installation\n\n```\nyarn add nexus-pagination-plugin\n```\nor\n```\nnpm install nexus-pagination-plugin\n```\n\n## Setup\n\n```ts\nimport { makeSchema} from 'nexus';\nimport { paginationPlugin } from 'nexus-pagination-plugin';\n\nexport const schema = makeSchema({\n  // ... types, etc,\n  plugins: [\n    // ... other plugins\n    paginationPlugin()\n  ],\n});\n\n```\n\n## Example Usage\n\nThis plugin surfaces a `t.paginatedQueryResult` function that can be used to add pagination to a given type.\n\n```ts\n// User Type\nexport const User = objectType({\n  name: 'User',\n  description: 'A User',\n  definition(t) {\n    t.nonNull.id('id');\n    t.nonNull.string('firstName');\n    t.nonNull.string('lastName');\n  },\n});\n\n// add paginated users query\nexport const UsersQuery = queryField((t) =\u003e {\n  t.paginatedQueryResult('users', {\n    type: 'User',\n    resolve: async (_root, args, ctx) =\u003e {\n      const { take, skip } = ctx.paginationParams;\n\n      const users = await ctx.prisma.user.findMany({\n        skip,\n        take,\n      });\n      const usersCount = await ctx.prisma.user.count();\n      const pageInfo = ctx.calculatePageInfo(usersCount);\n\n      return {\n        results: users,\n        pageInfo\n      }\n    },\n  })\n})\n```\n\n## `resolve: (root, args, ctx) =\u003e ...`\n\n`t.paginatedQueryResult` wraps the resolve function passed in the query config and adds the following fields on the context object.\n\n### `ctx.paginationParams: {take: number, skip: number}`\n  \n* `take` specifies the page size\n* `skip` specifies how many to skip based on the page size and page arguments\n  \n### `ctx.calculatePageInfo: (count: number) =\u003e PageInfo`\n\n* `count` specifies the total count of records in the DB\n* Returns type [`PageInfo`](#pageinfo)\n\n## Generated Types\n\n### `PageInfo`\n\n```ts\nobjectType({\n  name: 'PageInfo',\n  definition(t) {\n    t.int('page');\n    t.int('nextPage');\n    t.int('totalPages');\n  },\n})\n```\n\n### `Paginated${targeTypename}s`\n\n```ts\nobjectType({\n  name: generatedTypeName,\n  definition(t2) {\n    t2.nonNull.list.field('results', {\n      type: fieldConfig.type,\n      description: `Collection of ${fieldName}`,\n    });\n\n    t2.nonNull.field('pageInfo', {\n      type: 'PageInfo',\n      description: 'Pagination information',\n    });\n  },\n})\n```\n\nFor a paginated field defined on `Query` like this:\n\n```ts\nqueryField((t) =\u003e {\n  t.paginatedQueryField('foos', {\n    type: 'Foo',\n    // ... any additional query config\n  });\n});\n```\n\nThe following types would be generated:\n\n```gql\ntype PageInfo {\n  nextPage: Int\n  page: Int\n  totalPages: Int\n}\n\ntype PaginatedFoos {\n  pageInfo: PageInfo!\n  results: [Foo]!\n}\n\ntype Query {\n  \"\"\" ... other Query fields \"\"\"\n\n  foos(\n    page: Int = 1,\n    pageSize: Int = 25\n  ): PaginatedFoos\n}\n```\n\nNote that the collection type will be added to whatever parent type is specified. This means that if you were to define a paginated field on another object rather than on `Query` like this:\n\n```ts\nobjectType({\n  type: 'Bar',\n  definition(t) {\n    // ... other definitions\n    t.paginatedQueryField('foos', {\n      type: 'Foo',\n      // ... any additional query config\n    });\n  }\n})\n```\n\nThe `foos` query would be added to the `Bar` type rather than the `Query` type:\n\n```gql\ntype Bar {\n  \"\"\" ... other Bar fields \"\"\"\n\n  foos(\n    page: Int = 1\n    pageSize: Int = 25\n  ): PaginatedFoos\n}\n```\n\n## Options\n\n### `defaultPageSize: number`\n\nUsed to specify a different default for the generated `pageSize` argument. Defaults to 25\n\nGlobal usage:\n\n```ts\npaginationPlugin({\n  defaultPageSize: 10\n})\n```\n\nField usage:\n\n```ts\nexport const UsersQuery = queryField((t) =\u003e {\n  t.paginatedQueryResult('users', {\n    // ... any additional query fields\n    defaultPageSize: 10\n  })  \n})\n```\n\n### `getGeneratedTypename: (targetTypename: string) =\u003e string`\n\nUsed to specify a different generated typename for the paginated types. Defaults to `Paginated${targetTypename}s`\n\nUsage:\n\n```ts\npaginationPlugin({\n  getGeneratedTypename: (targetTypename) =\u003e `${targetTypename}sPaginated`\n})\n```\n\n### `generatedTypename: string`\n\nUsed to specify a different generated typename for a specific field. Defaults to `Paginated${targetTypename}s` or whatever is defined by `getGeneratedTypename`\n\nUsage:\n\n```ts\nexport const FinishesQuery = queryField((t) =\u003e {\n  t.paginatedQueryResult('finishes', {\n    type: 'Finish',\n    // ... any additional query fields\n    generatedTypename: 'PaginatedFinishes'\n  })\n})\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fechobind%2Fnexus-pagination-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fechobind%2Fnexus-pagination-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fechobind%2Fnexus-pagination-plugin/lists"}