From c089adbd05cfc2b5d9a9b152ea0c86ab45acc16d Mon Sep 17 00:00:00 2001 From: Shomy <61943525+ShomyKohai@users.noreply.github.com> Date: Sun, 12 Nov 2023 10:15:36 +0100 Subject: [PATCH] Add `targetUser` to Types::Post (#1341) * Add `targetUser` to Types::Post * Add `target_user_id` to Post::Create input * Rename targetUser to targetProfile --- app/graphql/types/input/post/create.rb | 1 + app/graphql/types/post.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/app/graphql/types/input/post/create.rb b/app/graphql/types/input/post/create.rb index f2ce819361..f221227805 100644 --- a/app/graphql/types/input/post/create.rb +++ b/app/graphql/types/input/post/create.rb @@ -7,6 +7,7 @@ class Types::Input::Post::Create < Types::Input::Base argument :is_nsfw, Boolean, required: false, default_value: false, as: :nsfw argument :spoiled_unit_id, ID, required: false argument :spoiled_unit_type, String, required: false + argument :target_user_id, ID, required: false def to_model to_h.merge({ user_id: current_user&.id }) diff --git a/app/graphql/types/post.rb b/app/graphql/types/post.rb index e8da4e2193..fe3ce34754 100644 --- a/app/graphql/types/post.rb +++ b/app/graphql/types/post.rb @@ -80,4 +80,12 @@ def follows Loaders::RecordLoader.for(User, token: context[:token]).load_many(follows.pluck(:user_id)) end end + + field :target_profile, Types::Profile, + null: false, + description: 'The profile of the target user of the post.' + + def target_profile + Loaders::RecordLoader.for(User).load(object.target_user_id) + end end