-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQL - Group Attachment Resolver + AttachFilesToGroup Mutation (#763)
* first cut, working functionality * update schema * Fix auth + add test case * add tests for attaching files to group * add test cases and fixtures
- Loading branch information
1 parent
d54efd9
commit 622a807
Showing
14 changed files
with
700 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mutations | ||
# Mutation that attaches files to group | ||
class AttachFilesToGroup < BaseMutation | ||
description 'Attaches files to group.' | ||
argument :files, [String], required: true, description: 'A list of files (signedBlobId) to attach to the group' | ||
argument :group_id, ID, | ||
required: false, | ||
description: 'The Node ID of the group to be updated. For example, `gid://irida/group/a84cd757-dedb-4c64-8b01-097020163077`' # rubocop:disable Layout/LineLength | ||
argument :group_puid, ID, # rubocop:disable GraphQL/ExtractInputType | ||
required: false, | ||
description: 'Persistent Unique Identifier of the group. For example, `INXT_PRJ_AAAAAAAAAA`.' | ||
validates required: { one_of: %i[group_id group_puid] } | ||
|
||
field :errors, [Types::UserErrorType], null: false, description: 'A list of errors that prevented the mutation.' | ||
field :group, Types::GroupType, null: true, description: 'The updated group.' | ||
field :status, GraphQL::Types::JSON, null: true, description: 'The status of the mutation.' | ||
|
||
def resolve(args) # rubocop:disable Metrics/MethodLength | ||
group = get_group_from_id_or_puid_args(args) | ||
|
||
if group.nil? | ||
return { | ||
group:, | ||
status: nil, | ||
errors: [{ path: ['group'], message: 'not found by provided ID or PUID' }] | ||
} | ||
end | ||
|
||
files_attached = Attachments::CreateService.new(current_user, group, { files: args[:files] }).execute | ||
|
||
status, user_errors = attachment_status_and_errors(files_attached:, file_blob_id_list: args[:files]) | ||
|
||
# append query level errors | ||
user_errors.push(*get_errors_from_object(group, 'group')) | ||
|
||
{ | ||
group:, | ||
status:, | ||
errors: user_errors | ||
} | ||
end | ||
|
||
def ready?(**_args) | ||
authorize!(to: :mutate?, with: GraphqlPolicy, context: { user: context[:current_user], token: context[:token] }) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resolvers | ||
# Group Attachments Resolver | ||
class GroupAttachmentsResolver < BaseResolver | ||
argument :filter, Types::AttachmentFilterInputType, | ||
required: false, | ||
description: 'Ransack filter', | ||
default_value: nil | ||
|
||
argument :order_by, Types::AttachmentOrderInputType, | ||
required: false, | ||
description: 'Order by', | ||
default_value: nil | ||
|
||
alias group object | ||
|
||
def resolve(filter:, order_by:) | ||
ransack_obj = group.attachments.joins(:file_blob).ransack(filter&.to_h) | ||
ransack_obj.sorts = ["#{order_by.field} #{order_by.direction}"] if order_by.present? | ||
|
||
ransack_obj.result | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.