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

[FEAT]: Better error message for pageInfo inside an array #238

Open
1 task done
jyasskin opened this issue Oct 3, 2024 · 1 comment
Open
1 task done

[FEAT]: Better error message for pageInfo inside an array #238

jyasskin opened this issue Oct 3, 2024 · 1 comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Feature New feature or request

Comments

@jyasskin
Copy link

jyasskin commented Oct 3, 2024

Describe the need

If you run:

import { Octokit } from "@octokit/core";
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
import process from "node:process";
const octokit = new (Octokit.plugin(paginateGraphQL))({
  auth: process.env.GITHUB_TOKEN,
});

console.log(
  await octokit.graphql.paginate(`query ($cursor: String) {
    nodes(ids: ["MDU6SXNzdWUxMDA1NzMzMzY2"]) {
      ... on Issue {
        timelineItems(first: 100, after: $cursor, itemTypes: [ISSUE_COMMENT]) {
          pageInfo {
            endCursor
            hasNextPage
          }
          nodes {
            __typename
          }
        }
      }
    }
  }
`)
);

you'll get the error:

file:///.../node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@octokit/plugin-paginate-graphql/dist-bundle/index.js:41
    throw new MissingPageInfo(responseData);
          ^

MissingPageInfo: No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: {
  "nodes": [
    {
      "timelineItems": {
        "pageInfo": {
          "endCursor": "Y3Vyc29yOnYyOpPPAAABj8psBWAAqjIxNDAyNTEyNjY=",
          "hasNextPage": false
        },
        "nodes": [
          {
...

This is confusing because there clearly is a pageInfo property sitting there, and there's only one item to page through. The fix is to use the node query instead of the nodes query to get rid of the 1-element array, and the error message could say that.

Or the code could notice that there's exactly one pageInfo object and optimistically page through that even though it's surrounded by an array.

SDK Version

@octokit/plugin-paginate-graphql 5.2.2

API Version

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jyasskin jyasskin added Status: Triage This is being looked at and prioritized Type: Feature New feature or request labels Oct 3, 2024
Copy link

github-actions bot commented Oct 3, 2024

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@github-project-automation github-project-automation bot moved this to 🆕 Triage in 🧰 Octokit Active Oct 3, 2024
@kfcampbell kfcampbell moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active Oct 7, 2024
@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Feature New feature or request
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

2 participants