/
conversation_part_type.rb
54 lines (45 loc) · 1.66 KB
/
conversation_part_type.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true
module Types
class ConversationPartType < Types::BaseObject
field :id, Integer, null: true
field :message, Types::ConversationPartContentType, null: true
# field :serialized_content, String, null: true
# field :html_content, String, null: true
# field :text_content, String, null: true
field :step_id, String, null: true
field :trigger_id, String, null: true
field :read_at, GraphQL::Types::ISO8601DateTime, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
field :app_user, Types::AuthorType, null: true
# field :authorable, Types::AuthorType, null: true
field :private_note, Boolean, null: true
# field :conversation, Types::ConversationType, null: true
field :source, String, null: true
field :message_source, Types::CampaignType, null: true
field :email_message_id, String, null: true
field :from_bot, Boolean, null: true
def from_bot
object.from_bot?
end
def app_user
#object.authorable
id = object.authorable_id
key = object.authorable_type
BatchLoader::GraphQL.for(id).batch(key: key) do |ids, loader, args|
model = Object.const_get(args[:key])
model.where(id: ids).each { |record| loader.call(record.id, record) }
end
end
def message
# object.messageable
id = object.messageable_id
key = object.messageable_type
BatchLoader::GraphQL.for(id).batch(key: key) do |ids, loader, args|
model = Object.const_get(args[:key])
model.where(id: ids).each { |record|
loader.call(record.id, record)
}
end
end
end
end