summaryrefslogtreecommitdiff
path: root/app/graphql/types/tree/tree_type.rb
blob: cbc448a0695a16a2a92365cf4fcbef8d8c1c6814 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true
module Types
  module Tree
    class TreeType < BaseObject
      graphql_name 'Tree'

      # Complexity 10 as it triggers a Gitaly call on each render
      field :last_commit, Types::CommitType, null: true, complexity: 10, resolve: -> (tree, args, ctx) do
        tree.repository.last_commit_for_path(tree.sha, tree.path)
      end

      field :trees, Types::Tree::TreeEntryType.connection_type, null: false, resolve: -> (obj, args, ctx) do
        Gitlab::Graphql::Representation::TreeEntry.decorate(obj.trees, obj.repository)
      end

      field :submodules, Types::Tree::SubmoduleType.connection_type, null: false

      field :blobs, Types::Tree::BlobType.connection_type, null: false, resolve: -> (obj, args, ctx) do
        Gitlab::Graphql::Representation::TreeEntry.decorate(obj.blobs, obj.repository)
      end
    end
  end
end