chore: handle push of unchanged schema

This commit is contained in:
2022-10-14 22:41:56 +02:00
parent eb41e24002
commit b1124d6350
10 changed files with 866 additions and 61 deletions
+559 -2
View File
@@ -51,7 +51,8 @@ type ComplexityRoot struct {
}
Query struct {
SubGraphs func(childComplexity int, ref string) int
SubGraphs func(childComplexity int, ref string) int
Supergraph func(childComplexity int, ref string, isAfter *string) int
}
SubGraph struct {
@@ -63,6 +64,17 @@ type ComplexityRoot struct {
URL func(childComplexity int) int
WsURL func(childComplexity int) int
}
SubGraphs struct {
ID func(childComplexity int) int
MinDelaySeconds func(childComplexity int) int
SubGraphs func(childComplexity int) int
}
Unchanged struct {
ID func(childComplexity int) int
MinDelaySeconds func(childComplexity int) int
}
}
type MutationResolver interface {
@@ -70,6 +82,7 @@ type MutationResolver interface {
}
type QueryResolver interface {
SubGraphs(ctx context.Context, ref string) ([]*model.SubGraph, error)
Supergraph(ctx context.Context, ref string, isAfter *string) (model.Supergraph, error)
}
type executableSchema struct {
@@ -111,6 +124,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.Query.SubGraphs(childComplexity, args["ref"].(string)), true
case "Query.supergraph":
if e.complexity.Query.Supergraph == nil {
break
}
args, err := ec.field_Query_supergraph_args(context.TODO(), rawArgs)
if err != nil {
return 0, false
}
return e.complexity.Query.Supergraph(childComplexity, args["ref"].(string), args["isAfter"].(*string)), true
case "SubGraph.changedAt":
if e.complexity.SubGraph.ChangedAt == nil {
break
@@ -160,6 +185,41 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.SubGraph.WsURL(childComplexity), true
case "SubGraphs.id":
if e.complexity.SubGraphs.ID == nil {
break
}
return e.complexity.SubGraphs.ID(childComplexity), true
case "SubGraphs.minDelaySeconds":
if e.complexity.SubGraphs.MinDelaySeconds == nil {
break
}
return e.complexity.SubGraphs.MinDelaySeconds(childComplexity), true
case "SubGraphs.subGraphs":
if e.complexity.SubGraphs.SubGraphs == nil {
break
}
return e.complexity.SubGraphs.SubGraphs(childComplexity), true
case "Unchanged.id":
if e.complexity.Unchanged.ID == nil {
break
}
return e.complexity.Unchanged.ID(childComplexity), true
case "Unchanged.minDelaySeconds":
if e.complexity.Unchanged.MinDelaySeconds == nil {
break
}
return e.complexity.Unchanged.MinDelaySeconds(childComplexity), true
}
return 0, false
}
@@ -230,13 +290,27 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er
var sources = []*ast.Source{
{Name: "../schema.graphqls", Input: `type Query {
subGraphs(ref: String!): [SubGraph!]! @hasApiKey
subGraphs(ref: String!): [SubGraph!]! @hasApiKey @deprecated(reason: "Use supergraph instead")
supergraph(ref: String!, isAfter: String): Supergraph! @hasApiKey
}
type Mutation {
updateSubGraph(input: InputSubGraph!): SubGraph! @hasApiKey
}
union Supergraph = Unchanged | SubGraphs
type Unchanged {
id: ID!
minDelaySeconds: Int!
}
type SubGraphs {
id: ID!
minDelaySeconds: Int!
subGraphs: [SubGraph!]!
}
type SubGraph {
id: ID!
service: String!
@@ -311,6 +385,30 @@ func (ec *executionContext) field_Query_subGraphs_args(ctx context.Context, rawA
return args, nil
}
func (ec *executionContext) field_Query_supergraph_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
var err error
args := map[string]interface{}{}
var arg0 string
if tmp, ok := rawArgs["ref"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("ref"))
arg0, err = ec.unmarshalNString2string(ctx, tmp)
if err != nil {
return nil, err
}
}
args["ref"] = arg0
var arg1 *string
if tmp, ok := rawArgs["isAfter"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isAfter"))
arg1, err = ec.unmarshalOString2ᚖstring(ctx, tmp)
if err != nil {
return nil, err
}
}
args["isAfter"] = arg1
return args, nil
}
func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
var err error
args := map[string]interface{}{}
@@ -531,6 +629,81 @@ func (ec *executionContext) fieldContext_Query_subGraphs(ctx context.Context, fi
return fc, nil
}
func (ec *executionContext) _Query_supergraph(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Query_supergraph(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
directive0 := func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.Query().Supergraph(rctx, fc.Args["ref"].(string), fc.Args["isAfter"].(*string))
}
directive1 := func(ctx context.Context) (interface{}, error) {
if ec.directives.HasApiKey == nil {
return nil, errors.New("directive hasApiKey is not implemented")
}
return ec.directives.HasApiKey(ctx, nil, directive0)
}
tmp, err := directive1(rctx)
if err != nil {
return nil, graphql.ErrorOnPath(ctx, err)
}
if tmp == nil {
return nil, nil
}
if data, ok := tmp.(model.Supergraph); ok {
return data, nil
}
return nil, fmt.Errorf(`unexpected type %T from directive, should be gitlab.com/unboundsoftware/schemas/graph/model.Supergraph`, tmp)
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(model.Supergraph)
fc.Result = res
return ec.marshalNSupergraph2gitlabᚗcomᚋunboundsoftwareᚋschemasᚋgraphᚋmodelᚐSupergraph(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Query_supergraph(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "Query",
Field: field,
IsMethod: true,
IsResolver: true,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type Supergraph does not have child fields")
},
}
defer func() {
if r := recover(); r != nil {
err = ec.Recover(ctx, r)
ec.Error(ctx, err)
}
}()
ctx = graphql.WithFieldContext(ctx, fc)
if fc.Args, err = ec.field_Query_supergraph_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
ec.Error(ctx, err)
return
}
return fc, nil
}
func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Query___type(ctx, field)
if err != nil {
@@ -962,6 +1135,242 @@ func (ec *executionContext) fieldContext_SubGraph_changedAt(ctx context.Context,
return fc, nil
}
func (ec *executionContext) _SubGraphs_id(ctx context.Context, field graphql.CollectedField, obj *model.SubGraphs) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_SubGraphs_id(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.ID, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(string)
fc.Result = res
return ec.marshalNID2string(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_SubGraphs_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "SubGraphs",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type ID does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _SubGraphs_minDelaySeconds(ctx context.Context, field graphql.CollectedField, obj *model.SubGraphs) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_SubGraphs_minDelaySeconds(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.MinDelaySeconds, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(int)
fc.Result = res
return ec.marshalNInt2int(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_SubGraphs_minDelaySeconds(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "SubGraphs",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type Int does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _SubGraphs_subGraphs(ctx context.Context, field graphql.CollectedField, obj *model.SubGraphs) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_SubGraphs_subGraphs(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.SubGraphs, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.([]*model.SubGraph)
fc.Result = res
return ec.marshalNSubGraph2ᚕᚖgitlabᚗcomᚋunboundsoftwareᚋschemasᚋgraphᚋmodelᚐSubGraphᚄ(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_SubGraphs_subGraphs(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "SubGraphs",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
switch field.Name {
case "id":
return ec.fieldContext_SubGraph_id(ctx, field)
case "service":
return ec.fieldContext_SubGraph_service(ctx, field)
case "url":
return ec.fieldContext_SubGraph_url(ctx, field)
case "wsUrl":
return ec.fieldContext_SubGraph_wsUrl(ctx, field)
case "sdl":
return ec.fieldContext_SubGraph_sdl(ctx, field)
case "changedBy":
return ec.fieldContext_SubGraph_changedBy(ctx, field)
case "changedAt":
return ec.fieldContext_SubGraph_changedAt(ctx, field)
}
return nil, fmt.Errorf("no field named %q was found under type SubGraph", field.Name)
},
}
return fc, nil
}
func (ec *executionContext) _Unchanged_id(ctx context.Context, field graphql.CollectedField, obj *model.Unchanged) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Unchanged_id(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.ID, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(string)
fc.Result = res
return ec.marshalNID2string(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Unchanged_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "Unchanged",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type ID does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _Unchanged_minDelaySeconds(ctx context.Context, field graphql.CollectedField, obj *model.Unchanged) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Unchanged_minDelaySeconds(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.MinDelaySeconds, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(int)
fc.Result = res
return ec.marshalNInt2int(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Unchanged_minDelaySeconds(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "Unchanged",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type Int does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) {
fc, err := ec.fieldContext___Directive_name(ctx, field)
if err != nil {
@@ -2799,6 +3208,29 @@ func (ec *executionContext) unmarshalInputInputSubGraph(ctx context.Context, obj
// region ************************** interface.gotpl ***************************
func (ec *executionContext) _Supergraph(ctx context.Context, sel ast.SelectionSet, obj model.Supergraph) graphql.Marshaler {
switch obj := (obj).(type) {
case nil:
return graphql.Null
case model.Unchanged:
return ec._Unchanged(ctx, sel, &obj)
case *model.Unchanged:
if obj == nil {
return graphql.Null
}
return ec._Unchanged(ctx, sel, obj)
case model.SubGraphs:
return ec._SubGraphs(ctx, sel, &obj)
case *model.SubGraphs:
if obj == nil {
return graphql.Null
}
return ec._SubGraphs(ctx, sel, obj)
default:
panic(fmt.Errorf("unexpected type %T", obj))
}
}
// endregion ************************** interface.gotpl ***************************
// region **************************** object.gotpl ****************************
@@ -2881,6 +3313,29 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr
return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc)
}
out.Concurrently(i, func() graphql.Marshaler {
return rrm(innerCtx)
})
case "supergraph":
field := field
innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._Query_supergraph(ctx, field)
if res == graphql.Null {
atomic.AddUint32(&invalids, 1)
}
return res
}
rrm := func(ctx context.Context) graphql.Marshaler {
return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc)
}
out.Concurrently(i, func() graphql.Marshaler {
return rrm(innerCtx)
})
@@ -2971,6 +3426,83 @@ func (ec *executionContext) _SubGraph(ctx context.Context, sel ast.SelectionSet,
return out
}
var subGraphsImplementors = []string{"SubGraphs", "Supergraph"}
func (ec *executionContext) _SubGraphs(ctx context.Context, sel ast.SelectionSet, obj *model.SubGraphs) graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, subGraphsImplementors)
out := graphql.NewFieldSet(fields)
var invalids uint32
for i, field := range fields {
switch field.Name {
case "__typename":
out.Values[i] = graphql.MarshalString("SubGraphs")
case "id":
out.Values[i] = ec._SubGraphs_id(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
case "minDelaySeconds":
out.Values[i] = ec._SubGraphs_minDelaySeconds(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
case "subGraphs":
out.Values[i] = ec._SubGraphs_subGraphs(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
default:
panic("unknown field " + strconv.Quote(field.Name))
}
}
out.Dispatch()
if invalids > 0 {
return graphql.Null
}
return out
}
var unchangedImplementors = []string{"Unchanged", "Supergraph"}
func (ec *executionContext) _Unchanged(ctx context.Context, sel ast.SelectionSet, obj *model.Unchanged) graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, unchangedImplementors)
out := graphql.NewFieldSet(fields)
var invalids uint32
for i, field := range fields {
switch field.Name {
case "__typename":
out.Values[i] = graphql.MarshalString("Unchanged")
case "id":
out.Values[i] = ec._Unchanged_id(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
case "minDelaySeconds":
out.Values[i] = ec._Unchanged_minDelaySeconds(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
default:
panic("unknown field " + strconv.Quote(field.Name))
}
}
out.Dispatch()
if invalids > 0 {
return graphql.Null
}
return out
}
var __DirectiveImplementors = []string{"__Directive"}
func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler {
@@ -3324,6 +3856,21 @@ func (ec *executionContext) unmarshalNInputSubGraph2gitlabᚗcomᚋunboundsoftwa
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) unmarshalNInt2int(ctx context.Context, v interface{}) (int, error) {
res, err := graphql.UnmarshalInt(v)
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalNInt2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler {
res := graphql.MarshalInt(v)
if res == graphql.Null {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
}
}
return res
}
func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) {
res, err := graphql.UnmarshalString(v)
return res, graphql.ErrorOnPath(ctx, err)
@@ -3397,6 +3944,16 @@ func (ec *executionContext) marshalNSubGraph2ᚖgitlabᚗcomᚋunboundsoftware
return ec._SubGraph(ctx, sel, v)
}
func (ec *executionContext) marshalNSupergraph2gitlabᚗcomᚋunboundsoftwareᚋschemasᚋgraphᚋmodelᚐSupergraph(ctx context.Context, sel ast.SelectionSet, v model.Supergraph) graphql.Marshaler {
if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
}
return graphql.Null
}
return ec._Supergraph(ctx, sel, v)
}
func (ec *executionContext) unmarshalNTime2timeᚐTime(ctx context.Context, v interface{}) (time.Time, error) {
res, err := graphql.UnmarshalTime(v)
return res, graphql.ErrorOnPath(ctx, err)