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

What exactly do the docs mean by "nested pagination"? #170

Open
williammartin opened this issue Feb 22, 2024 · 2 comments
Open

What exactly do the docs mean by "nested pagination"? #170

williammartin opened this issue Feb 22, 2024 · 2 comments

Comments

@williammartin
Copy link

What would be expected to happen in the case of a query like:

octokit.graphql.paginate(
  `query ($ids: [ID!]!, $cursor: String) {
  nodes(ids: $ids) {
    ... on Repository {
      nameWithOwner
      defaultBranchRef {
        target {
          ... on Commit {
            history(first: 5, after: $cursor) {
              totalCount
              nodes {
                oid
              }
              pageInfo {
                hasNextPage
                endCursor
              }
            }
          }
        }
      }
    }
  }
 }`,
 {
    ids: ["R_kgDOFzp8zg"],
 },
).then(console.log);

There’s a section in the docs about nested pagination being unsupported and I think you would consider this query to have nested pagination but it’s slightly different from the example provided because it only has one layer of pagination, it’s just that the pagination is nested. I guess I’m not totally sure what the docs specifically mean by “nested”.

For what it’s worth, when I run this query I get:

/Users/williammartin/workspace/octokit-playground/node_modules/@octokit/plugin-paginate-graphql/dist-node/index.js:68
    throw new MissingPageInfo(responseData);
          ^

MissingPageInfo: No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: {
  "nodes": [
    {
      "nameWithOwner": "samcoe/gh-triage",
      "defaultBranchRef": {
        "target": {
          "history": {
            "totalCount": 7,
            "nodes": [
              {
                "oid": "d17b7ae2bdf9d3826ccea2b583fd850339821be4"
              },
              {
                "oid": "f7399a6f0bcad0f28ff09ae3af60a03ac14f629d"
              },
              {
                "oid": "8645e1e0199b306d1ed1587c01b75580f57fe170"
              },
              {
                "oid": "003d962ebb25229d570367194bdad3d6f3296c60"
              },
              {
                "oid": "a7c2afb0404dd0b478974998bf07e293cd73c08b"
              }
            ],
            "pageInfo": {
              "hasNextPage": true,
              "endCursor": "d17b7ae2bdf9d3826ccea2b583fd850339821be4 4"
            }
          }
        }
      }
    }
  ]
}
    at findPaginatedResourcePath (/Users/williammartin/workspace/octokit-playground/node_modules/@octokit/plugin-paginate-graphql/dist-node/index.js:68:11)
    at extractPageInfos (/Users/williammartin/workspace/octokit-playground/node_modules/@octokit/plugin-paginate-graphql/dist-node/index.js:108:24)
    at Object.next (/Users/williammartin/workspace/octokit-playground/node_modules/@octokit/plugin-paginate-graphql/dist-node/index.js:139:35)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Function.paginate (/Users/williammartin/workspace/octokit-playground/node_modules/@octokit/plugin-paginate-graphql/dist-node/index.js:189:22) {
  response: {
    nodes: [
      {
        nameWithOwner: 'samcoe/gh-triage',
        defaultBranchRef: { target: { history: [Object] } }
      }
    ]
  }
}

But because I’m already on shaky ground with js and not sure from the previous question if I’m using it correctly I’m not sure if I’m “holding it wrong”.

Adding the real API responses I get from the API as a test to the merge responses functionality shows the same thing.

  it("does something with nested pagination?", () => {
    const response1 = {
      data: {
        nodes: [
          {
            nameWithOwner: "samcoe/gh-triage",
            defaultBranchRef: {
              target: {
                history: {
                  totalCount: 7,
                  nodes: [
                    {
                      oid: "d17b7ae2bdf9d3826ccea2b583fd850339821be4",
                    },
                    {
                      oid: "f7399a6f0bcad0f28ff09ae3af60a03ac14f629d",
                    },
                    {
                      oid: "8645e1e0199b306d1ed1587c01b75580f57fe170",
                    },
                    {
                      oid: "003d962ebb25229d570367194bdad3d6f3296c60",
                    },
                    {
                      oid: "a7c2afb0404dd0b478974998bf07e293cd73c08b",
                    },
                  ],
                  pageInfo: {
                    hasNextPage: true,
                    endCursor: "d17b7ae2bdf9d3826ccea2b583fd850339821be4 4",
                  },
                },
              },
            },
          },
        ],
      },
    };

    const response2 = {
      data: {
        nodes: [
          {
            nameWithOwner: "samcoe/gh-triage",
            defaultBranchRef: {
              target: {
                history: {
                  totalCount: 7,
                  nodes: [
                    {
                      oid: "322114e39d2cb4b0e129b66c798dfdf85baf7d48",
                    },
                    {
                      oid: "7c3e8342d4e4e960e013c1068bead72ec51552a2",
                    },
                  ],
                  pageInfo: {
                    hasNextPage: false,
                    endCursor: "d17b7ae2bdf9d3826ccea2b583fd850339821be4 6",
                  },
                },
              },
            },
          },
        ],
      },
    };

    const result = mergeResponses(response1, response2);
  });
 FAIL  test/merge-responses.test.ts
  ● .mergeResponses() › does something with nested pagination?

    MissingPageInfo: No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: {
      "data": {
        "nodes": [
          {
            "nameWithOwner": "samcoe/gh-triage",
            "defaultBranchRef": {
              "target": {
                "history": {
                  "totalCount": 7,
                  "nodes": [
                    {
                      "oid": "d17b7ae2bdf9d3826ccea2b583fd850339821be4"
                    },
                    {
                      "oid": "f7399a6f0bcad0f28ff09ae3af60a03ac14f629d"
                    },
                    {
                      "oid": "8645e1e0199b306d1ed1587c01b75580f57fe170"
                    },
                    {
                      "oid": "003d962ebb25229d570367194bdad3d6f3296c60"
                    },
                    {
                      "oid": "a7c2afb0404dd0b478974998bf07e293cd73c08b"
                    }
                  ],
                  "pageInfo": {
                    "hasNextPage": true,
                    "endCursor": "d17b7ae2bdf9d3826ccea2b583fd850339821be4 4"
                  }
                }
              }
            }
          }
        ]
      }
    }

      10 |   );
      11 |   if (paginatedResourcePath.length === 0) {
    > 12 |     throw new MissingPageInfo(responseData);
         |           ^
      13 |   }
      14 |   return paginatedResourcePath;
      15 | }

      at findPaginatedResourcePath (src/object-helpers.ts:12:11)
      at mergeResponses (src/merge-responses.ts:11:41)
      at Object.<anonymous> (test/merge-responses.test.ts:197:34)
Copy link

👋 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 labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@williammartin
Copy link
Author

It's been pointed out to me that the query I provided wouldn't make much sense given that a single cursor would be shared between multiple repositories. However, I'm not sure if that is resolvable right now due to #169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

1 participant