diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-05-21 10:52:24 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-06-05 21:47:42 +0300 |
commit | aa4b1ae71260720b47695b8a256134f20280f61a (patch) | |
tree | 81020f291d634e76fe0a31d906ed73639f634b7d /app/graphql/types | |
parent | 287c34ca1f9af4e395493c99623af8437f82d919 (diff) |
Add `present_using` to types
By specifying a presenter for the object type, we can keep the logic
out of `GitlabSchema`.
The presenter gets initialized using the object being presented, and
the context (including the `current_user`).
Diffstat (limited to 'app/graphql/types')
-rw-r--r-- | app/graphql/types/merge_request_type.rb | 56 | ||||
-rw-r--r-- | app/graphql/types/project_type.rb | 1 |
2 files changed, 27 insertions, 30 deletions
diff --git a/app/graphql/types/merge_request_type.rb b/app/graphql/types/merge_request_type.rb index 9b12f6f2bf3..fc430ca03d5 100644 --- a/app/graphql/types/merge_request_type.rb +++ b/app/graphql/types/merge_request_type.rb @@ -1,50 +1,46 @@ Types::MergeRequestType = GraphQL::ObjectType.define do + present_using MergeRequestPresenter + name 'MergeRequest' field :id, !types.ID field :iid, !types.ID - field :title, types.String + field :title, !types.String field :description, types.String field :state, types.String - - field :created_at, Types::TimeType - field :updated_at, Types::TimeType - - field :source_project, -> { Types::ProjectType } - field :target_project, -> { Types::ProjectType } - + field :created_at, !Types::TimeType + field :updated_at, !Types::TimeType + field :source_project, Types::ProjectType + field :target_project, !Types::ProjectType # Alias for target_project - field :project, -> { Types::ProjectType } - + field :project, !Types::ProjectType + field :project_id, !types.Int, property: :target_project_id field :source_project_id, types.Int - field :target_project_id, types.Int - field :project_id, types.Int - - field :source_branch, types.String - field :target_branch, types.String - + field :target_project_id, !types.Int + field :source_branch, !types.String + field :target_branch, !types.String field :work_in_progress, types.Boolean, property: :work_in_progress? field :merge_when_pipeline_succeeds, types.Boolean - field :sha, types.String, property: :diff_head_sha field :merge_commit_sha, types.String - field :user_notes_count, types.Int field :should_remove_source_branch, types.Boolean, property: :should_remove_source_branch? field :force_remove_source_branch, types.Boolean, property: :force_remove_source_branch? - field :merge_status, types.String - - field :web_url, types.String do - resolve ->(merge_request, args, ctx) { Gitlab::UrlBuilder.build(merge_request) } - end - + field :in_progress_merge_commit_sha, types.String + field :merge_error, types.String + field :allow_maintainer_to_push, types.Boolean + field :should_be_rebased, types.Boolean, property: :should_be_rebased? + field :rebase_commit_sha, types.String + field :rebase_in_progress, types.Boolean, property: :rebase_in_progress? + field :diff_head_sha, types.String + field :merge_commit_message, types.String + field :merge_ongoing, types.Boolean, property: :merge_ongoing? + field :work_in_progress, types.Boolean, property: :work_in_progress? + field :source_branch_exists, types.Boolean, property: :source_branch_exists? + field :mergeable_discussions_state, types.Boolean + field :web_url, types.String, property: :web_url field :upvotes, types.Int field :downvotes, types.Int - - field :subscribed, types.Boolean do - resolve ->(merge_request, args, ctx) do - merge_request.subscribed?(ctx[:current_user], merge_request.target_project) - end - end + field :subscribed, types.Boolean, property: :subscribed? end diff --git a/app/graphql/types/project_type.rb b/app/graphql/types/project_type.rb index bfefc594896..593c1b67830 100644 --- a/app/graphql/types/project_type.rb +++ b/app/graphql/types/project_type.rb @@ -31,6 +31,7 @@ Types::ProjectType = GraphQL::ObjectType.define do field :container_registry_enabled, types.Boolean field :shared_runners_enabled, types.Boolean field :lfs_enabled, types.Boolean + field :ff_only_enabled, types.Boolean, property: :merge_requests_ff_only_enabled field :avatar_url, types.String do resolve ->(project, args, ctx) { project.avatar_url(only_path: false) } |