diff options
author | Phil Hughes <me@iamphill.com> | 2019-06-28 08:30:29 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-06-28 08:30:29 +0100 |
commit | d78f7ceac94abe0e8318c6472fc5f7967325a74f (patch) | |
tree | 831839462f28797c52b8f2452ce3c659c1874b9a /app/graphql | |
parent | 80735a2d4b3615e5bd94ea6032b304b58dd2c357 (diff) | |
download | gitlab-ce-d78f7ceac94abe0e8318c6472fc5f7967325a74f.tar.gz |
Added commit type to tree GraphQL type
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 |