Class: Resolvers::PackagePipelinesResolver

Inherits:
BaseResolver
  • Object
show all
Includes:
Gitlab::Graphql::Authorize::AuthorizeResource
Defined in:
app/graphql/resolvers/package_pipelines_resolver.rb

Constant Summary collapse

MAX_PAGE_SIZE =

this resolver can be called for 100 packages max and we want to limit the number of build infos returned for each package when using the new finder.

20

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #authorized_resource?, #find_object, #raise_resource_not_available_error!

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

we manage the pagination manually, so opt out of the connection field extension


45
46
47
48
49
50
# File 'app/graphql/resolvers/package_pipelines_resolver.rb', line 45

def self.field_options
  super.merge(
    connection: false,
    extras: [:lookahead]
  )
end

Instance Method Details

#resolve(first: nil, last: nil, after: nil, before: nil, lookahead:) ⇒ Object

This returns a promise for a connection of promises for pipelines: Lazy[Connection[Lazy]] structure


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

def resolve(first: nil, last: nil, after: nil, before: nil, lookahead:)
  default_value = default_value_for(first: first, last: last, after: after, before: before)
  BatchLoader::GraphQL.for(package.id)
                      .batch(default_value: default_value) do |package_ids, loader|
    build_infos = ::Packages::BuildInfosFinder.new(
      package_ids,
      first: first,
      last: last,
      after: decode_cursor(after),
      before: decode_cursor(before),
      max_page_size: MAX_PAGE_SIZE,
      support_next_page: lookahead.selects?(:page_info)
    ).execute

    build_infos.each do |build_info|
      loader.call(build_info.package_id) do |connection|
        connection.items << lazy_load_pipeline(build_info.pipeline_id)
        connection
      end
    end
  end
end