Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spelling #167

Merged
merged 7 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ Only one version number is bumped at a time, the highest version change trumps t
Besides publishing a new version to npm, semantic-release also creates a git tag and release
on GitHub, generates changelogs from the commit messages and puts them into the release notes.

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.
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.

If the pull request looks good but does not follow the commit conventions, use the <kbd>Squash & merge</kbd> button.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Load `@octokit/plugin-paginate-graphql` and [`@octokit/core`](https://github.com
```html
<script type="module">
import { Octokit } from "https://esm.sh/@octokit/core";
import { paginateGraphql } from "https://esm.sh/@octokit/plugin-paginate-graphql";
import { paginateGraphQL } from "https://esm.sh/@octokit/plugin-paginate-graphql";
</script>
```

Expand All @@ -31,15 +31,15 @@ Install with `npm install @octokit/core @octokit/plugin-paginate-graphql`. Optio

```js
const { Octokit } = require("@octokit/core");
const { paginateGraphql } = require("@octokit/plugin-paginate-graphql");
const { paginateGraphQL } = require("@octokit/plugin-paginate-graphql");
```

</td></tr>
</tbody>
</table>

```js
const MyOctokit = Octokit.plugin(paginateGraphql);
const MyOctokit = Octokit.plugin(paginateGraphQL);
const octokit = new MyOctokit({ auth: "secret123" });

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

There are two convetions this plugin relies on:
There are two conventions this plugin relies on:

1. The name of the cursor variable must be `$cursor`
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)

## `octokit.graphql.paginate()`

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

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`.

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

> **Warning**
> 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).
Expand Down Expand Up @@ -159,7 +159,7 @@ await octokit.graphql.paginate(

### Pagination Direction

You can control the pagination direction by the properties deinfed in the `pageInfo` resource.
You can control the pagination direction by the properties defined in the `pageInfo` resource.

For a forward pagination, use:

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

### Unsupported: Nested pagination

Nested pagination with GraphlQL is complicated, so the following **is not supported**:
Nested pagination with GraphQL is complicated, so the following **is not supported**:

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

### TypeScript Support

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

```ts
await octokit.graphql.paginate<RepositoryIssueResponseType>((cursor) => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createIterator } from "./iterator";
import { createPaginate } from "./paginate";
export type { PageInfoForward, PageInfoBackward } from "./page-info";

export function paginateGraphql(octokit: Octokit) {
export function paginateGraphQL(octokit: Octokit) {
octokit.graphql;
return {
graphql: Object.assign(octokit.graphql, {
Expand Down
4 changes: 2 additions & 2 deletions test/paginate-graphql.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Octokit } from "@octokit/core";
import { paginateGraphql } from "../src";
import { paginateGraphQL } from "../src";

const PatchedOctokit = Octokit.plugin(paginateGraphql);
const PatchedOctokit = Octokit.plugin(paginateGraphQL);

const token = process.env.E2E_GITHUB_TOKEN;
if (!token) {
Expand Down
2 changes: 1 addition & 1 deletion test/paginate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe("pagination", () => {
`
query paginate($cursor: String, $organization: String!) {
repository(owner: $organization, name: "rest.js") {
issues(first: 10, after: $curosr) {
issues(first: 10, after: $cursor) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test was testing what it thought it was testing.

nodes {
title
}
Expand Down
4 changes: 2 additions & 2 deletions test/testHelpers/mock-octokit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Octokit } from "@octokit/core";
import { paginateGraphql } from "../../src/index";
import { paginateGraphQL } from "../../src/index";
import fetchMock from "fetch-mock";

const PatchedOctokit = Octokit.plugin(paginateGraphql);
const PatchedOctokit = Octokit.plugin(paginateGraphQL);

const MockOctokit = ({ responses = [{}] }: { responses?: any[] } = {}) => {
let calledQueries: string[] = [];
Expand Down
6 changes: 3 additions & 3 deletions test/typescript-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// ************************************************************

import { Octokit } from "@octokit/core";
import { paginateGraphql, PageInfoBackward, PageInfoForward } from "../src";
import { paginateGraphQL, PageInfoBackward, PageInfoForward } from "../src";
import { TestResponseType } from "./testHelpers/mock-response";

const MyOctokit = Octokit.plugin(paginateGraphql);
const MyOctokit = Octokit.plugin(paginateGraphQL);
const octokit = new MyOctokit();

const query = `
Expand Down Expand Up @@ -37,7 +37,7 @@ export async function typedIterator() {
}
}

export function pageInfoBackwaredExported(): PageInfoBackward {
export function pageInfoBackwardExported(): PageInfoBackward {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a test, but, um... I'm not sure what it was doing either.

return {
hasPreviousPage: true,
startCursor: "startCursor",
Expand Down
Loading