我想创建一个不在 ActiveRecord 中的 MentionType。当查询 SummaryCommentType 时,我想用它返回 MentionType。但我不知道该怎么做。
我对 graphql 完全陌生。对不起我的英语不好。
这是我的代码
module Types
class MentionType < Types::BaseObject
field :id, Integer, null: false
field :name, String, null: false
end
end
module Types
class SummaryCommentType < Types::BaseObject
field :id, Integer, null: false
field :summary_id, Integer, null: false
field :comment_status, Integer, null: false
field :curator_id, Integer, null: true
field :curator, CuratorType, null: true
field :total_like, Integer, null: true
field :total_dislike, Integer, null: true
field :comment_desc, String, null: true
field :parent_comment_key, Integer, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
field :sub_comment_count, Integer, null: true
field :summary_comment_sticker, SummaryCommentStickerType, null: true
field :mention, [MentionType.graphql_definition], null:true do
argument :comment_id, Integer, required: true
end
def mention(comment_id:)
comment = SummaryComment.where(id: self.object.id)
# to do put logic here to query mention by comment
# ....
return mention
end
end
end