Commit 068aa93f authored by Sean McGivern's avatar Sean McGivern

Merge branch 'bw-offset-pagination' into 'master'

GraphQL: Subclass offset based pagination

See merge request gitlab-org/gitlab!26126
parents 792ff555 a3a260ae
...@@ -16,6 +16,10 @@ module Gitlab ...@@ -16,6 +16,10 @@ module Gitlab
Gitlab::Graphql::ExternallyPaginatedArray, Gitlab::Graphql::ExternallyPaginatedArray,
Gitlab::Graphql::Connections::ExternallyPaginatedArrayConnection Gitlab::Graphql::Connections::ExternallyPaginatedArrayConnection
) )
GraphQL::Relay::BaseConnection.register_connection_implementation(
Gitlab::Graphql::Pagination::Relations::OffsetActiveRecordRelation,
Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection
)
end end
end end
end end
......
# frozen_string_literal: true
# We use the Keyset / Stable cursor connection by default for ActiveRecord::Relation.
# However, there are times when that may not be powerful enough (yet), and we
# want to use standard offset pagination.
module Gitlab
module Graphql
module Pagination
class OffsetActiveRecordRelationConnection < GraphQL::Relay::RelationConnection
end
end
end
end
# frozen_string_literal: true
module Gitlab
module Graphql
module Pagination
module Relations
class OffsetActiveRecordRelation < ::ActiveRecord::Relation
end
end
end
end
end
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
require 'spec_helper' require 'spec_helper'
describe GitlabSchema do describe GitlabSchema do
let_it_be(:implementations) { GraphQL::Relay::BaseConnection::CONNECTION_IMPLEMENTATIONS }
let(:user) { build :user } let(:user) { build :user }
it 'uses batch loading' do it 'uses batch loading' do
...@@ -33,12 +34,30 @@ describe GitlabSchema do ...@@ -33,12 +34,30 @@ describe GitlabSchema do
expect(described_class.query).to eq(::Types::QueryType.to_graphql) expect(described_class.query).to eq(::Types::QueryType.to_graphql)
end end
it 'paginates active record relations using `Gitlab::Graphql::Connections::KeysetConnection`' do it 'paginates active record relations using `Connections::Keyset::Connection`' do
connection = GraphQL::Relay::BaseConnection::CONNECTION_IMPLEMENTATIONS[ActiveRecord::Relation.name] connection = implementations[ActiveRecord::Relation.name]
expect(connection).to eq(Gitlab::Graphql::Connections::Keyset::Connection) expect(connection).to eq(Gitlab::Graphql::Connections::Keyset::Connection)
end end
it 'paginates ExternallyPaginatedArray using `Connections::ExternallyPaginatedArrayConnection`' do
connection = implementations[Gitlab::Graphql::ExternallyPaginatedArray.name]
expect(connection).to eq(Gitlab::Graphql::Connections::ExternallyPaginatedArrayConnection)
end
it 'paginates FilterableArray using `Connections::FilterableArrayConnection`' do
connection = implementations[Gitlab::Graphql::FilterableArray.name]
expect(connection).to eq(Gitlab::Graphql::Connections::FilterableArrayConnection)
end
it 'paginates OffsetActiveRecordRelation using `Pagination::OffsetActiveRecordRelationConnection`' do
connection = implementations[Gitlab::Graphql::Pagination::Relations::OffsetActiveRecordRelation.name]
expect(connection).to eq(Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection)
end
describe '.execute' do describe '.execute' do
context 'for different types of users' do context 'for different types of users' do
context 'when no context' do context 'when no context' do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection do
it 'subclasses from GraphQL::Relay::RelationConnection' do
expect(described_class.superclass).to eq GraphQL::Relay::RelationConnection
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment