forked from kyma-project/kyma
/
function_resolver.go
37 lines (31 loc) · 1.05 KB
/
function_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
package kubeless
import (
"context"
"fmt"
"github.com/golang/glog"
"github.com/kyma-project/kyma/components/ui-api-layer/internal/gqlschema"
"github.com/kyma-project/kyma/components/ui-api-layer/internal/pager"
"github.com/pkg/errors"
)
type functionResolver struct {
functionLister functionLister
functionConverter *functionConverter
}
func newFunctionResolver(functionLister functionLister) *functionResolver {
return &functionResolver{
functionLister: functionLister,
functionConverter: &functionConverter{},
}
}
func (r *functionResolver) FunctionsQuery(ctx context.Context, environment string, first *int, offset *int) ([]gqlschema.Function, error) {
externalErr := fmt.Errorf("Cannot query functions in environment `%s`", environment)
functions, err := r.functionLister.List(environment, pager.PagingParams{
First: first,
Offset: offset,
})
if err != nil {
glog.Error(errors.Wrapf(err, "while listing Functions for environment %s", environment))
return nil, externalErr
}
return r.functionConverter.ToGQLs(functions), nil
}