-
Notifications
You must be signed in to change notification settings - Fork 12
/
attachment.resolvers.go
49 lines (41 loc) · 2.16 KB
/
attachment.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
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"
neo4jentity "github.com/openline-ai/openline-customer-os/packages/server/customer-os-neo4j-repository/entity"
"github.com/opentracing/opentracing-go/log"
)
// AttachmentCreate is the resolver for the attachment_Create field.
func (r *mutationResolver) AttachmentCreate(ctx context.Context, input model.AttachmentInput) (*model.Attachment, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "MutationResolver.AttachmentCreate", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
attachmentCreated, err := r.Services.AttachmentService.Create(ctx, mapper.MapAttachmentInputToEntity(&input), neo4jentity.DataSourceOpenline, neo4jentity.DataSourceOpenline)
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to create Attachment")
return nil, err
}
newAttachment := mapper.MapEntityToAttachment(attachmentCreated)
return newAttachment, nil
}
// Attachment is the resolver for the attachment field.
func (r *queryResolver) Attachment(ctx context.Context, id string) (*model.Attachment, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "QueryResolver.Attachment", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
span.LogFields(log.String("request.ID", id))
attachmentEntity, err := r.Services.AttachmentService.GetAttachmentById(ctx, id)
if err != nil || attachmentEntity == nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Attachment with id %s not found", id)
return nil, err
}
return mapper.MapEntityToAttachment(attachmentEntity), nil
}