Skip to content

GraphQL: Check that connections support keyset pagination

Brett Walker requested to merge bw-validate-graphql-type-connections into master

What does this MR do?

When a GraphQL type, such as Types::ProjectType uses a field as a connection type (which uses our underlying keyset/cursor pagination), we want to ensure that the type has been tested that it supports the pagination

module Types
  class ProjectType < BaseObject
    field :issues, # rubocop:disable Graphql/Descriptions
          Types::IssueType.connection_type,
          null: true,
          resolver: Resolvers::IssuesResolver
  end
end

We need to make sure that Types::IssueType has been properly tested with the pagination.

This MR implements one proposal. An overall spec was written in gitlab_schema_spec.rb that iterates over the schema, detects connection fields, and checks a flag on the type that indicates it supports pagination. For example, by adding

    # means specs written/pass for using this type as a paginated connection
    supports_keyset_pagination

to the Types::IssueType, that indicates that we've tested this type with keyset pagination.

Of course, this is manual - a developer must write the specs and add the supports_keyset_pagination, and of course it could be added without the actual specs. So it's far from perfect or automated. But the comment should stay with the line to highlight it when someone copy/pastes the code.

Very much open to a better way to solve this.

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Merge request reports