/
storage.resolvers.go
51 lines (41 loc) · 1.92 KB
/
storage.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
package graph
// 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/nais/api/internal/graph/gengql"
"github.com/nais/api/internal/graph/loader"
"github.com/nais/api/internal/graph/model"
"github.com/nais/api/internal/slug"
)
// SQLInstance is the resolver for the sqlInstance field.
func (r *queryResolver) SQLInstance(ctx context.Context, name string, team slug.Slug, env string) (*model.SQLInstance, error) {
return r.sqlInstanceClient.SqlInstance(ctx, env, team, name)
}
// Database is the resolver for the database field.
func (r *sqlInstanceResolver) Database(ctx context.Context, obj *model.SQLInstance) (*model.SQLDatabase, error) {
return r.sqlInstanceClient.SqlDatabase(obj)
}
// Team is the resolver for the team field.
func (r *sqlInstanceResolver) Team(ctx context.Context, obj *model.SQLInstance) (*model.Team, error) {
return loader.GetTeam(ctx, obj.GQLVars.TeamSlug)
}
// Workload is the resolver for the workload field.
func (r *sqlInstanceResolver) Workload(ctx context.Context, obj *model.SQLInstance) (model.Workload, error) {
if obj.GQLVars.OwnerReference == nil {
return nil, nil
}
switch obj.GQLVars.OwnerReference.Kind {
case "Naisjob":
return r.k8sClient.NaisJob(ctx, obj.GQLVars.OwnerReference.Name, string(obj.GQLVars.TeamSlug), obj.Env.Name)
case "Application":
return r.k8sClient.App(ctx, obj.GQLVars.OwnerReference.Name, string(obj.GQLVars.TeamSlug), obj.Env.Name)
default:
r.log.WithField("kind", obj.GQLVars.OwnerReference.Kind).Warnf("Unknown owner reference kind")
}
return nil, nil
}
// SqlInstance returns gengql.SqlInstanceResolver implementation.
func (r *Resolver) SqlInstance() gengql.SqlInstanceResolver { return &sqlInstanceResolver{r} }
type sqlInstanceResolver struct{ *Resolver }