diff options
Diffstat (limited to 'app/graphql')
-rw-r--r-- | app/graphql/mutations/concerns/mutations/resolves_group.rb | 15 | ||||
-rw-r--r-- | app/graphql/resolvers/todo_resolver.rb | 90 | ||||
-rw-r--r-- | app/graphql/types/query_type.rb | 5 | ||||
-rw-r--r-- | app/graphql/types/todo_action_enum.rb | 13 | ||||
-rw-r--r-- | app/graphql/types/todo_state_enum.rb | 8 | ||||
-rw-r--r-- | app/graphql/types/todo_target_enum.rb | 9 | ||||
-rw-r--r-- | app/graphql/types/todo_type.rb | 53 | ||||
-rw-r--r-- | app/graphql/types/user_type.rb | 3 |
8 files changed, 196 insertions, 0 deletions
diff --git a/app/graphql/mutations/concerns/mutations/resolves_group.rb b/app/graphql/mutations/concerns/mutations/resolves_group.rb new file mode 100644 index 00000000000..4306ce512f1 --- /dev/null +++ b/app/graphql/mutations/concerns/mutations/resolves_group.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mutations + module ResolvesGroup + extend ActiveSupport::Concern + + def resolve_group(full_path:) + resolver.resolve(full_path: full_path) + end + + def resolver + Resolvers::GroupResolver.new(object: nil, context: context) + end + end +end 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 diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index bbf94fb92df..996bf225976 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -14,6 +14,11 @@ module Types resolver: Resolvers::GroupResolver, description: "Find a group" + field :current_user, Types::UserType, + null: true, + resolve: -> (_obj, _args, context) { context[:current_user] }, + description: "Get information about current user" + field :namespace, Types::NamespaceType, null: true, resolver: Resolvers::NamespaceResolver, diff --git a/app/graphql/types/todo_action_enum.rb b/app/graphql/types/todo_action_enum.rb new file mode 100644 index 00000000000..0e538838474 --- /dev/null +++ b/app/graphql/types/todo_action_enum.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Types + class TodoActionEnum < BaseEnum + value 'assigned', value: 1 + value 'mentioned', value: 2 + value 'build_failed', value: 3 + value 'marked', value: 4 + value 'approval_required', value: 5 + value 'unmergeable', value: 6 + value 'directly_addressed', value: 7 + end +end diff --git a/app/graphql/types/todo_state_enum.rb b/app/graphql/types/todo_state_enum.rb new file mode 100644 index 00000000000..29a28b5208d --- /dev/null +++ b/app/graphql/types/todo_state_enum.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module Types + class TodoStateEnum < BaseEnum + value 'pending' + value 'done' + end +end diff --git a/app/graphql/types/todo_target_enum.rb b/app/graphql/types/todo_target_enum.rb new file mode 100644 index 00000000000..9a7391dcd99 --- /dev/null +++ b/app/graphql/types/todo_target_enum.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Types + class TodoTargetEnum < BaseEnum + value 'Issue' + value 'MergeRequest' + value 'Epic' + end +end diff --git a/app/graphql/types/todo_type.rb b/app/graphql/types/todo_type.rb new file mode 100644 index 00000000000..d36daaf7dec --- /dev/null +++ b/app/graphql/types/todo_type.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +module Types + class TodoType < BaseObject + graphql_name 'Todo' + description 'Representing a todo entry' + + present_using TodoPresenter + + authorize :read_todo + + field :id, GraphQL::ID_TYPE, + description: 'Id of the todo', + null: false + + field :project, Types::ProjectType, + description: 'The project this todo is associated with', + null: true, + authorize: :read_project, + resolve: -> (todo, args, context) { Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, todo.project_id).find } + + field :group, Types::GroupType, + description: 'Group this todo is associated with', + null: true, + authorize: :read_group, + resolve: -> (todo, args, context) { Gitlab::Graphql::Loaders::BatchModelLoader.new(Group, todo.group_id).find } + + field :author, Types::UserType, + description: 'The owner of this todo', + null: false, + resolve: -> (todo, args, context) { Gitlab::Graphql::Loaders::BatchModelLoader.new(User, todo.author_id).find } + + field :action, Types::TodoActionEnum, + description: 'Action of the todo', + null: false + + field :target_type, Types::TodoTargetEnum, + description: 'Target type of the todo', + null: false + + field :body, GraphQL::STRING_TYPE, + description: 'Body of the todo', + null: false + + field :state, Types::TodoStateEnum, + description: 'State of the todo', + null: false + + field :created_at, Types::TimeType, + description: 'Timestamp this todo was created', + null: false + end +end diff --git a/app/graphql/types/user_type.rb b/app/graphql/types/user_type.rb index 9f7d2a171d6..1ba37927b40 100644 --- a/app/graphql/types/user_type.rb +++ b/app/graphql/types/user_type.rb @@ -12,5 +12,8 @@ module Types field :username, GraphQL::STRING_TYPE, null: false # rubocop:disable Graphql/Descriptions field :avatar_url, GraphQL::STRING_TYPE, null: false # rubocop:disable Graphql/Descriptions field :web_url, GraphQL::STRING_TYPE, null: false # rubocop:disable Graphql/Descriptions + field :todos, Types::TodoType.connection_type, null: false, + resolver: Resolvers::TodoResolver, + description: 'Todos of this user' end end |