-
Notifications
You must be signed in to change notification settings - Fork 12
/
tag.resolvers.go
79 lines (68 loc) · 2.98 KB
/
tag.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
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/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"
"github.com/opentracing/opentracing-go/log"
)
// TagCreate is the resolver for the tag_Create field.
func (r *mutationResolver) TagCreate(ctx context.Context, input model.TagInput) (*model.Tag, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "MutationResolver.TagCreate", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
createdTag, err := r.Services.TagService.Merge(ctx, mapper.MapTagInputToEntity(input))
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to create tag %s", input.Name)
return nil, err
}
return mapper.MapEntityToTag(*createdTag), nil
}
// TagUpdate is the resolver for the tag_Update field.
func (r *mutationResolver) TagUpdate(ctx context.Context, input model.TagUpdateInput) (*model.Tag, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "MutationResolver.TagUpdate", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
span.LogFields(log.String("request.tagID", input.ID))
updatedTag, err := r.Services.TagService.Update(ctx, mapper.MapTagUpdateInputToEntity(input))
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to update tag %s", input.ID)
return nil, err
}
return mapper.MapEntityToTag(*updatedTag), nil
}
// TagDelete is the resolver for the tag_Delete field.
func (r *mutationResolver) TagDelete(ctx context.Context, id string) (*model.Result, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "MutationResolver.TagDelete", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
span.LogFields(log.String("request.tagID", id))
result, err := r.Services.TagService.UnlinkAndDelete(ctx, id)
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to delete tag %s", id)
return nil, err
}
return &model.Result{
Result: result,
}, nil
}
// Tags is the resolver for the tags field.
func (r *queryResolver) Tags(ctx context.Context) ([]*model.Tag, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "QueryResolver.Tags", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
tags, err := r.Services.TagService.GetAll(ctx)
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to fetch tags")
return nil, err
}
return mapper.MapEntitiesToTags(tags), err
}