Skip to content

Add pagination support to GraphQL-based tools #683

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

mattdholloway
Copy link

@mattdholloway mattdholloway commented Jul 15, 2025

This PR idiomatically implements pagination for GraphQL based tools using the spec described in https://docs.github.com/en/graphql/reference/objects#connection and based on the standard in https://graphql.org/learn/pagination/

Closes: https://github.com/github/copilot-agent-services/issues/296

@mattdholloway mattdholloway self-assigned this Jul 15, 2025
@mattdholloway mattdholloway changed the title initial pagination for ListDiscussions Add pagination support to GraphQL-based tools Jul 15, 2025
@mattdholloway
Copy link
Author

Pagination works for listing discussions but does not currently provide the caller with the details of which page it is on:

Screenshot 2025-07-15 at 16 45 33

@mattdholloway mattdholloway marked this pull request as ready for review July 16, 2025 09:29
@Copilot Copilot AI review requested due to automatic review settings July 16, 2025 09:29
@mattdholloway mattdholloway requested a review from a team as a code owner July 16, 2025 09:29
Copilot

This comment was marked as outdated.

@mattdholloway mattdholloway requested a review from Copilot July 16, 2025 14:59
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds pagination support to GraphQL-based tools for GitHub discussions and related functionality, implementing GitHub's GraphQL cursor-based pagination spec while maintaining compatibility with REST API pagination patterns.

  • Introduces unified pagination using page/perPage parameters that convert to GraphQL 'first' parameter
  • Adds GraphQLPaginationParams type and conversion methods from REST-style pagination
  • Updates GraphQL queries to include pagination parameters and PageInfo for proper cursor-based pagination

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/github/server.go Adds WithUnifiedPagination function, GraphQLPaginationParams type, and ToGraphQLParams conversion method
pkg/github/discussions.go Updates GraphQL discussions tools to use unified pagination with proper PageInfo handling
pkg/github/discussions_test.go Updates test mocks to include PageInfo and fixes variable types for GraphQL compatibility
pkg/github/server_test.go Updates test expectations for capitalized PaginationParams fields
Multiple REST files Updates field references from lowercase to capitalized PaginationParams fields
README.md Updates documentation to reflect new pagination parameters for discussion tools

}

// Use default of 100 if pagination was not explicitly provided
if !paginationExplicit {
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

The logic for detecting explicit pagination parameters is duplicated across multiple functions. Consider extracting this into a helper function to reduce code duplication.

Copilot uses AI. Check for mistakes.

@@ -102,6 +119,11 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
}
discussions = append(discussions, di)
}

out, err = json.Marshal(discussions)
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

JSON marshaling is duplicated in both conditional branches. Consider moving this logic outside the conditional blocks to reduce duplication.

Copilot uses AI. Check for mistakes.

@mattdholloway
Copy link
Author

A downside of using cursor-based pagination in GraphQL is that there is no way of 'skipping' pages as the ID of the final entry of the previously - I am investigating falling back to the REST api if the user needs this functionality.

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

Successfully merging this pull request may close these issues.

1 participant