diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2019-06-28 10:02:57 +0000 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2019-06-28 10:02:57 +0000 |
commit | 2321b337f1487031e2cab8e1a4e778f3aaf8e2da (patch) | |
tree | 09ac0a7fe65e4da93f873e4b8cf02b57cd359791 /app/graphql | |
parent | 1012cfb0b780bc9348a8478a66af2a337a69b0f6 (diff) | |
parent | d78f7ceac94abe0e8318c6472fc5f7967325a74f (diff) | |
download | gitlab-ce-2321b337f1487031e2cab8e1a4e778f3aaf8e2da.tar.gz |
Merge branch 'graphql-tree-last-commit' into 'master'
Added commit type to tree GraphQL type
See merge request gitlab-org/gitlab-ce!29412
Diffstat (limited to 'app/graphql')
-rw-r--r-- | app/graphql/types/commit_type.rb | 30 | ||||
-rw-r--r-- | app/graphql/types/tree/tree_type.rb | 5 |
2 files changed, 35 insertions, 0 deletions
diff --git a/app/graphql/types/commit_type.rb b/app/graphql/types/commit_type.rb new file mode 100644 index 00000000000..d73dd73affd --- /dev/null +++ b/app/graphql/types/commit_type.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Types + class CommitType < BaseObject + graphql_name 'Commit' + + authorize :download_code + + present_using CommitPresenter + + field :id, type: GraphQL::ID_TYPE, null: false + field :sha, type: GraphQL::STRING_TYPE, null: false + field :title, type: GraphQL::STRING_TYPE, null: true + field :description, type: GraphQL::STRING_TYPE, null: true + field :message, type: GraphQL::STRING_TYPE, null: true + field :authored_date, type: Types::TimeType, null: true + field :web_url, type: GraphQL::STRING_TYPE, null: false + + # models/commit lazy loads the author by email + field :author, type: Types::UserType, null: true + + field :latest_pipeline, + type: Types::Ci::PipelineType, + null: true, + description: "Latest pipeline for this commit", + resolve: -> (obj, ctx, args) do + Gitlab::Graphql::Loaders::PipelineForShaLoader.new(obj.project, obj.sha).find_last + end + end +end diff --git a/app/graphql/types/tree/tree_type.rb b/app/graphql/types/tree/tree_type.rb index 1ee93ed9542..cbc448a0695 100644 --- a/app/graphql/types/tree/tree_type.rb +++ b/app/graphql/types/tree/tree_type.rb @@ -4,6 +4,11 @@ module Types 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 |