diff --git a/graph/generated/generated.go b/graph/generated/generated.go index 2195972..db5e1d8 100644 --- a/graph/generated/generated.go +++ b/graph/generated/generated.go @@ -87,6 +87,7 @@ type ComplexityRoot struct { Exclusive func(childComplexity int) int ID func(childComplexity int) int JobID func(childComplexity int) int + MetaData func(childComplexity int) int MonitoringStatus func(childComplexity int) int NumAcc func(childComplexity int) int NumHWThreads func(childComplexity int) int @@ -424,6 +425,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Job.JobID(childComplexity), true + case "Job.metaData": + if e.complexity.Job.MetaData == nil { + break + } + + return e.complexity.Job.MetaData(childComplexity), true + case "Job.monitoringStatus": if e.complexity.Job.MonitoringStatus == nil { break @@ -1191,6 +1199,8 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er var sources = []*ast.Source{ {Name: "graph/schema.graphqls", Input: `scalar Time +scalar Any + scalar NullableFloat scalar MetricScope scalar JobState @@ -1212,6 +1222,7 @@ type Job { arrayJobId: Int! monitoringStatus: Int! state: JobState! + metaData: Any tags: [Tag!]! resources: [Resource!]! } @@ -3019,6 +3030,38 @@ func (ec *executionContext) _Job_state(ctx context.Context, field graphql.Collec return ec.marshalNJobState2githubᚗcomᚋClusterCockpitᚋccᚑbackendᚋschemaᚐJobState(ctx, field.Selections, res) } +func (ec *executionContext) _Job_metaData(ctx context.Context, field graphql.CollectedField, obj *schema.Job) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Job", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.MetaData, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(interface{}) + fc.Result = res + return ec.marshalOAny2interface(ctx, field.Selections, res) +} + func (ec *executionContext) _Job_tags(ctx context.Context, field graphql.CollectedField, obj *schema.Job) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -7696,6 +7739,8 @@ func (ec *executionContext) _Job(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) } + case "metaData": + out.Values[i] = ec._Job_metaData(ctx, field, obj) case "tags": field := field out.Concurrently(i, func() (res graphql.Marshaler) { @@ -10121,6 +10166,21 @@ func (ec *executionContext) marshalOAggregate2ᚖgithubᚗcomᚋClusterCockpit return v } +func (ec *executionContext) unmarshalOAny2interface(ctx context.Context, v interface{}) (interface{}, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalAny(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOAny2interface(ctx context.Context, sel ast.SelectionSet, v interface{}) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return graphql.MarshalAny(v) +} + func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { res, err := graphql.UnmarshalBoolean(v) return res, graphql.ErrorOnPath(ctx, err) diff --git a/graph/schema.graphqls b/graph/schema.graphqls index d3d1711..133d68d 100644 --- a/graph/schema.graphqls +++ b/graph/schema.graphqls @@ -1,4 +1,6 @@ scalar Time +scalar Any + scalar NullableFloat scalar MetricScope scalar JobState @@ -20,6 +22,7 @@ type Job { arrayJobId: Int! monitoringStatus: Int! state: JobState! + metaData: Any tags: [Tag!]! resources: [Resource!]! } diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go index b526493..236c06a 100644 --- a/graph/schema.resolvers.go +++ b/graph/schema.resolvers.go @@ -165,6 +165,13 @@ func (r *queryResolver) JobsFootprints(ctx context.Context, filter []*model.JobF } func (r *queryResolver) Jobs(ctx context.Context, filter []*model.JobFilter, page *model.PageRequest, order *model.OrderByInput) (*model.JobResultList, error) { + if page == nil { + page = &model.PageRequest{ + ItemsPerPage: 50, + Page: 1, + } + } + jobs, err := r.Repo.QueryJobs(ctx, filter, page, order) if err != nil { return nil, err diff --git a/repository/query.go b/repository/query.go index 53a863e..6213eaa 100644 --- a/repository/query.go +++ b/repository/query.go @@ -38,8 +38,6 @@ func (r *JobRepository) QueryJobs( if page != nil { limit := uint64(page.ItemsPerPage) query = query.Offset((uint64(page.Page) - 1) * limit).Limit(limit) - } else { - query = query.Limit(50) } for _, f := range filters { @@ -90,7 +88,7 @@ func (r *JobRepository) CountJobs( func SecurityCheck(ctx context.Context, query sq.SelectBuilder) sq.SelectBuilder { user := auth.GetUser(ctx) - if user == nil || user.HasRole(auth.RoleAdmin) { + if user == nil || user.HasRole(auth.RoleAdmin) || user.HasRole(auth.RoleApi) { return query }