-
Notifications
You must be signed in to change notification settings - Fork 12
/
issue.resolvers.go
157 lines (134 loc) · 6.88 KB
/
issue.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
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"
"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/tracing"
opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/log"
)
// Tags is the resolver for the tags field.
func (r *issueResolver) Tags(ctx context.Context, obj *model.Issue) ([]*model.Tag, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
tagEntities, err := dataloader.For(ctx).GetTagsForIssue(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get tags for issue %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get tags for issue %s", obj.ID)
return nil, err
}
return mapper.MapEntitiesToTags(tagEntities), nil
}
// InteractionEvents is the resolver for the interactionEvents field.
func (r *issueResolver) InteractionEvents(ctx context.Context, obj *model.Issue) ([]*model.InteractionEvent, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
interactionEventEntities, err := dataloader.For(ctx).GetInteractionEventsForIssue(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("failed to get interaction events for issue %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "failed to get interaction events for issue %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToInteractionEvents(interactionEventEntities), nil
}
// Comments is the resolver for the comments field.
func (r *issueResolver) Comments(ctx context.Context, obj *model.Issue) ([]*model.Comment, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
commentEntities, err := dataloader.For(ctx).GetCommentsForIssue(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("failed to get comments for issue %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "failed to get comments for issue %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToComments(commentEntities), nil
}
// ExternalLinks is the resolver for the externalLinks field.
func (r *issueResolver) ExternalLinks(ctx context.Context, obj *model.Issue) ([]*model.ExternalSystem, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
entities, err := dataloader.For(ctx).GetExternalSystemsForIssue(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get external system for issue %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get external system for issue %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToExternalSystems(entities), nil
}
// SubmittedBy is the resolver for the submittedBy field.
func (r *issueResolver) SubmittedBy(ctx context.Context, obj *model.Issue) (model.IssueParticipant, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
issueParticipants, err := dataloader.For(ctx).GetSubmitterParticipantsForIssue(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get submitter for issue %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get submitter for issue %s", obj.ID)
return nil, nil
}
if len(*issueParticipants) == 0 {
return nil, nil
}
return mapper.MapEntitiesToIssueParticipants(issueParticipants)[0], nil
}
// ReportedBy is the resolver for the reportedBy field.
func (r *issueResolver) ReportedBy(ctx context.Context, obj *model.Issue) (model.IssueParticipant, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
issueParticipants, err := dataloader.For(ctx).GetReporterParticipantsForIssue(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get reporter for issue %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get reporter for issue %s", obj.ID)
return nil, nil
}
if len(*issueParticipants) == 0 {
return nil, nil
}
return mapper.MapEntitiesToIssueParticipants(issueParticipants)[0], nil
}
// AssignedTo is the resolver for the assignedTo field.
func (r *issueResolver) AssignedTo(ctx context.Context, obj *model.Issue) ([]model.IssueParticipant, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
issueParticipants, err := dataloader.For(ctx).GetAssigneeParticipantsForIssue(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get assignees for issue %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get assignees for issue %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToIssueParticipants(issueParticipants), nil
}
// FollowedBy is the resolver for the followedBy field.
func (r *issueResolver) FollowedBy(ctx context.Context, obj *model.Issue) ([]model.IssueParticipant, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
issueParticipants, err := dataloader.For(ctx).GetFollowerParticipantsForIssue(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get followers for issue %s: %s", obj.ID, err.Error())
graphql.AddErrorf(ctx, "Failed to get followers for issue %s", obj.ID)
return nil, nil
}
return mapper.MapEntitiesToIssueParticipants(issueParticipants), nil
}
// Issue is the resolver for the issue field.
func (r *queryResolver) Issue(ctx context.Context, id string) (*model.Issue, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "QueryResolver.Issue", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
span.LogFields(log.String("request.issueID", id))
issueEntity, err := r.Services.IssueService.GetById(ctx, id)
if err != nil || issueEntity == nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Issue with id %s not found", id)
return nil, err
}
return mapper.MapEntityToIssue(issueEntity), nil
}
// Issue returns generated.IssueResolver implementation.
func (r *Resolver) Issue() generated.IssueResolver { return &issueResolver{r} }
type issueResolver struct{ *Resolver }