diff options
Diffstat (limited to 'app/graphql/types/work_items/widgets')
-rw-r--r-- | app/graphql/types/work_items/widgets/hierarchy_type.rb | 23 | ||||
-rw-r--r-- | app/graphql/types/work_items/widgets/notes_type.rb | 26 |
2 files changed, 48 insertions, 1 deletions
diff --git a/app/graphql/types/work_items/widgets/hierarchy_type.rb b/app/graphql/types/work_items/widgets/hierarchy_type.rb index 0ccd8af7dc8..4ec8ec84779 100644 --- a/app/graphql/types/work_items/widgets/hierarchy_type.rb +++ b/app/graphql/types/work_items/widgets/hierarchy_type.rb @@ -20,8 +20,29 @@ module Types null: true, complexity: 5, description: 'Child work items.' + field :has_children, GraphQL::Types::Boolean, + null: false, description: 'Indicates if the work item has children.' + + # rubocop: disable CodeReuse/ActiveRecord + def has_children? + BatchLoader::GraphQL.for(object.work_item.id).batch(default_value: false) do |ids, loader| + links_for_parents = ::WorkItems::ParentLink.for_parents(ids) + .select(:work_item_parent_id) + .group(:work_item_parent_id) + .reorder(nil) + + links_for_parents.each { |link| loader.call(link.work_item_parent_id, true) } + end + end + # rubocop: enable CodeReuse/ActiveRecord + + alias_method :has_children, :has_children? + def children - object.children.inc_relations_for_permission_check + relation = object.children + relation = relation.inc_relations_for_permission_check unless object.children.loaded? + + relation end end # rubocop:enable Graphql/AuthorizeTypes diff --git a/app/graphql/types/work_items/widgets/notes_type.rb b/app/graphql/types/work_items/widgets/notes_type.rb new file mode 100644 index 00000000000..7da2777beee --- /dev/null +++ b/app/graphql/types/work_items/widgets/notes_type.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Types + module WorkItems + module Widgets + # Disabling widget level authorization as it might be too granular + # and we already authorize the parent work item + # rubocop:disable Graphql/AuthorizeTypes + class NotesType < BaseObject + graphql_name 'WorkItemWidgetNotes' + description 'Represents a notes widget' + + implements Types::WorkItems::WidgetInterface + + # This field loads user comments, system notes and resource events as a discussion for an work item, + # raising the complexity considerably. In order to discourage fetching this field as part of fetching + # a list of issues we raise the complexity + field :discussions, Types::Notes::DiscussionType.connection_type, + null: true, + description: "Notes on this work item.", + resolver: Resolvers::WorkItems::WorkItemDiscussionsResolver + end + # rubocop:enable Graphql/AuthorizeTypes + end + end +end |