-
Notifications
You must be signed in to change notification settings - Fork 12
/
analysis.resolvers.go
77 lines (65 loc) · 3.46 KB
/
analysis.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
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/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"
)
// Describes is the resolver for the describes field.
func (r *analysisResolver) Describes(ctx context.Context, obj *model.Analysis) ([]model.DescriptionNode, error) {
ctx = tracing.EnrichCtxWithSpanCtxForGraphQL(ctx, graphql.GetOperationContext(ctx))
participantEntities, err := dataloader.For(ctx).GetDescribesForAnalysis(ctx, obj.ID)
if err != nil {
tracing.TraceErr(opentracing.SpanFromContext(ctx), err)
r.log.Errorf("Failed to get participants 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.MapEntitiesToDescriptionNodes(participantEntities), nil
}
// AnalysisCreate is the resolver for the analysis_Create field.
func (r *mutationResolver) AnalysisCreate(ctx context.Context, analysis model.AnalysisInput) (*model.Analysis, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "MutationResolver.AnalysisCreate", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
analysisCreated, err := r.Services.AnalysisService.Create(ctx, &service.AnalysisCreateData{
AnalysisEntity: mapper.MapAnalysisInputToEntity(&analysis),
Describes: service.MapAnalysisDescriptionInputToDescriptionData(analysis.Describes),
Source: neo4jentity.DataSourceOpenline,
SourceOfTruth: neo4jentity.DataSourceOpenline,
})
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to create Analysis")
return nil, err
}
newAnalysis := mapper.MapEntityToAnalysis(analysisCreated)
return newAnalysis, nil
}
// Analysis is the resolver for the analysis field.
func (r *queryResolver) Analysis(ctx context.Context, id string) (*model.Analysis, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "QueryResolver.Analysis", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
span.LogFields(log.String("request.ID", id))
analysis, err := r.Services.AnalysisService.GetAnalysisById(ctx, id)
if err != nil || analysis == nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Analysis with id %s not found", id)
return nil, err
}
return mapper.MapEntityToAnalysis(analysis), nil
}
// Analysis returns generated.AnalysisResolver implementation.
func (r *Resolver) Analysis() generated.AnalysisResolver { return &analysisResolver{r} }
type analysisResolver struct{ *Resolver }