Class: Resolvers::BlobsResolver

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

Constant Summary

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, calculate_ext_conn_complexity, calls_gitaly!, complexity, complexity_multiplier, #current_user, field_options, last, #object, #offset_pagination, requires_argument!, #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!

Class Method Details

.resolver_complexity(args, child_complexity:) ⇒ Object

We fetch blobs from Gitaly efficiently but it still scales O(N) with the number of paths being fetched, so apply a scaling limit to that.



27
28
29
# File 'app/graphql/resolvers/blobs_resolver.rb', line 27

def self.resolver_complexity(args, child_complexity:)
  super + (args[:paths] || []).size
end

Instance Method Details

#resolve(paths:, ref:, ref_type:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/graphql/resolvers/blobs_resolver.rb', line 31

def resolve(paths:, ref:, ref_type:)
  authorize!(repository.container)

  return [] if repository.empty?

  ref ||= repository.root_ref
  validate_ref(ref)

  ref = ExtractsRef.qualify_ref(ref, ref_type)

  repository.blobs_at(paths.map { |path| [ref, path] }).tap do |blobs|
    blobs.each do |blob|
      blob.ref_type = ref_type
    end
  end
end