Skip to content

Add paginated_field helper to reduce pagination boilerplate#239

Open
Copilot wants to merge 6 commits intomainfrom
copilot/commonize-collection-field-arguments
Open

Add paginated_field helper to reduce pagination boilerplate#239
Copilot wants to merge 6 commits intomainfrom
copilot/commonize-collection-field-arguments

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

Implementation Plan for Paginated Field Helper

  • Explore repository structure and understand existing codebase
  • Run existing tests to ensure baseline functionality
  • Create PaginatedField module with paginated_field method
  • Extend GraphQL::Schema::Object with the new module
  • Add tests for paginated_field functionality
  • Test with additional arguments in block
  • Update README with usage examples
  • Run all tests to verify implementation
  • Run code review (reviewed - instance_eval is appropriate for DSL context)
  • Run CodeQL security scan (timed out - manual review completed, no security concerns)
  • Address feedback: Revert undesired Gemfile.lock changes
  • Rebase with main and resolve conflicts ✅

Summary

Successfully implemented the paginated_field helper method that reduces boilerplate when defining pagination arguments. The helper:

  • Automatically adds page and per arguments (both optional)
  • Supports additional custom arguments via a block
  • Is fully backward compatible with existing code
  • Has comprehensive test coverage (33 passing tests including new features from main)
  • Is documented in the README with clear examples
  • Works alongside the new collection_field complexity calculation feature
  • Compatible with both GraphQL::Schema::Object and GraphQL::Schema::Resolver

Branch has been successfully merged with main, resolving conflicts between:

  • The new paginated_field helper (this PR)
  • The collection_field complexity calculation feature (from main)
  • GraphQL Resolver support (from main)

All features work together harmoniously.

Security Summary

No security vulnerabilities introduced:

  • The implementation is a simple DSL helper that delegates to existing GraphQL Ruby methods
  • Uses instance_eval appropriately for DSL block evaluation during schema definition
  • No runtime user input handling
  • No new dependencies added
  • All tests pass successfully
Original prompt

This section details on the original issue you should resolve

<issue_title>Commonize collection field arguments</issue_title>
<issue_description>Hi, first of all, thank you for the great library.

Describe the solution

It is verbose to write every pagination arguments if we have lots of fields. I would like to have less verbose way to do it.

    argument :page, Integer, required: false
    argument :limit, Integer, required: false

Describe the users

Those who are working with lots of types with pagination.

Designs

The feature can be implemented by defining paginated_field like this:

# app/graphql/types/base_object.rb

module Types
  class BaseObject < GraphQL::Schema::Object
    module HasPaginatedField
      def paginated_field(name, type, **kwargs, &block)
        field name, type, **kwargs do
          argument :page, GraphQL::Schema::Member::Int, required: true
          argument :per, GraphQL::Schema::Member::Int, required: false
          instance_eval &block if block_given? # Enable to define additional arguments
        end
      end
    end

    edge_type_class(Types::BaseEdge)
    connection_type_class(Types::BaseConnection)
    field_class Types::BaseField

    extend HasPaginatedField
  end
end

So paginated_field can be used in object type definitions like this:

  field :projects, Types::ProjectType.collection_type do
    argument :where, Types::ProjectWhereInput, required: false
    argument :order, String, required: false
  end
  def projects(page: nil, per: nil)
    Project.page(page).per(per)
  end
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 27, 2026 08:51
Co-authored-by: knapo <63880+knapo@users.noreply.github.com>
Co-authored-by: knapo <63880+knapo@users.noreply.github.com>
Copilot AI changed the title [WIP] Commonize collection field arguments for pagination Add paginated_field helper to reduce pagination boilerplate Jan 27, 2026
Copilot AI requested a review from knapo January 27, 2026 08:59
@knapo knapo marked this pull request as ready for review January 27, 2026 09:11
@knapo
Copy link
Member

knapo commented Jan 27, 2026

@copilot your Gemfile.lock changes are not desired

Co-authored-by: knapo <63880+knapo@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 27, 2026

@copilot your Gemfile.lock changes are not desired

Reverted Gemfile.lock to its original state in 79e5417

@knapo
Copy link
Member

knapo commented Jan 27, 2026

@copilot rebase with main and resolve conflicts

Copy link
Contributor Author

Copilot AI commented Jan 27, 2026

@copilot rebase with main and resolve conflicts

Branch rebased with main and conflicts resolved in 17f2e28. All 33 tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commonize collection field arguments

2 participants