summaryrefslogtreecommitdiff
path: root/lib/gitlab/graphql/pagination/filterable_array_connection.rb
blob: 4a76cd5fb000a1a72091b99eb0803f476929e9db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# frozen_string_literal: true

module Gitlab
  module Graphql
    module Pagination
      # FilterableArrayConnection is useful especially for lazy-loaded values.
      # It allows us to call a callback only on the slice of array being
      # rendered in the "after loaded" phase.  For example we can check
      # permissions only on a small subset of items.
      class FilterableArrayConnection < GraphQL::Pagination::ArrayConnection
        def nodes
          @nodes ||= items.filter_callback.call(super)
        end
      end
    end
  end
end