generated from datumforge/go-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
integration.resolvers.go
88 lines (68 loc) · 2.67 KB
/
integration.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
package graphapi
// 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
import (
"context"
"github.com/datumforge/datum/internal/ent/generated"
_ "github.com/datumforge/datum/internal/ent/generated/runtime"
)
// CreateIntegration is the resolver for the createIntegration field.
func (r *mutationResolver) CreateIntegration(ctx context.Context, input generated.CreateIntegrationInput) (*IntegrationCreatePayload, error) {
// TODO - add permissions checks
i, err := withTransactionalMutation(ctx).Integration.Create().SetInput(input).Save(ctx)
if err != nil {
if generated.IsValidationError(err) {
return nil, err
}
r.logger.Errorw("failed to create integration", "error", err)
return nil, ErrInternalServerError
}
return &IntegrationCreatePayload{Integration: i}, nil
}
// UpdateIntegration is the resolver for the updateIntegration field.
func (r *mutationResolver) UpdateIntegration(ctx context.Context, id string, input generated.UpdateIntegrationInput) (*IntegrationUpdatePayload, error) {
// TODO - add permissions checks
i, err := withTransactionalMutation(ctx).Integration.Get(ctx, id)
if err != nil {
if generated.IsNotFound(err) {
return nil, err
}
r.logger.Errorw("failed to get integration", "error", err)
return nil, ErrInternalServerError
}
i, err = i.Update().SetInput(input).Save(ctx)
if err != nil {
if generated.IsValidationError(err) {
return nil, err
}
r.logger.Errorw("failed to update integration", "error", err)
return nil, ErrInternalServerError
}
return &IntegrationUpdatePayload{Integration: i}, nil
}
// DeleteIntegration is the resolver for the deleteIntegration field.
func (r *mutationResolver) DeleteIntegration(ctx context.Context, id string) (*IntegrationDeletePayload, error) {
// TODO - add permissions checks
if err := withTransactionalMutation(ctx).Integration.DeleteOneID(id).Exec(ctx); err != nil {
if generated.IsNotFound(err) {
return nil, err
}
r.logger.Errorw("failed to delete integration", "error", err)
return nil, err
}
return &IntegrationDeletePayload{DeletedID: id}, nil
}
// Integration is the resolver for the integration field.
func (r *queryResolver) Integration(ctx context.Context, id string) (*generated.Integration, error) {
// TODO - add permissions checks
i, err := withTransactionalMutation(ctx).Integration.Get(ctx, id)
if err != nil {
if generated.IsNotFound(err) {
return nil, err
}
r.logger.Errorw("failed to get integration", "error", err)
return nil, ErrInternalServerError
}
return i, nil
}