-
Notifications
You must be signed in to change notification settings - Fork 12
/
interaction_event.resolvers.go
410 lines (353 loc) · 20.5 KB
/
interaction_event.resolvers.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
package resolver
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.46
import (
"context"
"fmt"
"github.com/99designs/gqlgen/graphql"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/dataloader"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/graph/generated"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/graph/model"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/mapper"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/repository"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/service"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/tracing"
neo4jentity "github.com/openline-ai/openline-customer-os/packages/server/customer-os-neo4j-repository/entity"
opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/log"
)
// InteractionSession is the resolver for the interactionSession field.
func (r *interactionEventResolver) InteractionSession(ctx context.Context, obj *model.InteractionEvent) (*model.InteractionSession, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
interactionSessionEntityNillable, err := dataloader.For(ctx).GetInteractionSessionForInteractionEvent(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get interaction session for interaction event %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get interaction session for interaction event %s", obj.ID)
return nil, nil
}
return mapper.MapEntityToInteractionSession(interactionSessionEntityNillable), nil
}
// Issue is the resolver for the issue field.
func (r *interactionEventResolver) Issue(ctx context.Context, obj *model.InteractionEvent) (*model.Issue, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
issueEntityNillable, err := dataloader.For(ctx).GetIssueForInteractionEvent(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get issue for interaction event %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get issue for interaction event %s", obj.ID)
return nil, nil
}
return mapper.MapEntityToIssue(issueEntityNillable), nil
}
// Meeting is the resolver for the meeting field.
func (r *interactionEventResolver) Meeting(ctx context.Context, obj *model.InteractionEvent) (*model.Meeting, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
meetingEntityNillable, err := dataloader.For(ctx).GetMeetingForInteractionEvent(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get meeting for interaction event %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get meeting for interaction event %s", obj.ID)
return nil, nil
}
return mapper.MapEntityToMeeting(meetingEntityNillable), nil
}
// SentBy is the resolver for the sentBy field.
func (r *interactionEventResolver) SentBy(ctx context.Context, obj *model.InteractionEvent) ([]model.InteractionEventParticipant, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
participantEntities, err := dataloader.For(ctx).GetSentByParticipantsForInteractionEvent(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get SentBy for interaction event %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get participants for interaction event %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToInteractionEventParticipants(participantEntities), nil
}
// SentTo is the resolver for the sentTo field.
func (r *interactionEventResolver) SentTo(ctx context.Context, obj *model.InteractionEvent) ([]model.InteractionEventParticipant, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
participantEntities, err := dataloader.For(ctx).GetSentToParticipantsForInteractionEvent(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get SentTo for interaction event %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get participants for interaction event %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToInteractionEventParticipants(participantEntities), nil
}
// RepliesTo is the resolver for the repliesTo field.
func (r *interactionEventResolver) RepliesTo(ctx context.Context, obj *model.InteractionEvent) (*model.InteractionEvent, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
interactionEventEntities, err := dataloader.For(ctx).GetInteractionEventsForInteractionEvent(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get ReplyTo for interaction event %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get ReplyTo for interaction event %s", obj.ID)
return nil, nil
}
if len(*interactionEventEntities) > 0 {
return mapper.MapEntityToInteractionEvent(&(*interactionEventEntities)[0]), nil
}
return nil, nil
}
// Includes is the resolver for the includes field.
func (r *interactionEventResolver) Includes(ctx context.Context, obj *model.InteractionEvent) ([]*model.Attachment, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
entities, err := dataloader.For(ctx).GetAttachmentsForInteractionEvent(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get attachment entities for Interaction Event %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get attachment entities for Interaction Event %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToAttachment(entities), nil
}
// Summary is the resolver for the summary field.
func (r *interactionEventResolver) Summary(ctx context.Context, obj *model.InteractionEvent) (*model.Analysis, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
analysisEntities, err := dataloader.For(ctx).GetDescribedByFor(ctx, repository.LINKED_WITH_INTERACTION_EVENT, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get analysis for InteractionEvent %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get analysis for InteractionEvent %s", obj.ID)
return nil, nil
}
if len(*analysisEntities) == 1 {
return mapper.MapEntityToAnalysis(&(*analysisEntities)[0]), nil
}
return nil, nil
}
// Actions is the resolver for the actions field.
func (r *interactionEventResolver) Actions(ctx context.Context, obj *model.InteractionEvent) ([]*model.Action, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
entities, err := dataloader.For(ctx).GetActionsForInteractionEvent(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get action entities for Interaction Event %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get action entities for Interaction Event %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToAction(entities), nil
}
// ActionItems is the resolver for the actionItems field.
func (r *interactionEventResolver) ActionItems(ctx context.Context, obj *model.InteractionEvent) ([]*model.ActionItem, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
entities, err := dataloader.For(ctx).GetActionItemsForInteractionEvent(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get action items entities for Interaction Event %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get action items entities for Interaction Event %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToActionItem(entities), nil
}
// ExternalLinks is the resolver for the externalLinks field.
func (r *interactionEventResolver) ExternalLinks(ctx context.Context, obj *model.InteractionEvent) ([]*model.ExternalSystem, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
entities, err := dataloader.For(ctx).GetExternalSystemsForInteractionEvent(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get external system for interaction event %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get external systems for interaction event %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToExternalSystems(entities), nil
}
// Events is the resolver for the events field.
func (r *interactionSessionResolver) Events(ctx context.Context, obj *model.InteractionSession) ([]*model.InteractionEvent, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
interactionEventEntities, err := dataloader.For(ctx).GetInteractionEventsForInteractionSession(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get interaction events for interaction session %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get interaction events for interaction session %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToInteractionEvents(interactionEventEntities), nil
}
// AttendedBy is the resolver for the attendedBy field.
func (r *interactionSessionResolver) AttendedBy(ctx context.Context, obj *model.InteractionSession) ([]model.InteractionSessionParticipant, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
participantEntities, err := dataloader.For(ctx).GetAttendedByParticipantsForInteractionSession(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get AttendedBy for interaction event %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get participants for interaction event %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToInteractionSessionParticipants(participantEntities), nil
}
// Includes is the resolver for the includes field.
func (r *interactionSessionResolver) Includes(ctx context.Context, obj *model.InteractionSession) ([]*model.Attachment, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
entities, err := dataloader.For(ctx).GetAttachmentsForInteractionSession(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get attachment entities for Interaction Session %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get attachment entities for Interaction Session %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToAttachment(entities), nil
}
// DescribedBy is the resolver for the describedBy field.
func (r *interactionSessionResolver) DescribedBy(ctx context.Context, obj *model.InteractionSession) ([]*model.Analysis, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
analysisEntities, err := dataloader.For(ctx).GetDescribedByFor(ctx, repository.LINKED_WITH_INTERACTION_SESSION, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get analysis for InteractionSession %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get analysis for InteractionSession %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToAnalysis(analysisEntities), nil
}
// InteractionSessionCreate is the resolver for the interactionSession_Create field.
func (r *mutationResolver) InteractionSessionCreate(ctx context.Context, session model.InteractionSessionInput) (*model.InteractionSession, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "MutationResolver.InteractionSessionCreate", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
interactionSessionEntity, err := r.Services.InteractionSessionService.Create(ctx,
&service.InteractionSessionCreateData{
InteractionSessionEntity: mapper.MapInteractionSessionInputToEntity(&session),
AttendedBy: service.MapInteractionSessionParticipantInputToAddressData(session.AttendedBy),
})
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to create InteractionEvent")
return nil, err
}
interactionEvent := mapper.MapEntityToInteractionSession(interactionSessionEntity)
return interactionEvent, nil
}
// InteractionSessionLinkAttachment is the resolver for the interactionSession_LinkAttachment field.
func (r *mutationResolver) InteractionSessionLinkAttachment(ctx context.Context, sessionID string, attachmentID string) (*model.InteractionSession, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "MutationResolver.InteractionSessionLinkAttachment", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
span.LogFields(log.String("request.sessionID", sessionID), log.String("request.attachmentID", attachmentID))
session, err := r.Services.InteractionSessionService.InteractionSessionLinkAttachment(ctx, sessionID, attachmentID)
if err != nil {
return nil, err
}
return mapper.MapEntityToInteractionSession(session), nil
}
// InteractionEventCreate is the resolver for the interactionEvent_Create field.
func (r *mutationResolver) InteractionEventCreate(ctx context.Context, event model.InteractionEventInput) (*model.InteractionEvent, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "MutationResolver.InteractionEventCreate", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
interactionEventCreated, err := r.Services.InteractionEventService.Create(ctx, &service.InteractionEventCreateData{
InteractionEventEntity: mapper.MapInteractionEventInputToEntity(&event),
SessionIdentifier: event.InteractionSession,
MeetingIdentifier: event.MeetingID,
SentBy: service.MapInteractionEventParticipantInputToAddressData(event.SentBy),
SentTo: service.MapInteractionEventParticipantInputToAddressData(event.SentTo),
RepliesTo: event.RepliesTo,
Source: neo4jentity.DataSourceOpenline,
SourceOfTruth: neo4jentity.DataSourceOpenline,
})
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to create InteractionEvent")
return nil, err
}
interactionEvent := mapper.MapEntityToInteractionEvent(interactionEventCreated)
return interactionEvent, nil
}
// InteractionEventLinkAttachment is the resolver for the interactionEvent_LinkAttachment field.
func (r *mutationResolver) InteractionEventLinkAttachment(ctx context.Context, eventID string, attachmentID string) (*model.InteractionEvent, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "MutationResolver.InteractionEventLinkAttachment", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
span.LogFields(log.String("request.eventID", eventID), log.String("request.attachmentID", attachmentID))
event, err := r.Services.InteractionEventService.InteractionEventLinkAttachment(ctx, eventID, attachmentID)
if err != nil {
return nil, err
}
return mapper.MapEntityToInteractionEvent(event), nil
}
// InteractionSession is the resolver for the interactionSession field.
func (r *queryResolver) InteractionSession(ctx context.Context, id string) (*model.InteractionSession, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "QueryResolver.InteractionSession", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
span.LogFields(log.String("request.interactionSessionID", id))
interactionSessionEntity, err := r.Services.InteractionSessionService.GetInteractionSessionById(ctx, id)
if err != nil || interactionSessionEntity == nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "InteractionEvent with id %s not found", id)
return nil, err
}
return mapper.MapEntityToInteractionSession(interactionSessionEntity), nil
}
// InteractionSessionBySessionIdentifier is the resolver for the interactionSession_BySessionIdentifier field.
func (r *queryResolver) InteractionSessionBySessionIdentifier(ctx context.Context, sessionIdentifier string) (*model.InteractionSession, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "QueryResolver.InteractionSessionBySessionIdentifier", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
span.LogFields(log.String("request.sessionIdentifier", sessionIdentifier))
interactionSessionEntity, err := r.Services.InteractionSessionService.GetInteractionSessionBySessionIdentifier(ctx, sessionIdentifier)
if err != nil || interactionSessionEntity == nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "InteractionEvent with identifier %s not found", sessionIdentifier)
return nil, err
}
return mapper.MapEntityToInteractionSession(interactionSessionEntity), nil
}
// InteractionSessionByEventIdentifier is the resolver for the interactionSession_ByEventIdentifier field.
func (r *queryResolver) InteractionSessionByEventIdentifier(ctx context.Context, eventIdentifier string) (*model.InteractionSession, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "QueryResolver.InteractionSessionByEventIdentifier", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
span.LogFields(log.String("request.eventIdentifier", eventIdentifier))
interactionSessions, err := r.Services.InteractionSessionService.GetInteractionSessionsForInteractionEvents(ctx, []string{eventIdentifier})
if err != nil || interactionSessions == nil || len(*interactionSessions) == 0 {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "InteractionSession with EventIdentifier %s not found", eventIdentifier)
return nil, err
}
if len(*interactionSessions) > 1 {
return nil, fmt.Errorf("Multiple InteractionSessions found for EventIdentifier %s", eventIdentifier)
}
return mapper.MapEntityToInteractionSession(&(*interactionSessions)[0]), nil
}
// InteractionEvent is the resolver for the interactionEvent field.
func (r *queryResolver) InteractionEvent(ctx context.Context, id string) (*model.InteractionEvent, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "QueryResolver.InteractionEvent", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
span.LogFields(log.String("request.interactionEventID", id))
interactionEventEntity, err := r.Services.InteractionEventService.GetInteractionEventById(ctx, id)
if err != nil || interactionEventEntity == nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "InteractionEvent with id %s not found", id)
return nil, err
}
return mapper.MapEntityToInteractionEvent(interactionEventEntity), nil
}
// InteractionEventByEventIdentifier is the resolver for the interactionEvent_ByEventIdentifier field.
func (r *queryResolver) InteractionEventByEventIdentifier(ctx context.Context, eventIdentifier string) (*model.InteractionEvent, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "QueryResolver.InteractionEventByEventIdentifier", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
span.LogFields(log.String("request.eventIdentifier", eventIdentifier))
interactionEventEntity, err := r.Services.InteractionEventService.GetInteractionEventByEventIdentifier(ctx, eventIdentifier)
if err != nil || interactionEventEntity == nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "InteractionEvent with EventIdentifier %s not found", eventIdentifier)
return nil, err
}
return mapper.MapEntityToInteractionEvent(interactionEventEntity), nil
}
// InteractionEvent returns generated.InteractionEventResolver implementation.
func (r *Resolver) InteractionEvent() generated.InteractionEventResolver {
return &interactionEventResolver{r}
}
// InteractionSession returns generated.InteractionSessionResolver implementation.
func (r *Resolver) InteractionSession() generated.InteractionSessionResolver {
return &interactionSessionResolver{r}
}
type interactionEventResolver struct{ *Resolver }
type interactionSessionResolver struct{ *Resolver }