Class: Resolvers::PaginatedTreeResolver

Inherits:
BaseResolver
  • Object
show all
Defined in:
app/graphql/resolvers/paginated_tree_resolver.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseResolver

as_single, authorization, authorized?, before_connection_authorization, before_connection_authorization_block, calls_gitaly!, complexity, complexity_multiplier, #current_user, last, #object, #offset_pagination, requires_argument!, resolver_complexity, #select_result, single, #single?, single_definition_blocks, singular_type, when_single

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Class Method Details

.field_optionsObject


43
44
45
# File 'app/graphql/resolvers/paginated_tree_resolver.rb', line 43

def self.field_options
  super.merge(connection: false) # we manage the pagination manually, so opt out of the connection field extension
end

Instance Method Details

#resolve(**args) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/graphql/resolvers/paginated_tree_resolver.rb', line 24

def resolve(**args)
  return unless repository.exists?

  cursor = args.delete(:after)
  args[:ref] ||= :head

  pagination_params = {
    limit: @field.max_page_size || 100,
    page_token: cursor
  }

  tree = repository.tree(args[:ref], args[:path], recursive: args[:recursive], pagination_params: pagination_params)

  next_cursor = tree.cursor&.next_cursor
  Gitlab::Graphql::ExternallyPaginatedArray.new(cursor, next_cursor, *tree)
rescue Gitlab::Git::CommandError => e
  raise Gitlab::Graphql::Errors::ArgumentError, e
end