diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 18:06:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 18:06:17 +0300 |
commit | 238d22c07218adf2b8f3db630ee8b74ca6f29df5 (patch) | |
tree | 23fd5f85efef0fb95eb73bf6395d5b7e8c0f1b9f /app/graphql/resolvers/todo_resolver.rb | |
parent | 6b75320f525f841454f1ab162d141d3610f2e77b (diff) |
Add latest changes from gitlab-org/gitlab@masterlist
Diffstat (limited to 'app/graphql/resolvers/todo_resolver.rb')
-rw-r--r-- | app/graphql/resolvers/todo_resolver.rb | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/app/graphql/resolvers/todo_resolver.rb b/app/graphql/resolvers/todo_resolver.rb new file mode 100644 index 00000000000..38a4539f34a --- /dev/null +++ b/app/graphql/resolvers/todo_resolver.rb @@ -0,0 +1,90 @@ +# frozen_string_literal: true + +module Resolvers + class TodoResolver < BaseResolver + type Types::TodoType, null: true + + alias_method :user, :object + + argument :action, [Types::TodoActionEnum], + required: false, + description: 'The action to be filtered' + + argument :author_id, [GraphQL::ID_TYPE], + required: false, + description: 'The ID of an author' + + argument :project_id, [GraphQL::ID_TYPE], + required: false, + description: 'The ID of a project' + + argument :group_id, [GraphQL::ID_TYPE], + required: false, + description: 'The ID of a group' + + argument :state, [Types::TodoStateEnum], + required: false, + description: 'The state of the todo' + + argument :type, [Types::TodoTargetEnum], + required: false, + description: 'The type of the todo' + + def resolve(**args) + return Todo.none if user != context[:current_user] + + TodosFinder.new(user, todo_finder_params(args)).execute + end + + private + + # TODO: Support multiple queries for e.g. state and type on TodosFinder: + # + # https://gitlab.com/gitlab-org/gitlab/merge_requests/18487 + # https://gitlab.com/gitlab-org/gitlab/merge_requests/18518 + # + # As soon as these MR's are merged, we can refactor this to query by + # multiple contents. + # + def todo_finder_params(args) + { + state: first_state(args), + type: first_type(args), + group_id: first_group_id(args), + author_id: first_author_id(args), + action_id: first_action(args), + project_id: first_project(args) + } + end + + def first_project(args) + first_query_field(args, :project_id) + end + + def first_action(args) + first_query_field(args, :action) + end + + def first_author_id(args) + first_query_field(args, :author_id) + end + + def first_group_id(args) + first_query_field(args, :group_id) + end + + def first_state(args) + first_query_field(args, :state) + end + + def first_type(args) + first_query_field(args, :type) + end + + def first_query_field(query, field) + return unless query.key?(field) + + query[field].first if query[field].respond_to?(:first) + end + end +end |