Skip to content

Commit 4d6ff45

Browse files
wolfy1339jsoref
andauthored
feat: v5 (#175)
* maint: spelling (#167) Signed-off-by: Josh Soref <[email protected]> BREAKING CHANGE: change spelling of `paginateGraphql` export to `paginateGraphQL` * feat: package is now ESM BREAKING CHANGE: package is now ESM * fix: add return type annotation --------- Co-authored-by: Josh Soref <[email protected]>
1 parent 90f1218 commit 4d6ff45

20 files changed

+126
-113
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ Only one version number is bumped at a time, the highest version change trumps t
5656
Besides publishing a new version to npm, semantic-release also creates a git tag and release
5757
on GitHub, generates changelogs from the commit messages and puts them into the release notes.
5858

59-
Before the publish it runs the `npm run build` script which creates a `pkg/` folder with distributions for browsers, node and Typescript definitions. The contents of the `pkg/` folder are published to the npm registry.
59+
Before the publish it runs the `npm run build` script which creates a `pkg/` folder with distributions for browsers, node and TypeScript definitions. The contents of the `pkg/` folder are published to the npm registry.
6060

6161
If the pull request looks good but does not follow the commit conventions, use the <kbd>Squash & merge</kbd> button.

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Load `@octokit/plugin-paginate-graphql` and [`@octokit/core`](https://github.com
1818
```html
1919
<script type="module">
2020
import { Octokit } from "https://esm.sh/@octokit/core";
21-
import { paginateGraphql } from "https://esm.sh/@octokit/plugin-paginate-graphql";
21+
import { paginateGraphQL } from "https://esm.sh/@octokit/plugin-paginate-graphql";
2222
</script>
2323
```
2424

@@ -30,16 +30,16 @@ Node
3030
Install with `npm install @octokit/core @octokit/plugin-paginate-graphql`. Optionally replace `@octokit/core` with a core-compatible module
3131

3232
```js
33-
const { Octokit } = require("@octokit/core");
34-
const { paginateGraphql } = require("@octokit/plugin-paginate-graphql");
33+
import { Octokit } from "@octokit/core";
34+
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
3535
```
3636

3737
</td></tr>
3838
</tbody>
3939
</table>
4040

4141
```js
42-
const MyOctokit = Octokit.plugin(paginateGraphql);
42+
const MyOctokit = Octokit.plugin(paginateGraphQL);
4343
const octokit = new MyOctokit({ auth: "secret123" });
4444

4545
const { repository } = await octokit.graphql.paginate(
@@ -61,18 +61,18 @@ const { repository } = await octokit.graphql.paginate(
6161
console.log(`Found ${repository.issues.nodes.length} issues!`);
6262
```
6363

64-
There are two convetions this plugin relies on:
64+
There are two conventions this plugin relies on:
6565

6666
1. The name of the cursor variable must be `$cursor`
6767
2. You must include a valid `pageInfo` object in the paginated resource (see [Pagination Direction](#pagination-direction) for more info on what is considered valid)
6868

6969
## `octokit.graphql.paginate()`
7070

71-
The `paginateGraphql` plugin adds a new `octokit.graphql.paginate()` method which accepts a query with a single `$cursor` variable that is used to paginate.
71+
The `paginateGraphQL` plugin adds a new `octokit.graphql.paginate()` method which accepts a query with a single `$cursor` variable that is used to paginate.
7272

7373
The query gets passed over to the `octokit.graphql()`-function. The response is then scanned for the required `pageInfo`-object. If `hasNextPage` is `true`, it will automatically use the `endCursor` to execute the next query until `hasNextPage` is `false`.
7474

75-
While iterating, it ongoingly merges all `nodes` and/or `edges` of all responses and returns a combined response in the end.
75+
While iterating, it continually merges all `nodes` and/or `edges` of all responses and returns a combined response in the end.
7676

7777
> **Warning**
7878
> Please note that this plugin only supports pagination of a single resource - so you can **not** execute queries with parallel or nested pagination. You can find more details in [the chapter below](#unsupported-nested-pagination).
@@ -159,7 +159,7 @@ await octokit.graphql.paginate(
159159

160160
### Pagination Direction
161161

162-
You can control the pagination direction by the properties deinfed in the `pageInfo` resource.
162+
You can control the pagination direction by the properties defined in the `pageInfo` resource.
163163

164164
For a forward pagination, use:
165165

@@ -183,7 +183,7 @@ If you provide all 4 properties in a `pageInfo`, the plugin will default to forw
183183

184184
### Unsupported: Nested pagination
185185

186-
Nested pagination with GraphlQL is complicated, so the following **is not supported**:
186+
Nested pagination with GraphQL is complicated, so the following **is not supported**:
187187

188188
```js
189189
await octokit.graphql.paginate((cursor) => {
@@ -218,7 +218,7 @@ There is a great video from GitHub Universe 2019 [Advanced patterns for GitHub's
218218

219219
### TypeScript Support
220220

221-
You can type the response of the `paginateGraphql()` and `iterator()` functions like this:
221+
You can type the response of the `paginateGraphQL()` and `iterator()` functions like this:
222222

223223
```ts
224224
await octokit.graphql.paginate<RepositoryIssueResponseType>((cursor) => {

package-lock.json

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

package.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
"publishConfig": {
44
"access": "public"
55
},
6+
"type": "module",
67
"version": "0.0.0-development",
78
"description": "Octokit plugin to paginate GraphQL API endpoint responses",
8-
"main": "index.js",
99
"scripts": {
1010
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
1111
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
1212
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
1313
"pretest": "npm run -s lint",
14-
"test": "jest --coverage",
14+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
1515
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict test/typescript-validate.ts",
16-
"test:watch": "jest --watch",
17-
"test:e2e": "jest --testRegex test/*.e2e.ts"
16+
"test:watch": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --watch",
17+
"test:e2e": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --testRegex test/*.e2e.ts"
1818
},
1919
"repository": "github:octokit/plugin-paginate-graphql.js",
2020
"keywords": [
@@ -25,12 +25,12 @@
2525
],
2626
"license": "MIT",
2727
"peerDependencies": {
28-
"@octokit/core": ">=5"
28+
"@octokit/core": ">=6"
2929
},
3030
"devDependencies": {
31-
"@octokit/core": "^5.0.0",
32-
"@octokit/plugin-rest-endpoint-methods": "^10.0.0",
33-
"@octokit/tsconfig": "^2.0.0",
31+
"@octokit/core": "^6.0.0",
32+
"@octokit/plugin-rest-endpoint-methods": "^11.0.0",
33+
"@octokit/tsconfig": "^3.0.0",
3434
"@types/fetch-mock": "^7.3.1",
3535
"@types/jest": "^29.0.0",
3636
"@types/node": "^20.0.0",
@@ -46,11 +46,15 @@
4646
},
4747
"jest": {
4848
"preset": "ts-jest",
49+
"extensionsToTreatAsEsm": [
50+
".ts"
51+
],
4952
"transform": {
5053
"^.+\\.(ts|tsx)$": [
5154
"ts-jest",
5255
{
53-
"tsconfig": "test/tsconfig.test.json"
56+
"tsconfig": "test/tsconfig.test.json",
57+
"useESM": true
5458
}
5559
]
5660
},
@@ -64,6 +68,9 @@
6468
"functions": 100,
6569
"lines": 100
6670
}
71+
},
72+
"moduleNameMapper": {
73+
"^(.+)\\.jsx?$": "$1"
6774
}
6875
},
6976
"release": {

scripts/build.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ async function main() {
7575
...pkg,
7676
files: ["dist-*/**", "bin/**"],
7777
main: "dist-node/index.js",
78-
browser: "dist-web/index.js",
7978
types: "dist-types/index.d.ts",
80-
module: "dist-src/index.js",
79+
exports: {
80+
".": {
81+
types: "./dist-types/index.d.ts",
82+
import: "./dist-node/index.js",
83+
}
84+
},
8185
sideEffects: false,
8286
},
8387
null,

src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CursorValue, PageInfoContext } from "./page-info";
1+
import type { CursorValue, PageInfoContext } from "./page-info.js";
22

33
// Todo: Add link to explanation
44
const generateMessage = (path: string[], cursorValue: CursorValue): string =>

src/extract-page-info.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { PageInfoContext } from "./page-info";
2-
import { findPaginatedResourcePath, get } from "./object-helpers";
1+
import type { PageInfoContext } from "./page-info.js";
2+
import { findPaginatedResourcePath, get } from "./object-helpers.js";
33

44
const extractPageInfos = (responseData: any): PageInfoContext => {
55
const pageInfoPath = findPaginatedResourcePath(responseData);

0 commit comments

Comments
 (0)