generated from datumforge/go-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
integration.resolvers.go
99 lines (77 loc) · 3.15 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
89
90
91
92
93
94
95
96
97
98
99
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"
"github.com/datumforge/datum/pkg/rout"
)
// CreateIntegration is the resolver for the createIntegration field.
func (r *mutationResolver) CreateIntegration(ctx context.Context, input generated.CreateIntegrationInput) (*IntegrationCreatePayload, error) {
// set the organization in the auth context if its not done for us
if err := setOrganizationInAuthContext(ctx, input.OwnerID); err != nil {
r.logger.Errorw("failed to set organization in auth context", "error", err)
return nil, rout.NewMissingRequiredFieldError("owner_id")
}
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) {
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
}
if err := setOrganizationInAuthContext(ctx, &i.OwnerID); err != nil {
r.logger.Errorw("failed to set organization in auth context", "error", err)
return nil, ErrPermissionDenied
}
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) {
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
}
if err := generated.IntegrationEdgeCleanup(ctx, id); err != nil {
return nil, newCascadeDeleteError(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) {
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
}