Skip to content

Commit 74856f6

Browse files
feat: add plugin-paginate-graphql (#2487)
* feat: add plugin-paginate-graphql * docs: GraphQL pagination
1 parent ce52402 commit 74856f6

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The `octokit` package integrates the three main Octokit libraries
2727
- [Media Type formats](#media-type-formats)
2828
- [Request error handling](#request-error-handling)
2929
- [GraphQL API queries](#graphql-api-queries)
30+
- [Pagination](#pagination-1)
3031
- [Schema previews](#schema-previews)
3132
- [App client](#app-client)
3233
- [GitHub App](#github-app)
@@ -626,6 +627,40 @@ const { lastIssues } = await octokit.graphql(
626627
);
627628
```
628629

630+
#### Pagination
631+
632+
GitHub's GraphQL API returns a maximum of 100 items. If you want to retrieve all items, you can use the pagination API.
633+
634+
Example: get all issues
635+
636+
```js
637+
const { allIssues } = await octokit.graphql.paginate(
638+
`
639+
query allIssues($owner: String!, $repo: String!, $num: Int = 10, $cursor: String) {
640+
repository(owner: $owner, name: $repo) {
641+
issues(first: $num, after: $cursor) {
642+
edges {
643+
node {
644+
title
645+
}
646+
}
647+
pageInfo {
648+
hasNextPage
649+
endCursor
650+
}
651+
}
652+
}
653+
}
654+
`,
655+
{
656+
owner: "octokit",
657+
repo: "graphql.js",
658+
},
659+
);
660+
```
661+
662+
Learn more about [GitHub's GraphQL Pagination](https://github.com/octokit/plugin-paginate-graphql.js#readme) usage.
663+
629664
#### Schema previews
630665

631666
Previews can be enabled using the `{mediaType: previews: [] }` option.

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@octokit/app": "^14.0.0",
2424
"@octokit/core": "^5.0.0",
2525
"@octokit/oauth-app": "^6.0.0",
26+
"@octokit/plugin-paginate-graphql": "^4.0.0",
2627
"@octokit/plugin-paginate-rest": "^8.0.0",
2728
"@octokit/plugin-rest-endpoint-methods": "^9.0.0",
2829
"@octokit/plugin-retry": "^6.0.0",

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { Octokit, RequestError } from "./octokit";
2+
export type { PageInfoForward, PageInfoBackward } from "./octokit";
23
export { App, OAuthApp, createNodeMiddleware } from "./app";

src/octokit.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import { Octokit as OctokitCore } from "@octokit/core";
22
import { paginateRest } from "@octokit/plugin-paginate-rest";
3+
import { paginateGraphql } from "@octokit/plugin-paginate-graphql";
34
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
45
import { retry } from "@octokit/plugin-retry";
56
import { throttling } from "@octokit/plugin-throttling";
67

78
import { VERSION } from "./version";
89

910
export { RequestError } from "@octokit/request-error";
11+
export type {
12+
PageInfoForward,
13+
PageInfoBackward,
14+
} from "@octokit/plugin-paginate-graphql";
1015

1116
export const Octokit = OctokitCore.plugin(
1217
restEndpointMethods,
1318
paginateRest,
19+
paginateGraphql,
1420
retry,
1521
throttling,
1622
).defaults({

0 commit comments

Comments
 (0)