/
eventactivation_resolver.go
65 lines (52 loc) · 2.01 KB
/
eventactivation_resolver.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
package remoteenvironment
import (
"context"
"github.com/golang/glog"
"github.com/kyma-project/kyma/components/ui-api-layer/internal/gqlschema"
"github.com/pkg/errors"
)
type eventActivationResolver struct {
service eventActivationLister
converter *eventActivationConverter
asyncApiSpecGetter AsyncApiSpecGetter
}
func newEventActivationResolver(service eventActivationLister, asyncApiSpecGetter AsyncApiSpecGetter) *eventActivationResolver {
return &eventActivationResolver{
service: service,
converter: &eventActivationConverter{},
asyncApiSpecGetter: asyncApiSpecGetter,
}
}
func (r *eventActivationResolver) EventActivationsQuery(ctx context.Context, environment string) ([]gqlschema.EventActivation, error) {
items, err := r.service.List(environment)
if err != nil {
glog.Error(errors.Wrapf(err, "while listing eventActivations in `%s` environment", environment))
return nil, err
}
return r.converter.ToGQLs(items), nil
}
func (r *eventActivationResolver) EventActivationEventsField(ctx context.Context, eventActivation *gqlschema.EventActivation) ([]gqlschema.EventActivationEvent, error) {
if eventActivation == nil {
glog.Errorf("EventActivation cannot be empty in order to resolve events field")
return nil, r.eventsError()
}
asyncApiSpec, err := r.asyncApiSpecGetter.Find("service-class", eventActivation.Name)
if err != nil {
glog.Error(errors.Wrapf(err, "while gathering events for EventActivation %s", eventActivation.Name))
return nil, r.eventsError()
}
if asyncApiSpec == nil {
return []gqlschema.EventActivationEvent{}, nil
}
if asyncApiSpec.Data.AsyncAPI != "1.0.0" {
glog.Errorf("not supported version `%s` of asyncApiSpec", asyncApiSpec.Data.AsyncAPI)
return nil, r.eventsError()
}
return r.converter.ToGQLEvents(asyncApiSpec), nil
}
func (r *eventActivationResolver) genericError() error {
return errors.New("Cannot get EventActivation")
}
func (r *eventActivationResolver) eventsError() error {
return errors.New("Cannot list Events")
}