diff --git a/graph/generated/generated.go b/graph/generated/generated.go index 6acf778..79257a8 100644 --- a/graph/generated/generated.go +++ b/graph/generated/generated.go @@ -16,6 +16,7 @@ import ( "github.com/99designs/gqlgen/graphql/introspection" gqlparser "github.com/vektah/gqlparser/v2" "github.com/vektah/gqlparser/v2/ast" + "gitlab.com/unboundsoftware/schemas/graph/model" ) @@ -89,6 +90,7 @@ type ComplexityRoot struct { SubGraphs struct { ID func(childComplexity int) int MinDelaySeconds func(childComplexity int) int + Sdl func(childComplexity int) int SubGraphs func(childComplexity int) int } @@ -326,6 +328,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.SubGraphs.MinDelaySeconds(childComplexity), true + case "SubGraphs.sdl": + if e.complexity.SubGraphs.Sdl == nil { + break + } + + return e.complexity.SubGraphs.Sdl(childComplexity), true + case "SubGraphs.subGraphs": if e.complexity.SubGraphs.SubGraphs == nil { break @@ -503,6 +512,7 @@ type Unchanged { type SubGraphs { id: ID! minDelaySeconds: Int! + sdl: String! subGraphs: [SubGraph!]! } @@ -2155,6 +2165,50 @@ func (ec *executionContext) fieldContext_SubGraphs_minDelaySeconds(ctx context.C return fc, nil } +func (ec *executionContext) _SubGraphs_sdl(ctx context.Context, field graphql.CollectedField, obj *model.SubGraphs) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SubGraphs_sdl(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.Sdl, 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.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_SubGraphs_sdl(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 String 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 { @@ -4622,6 +4676,11 @@ func (ec *executionContext) _SubGraphs(ctx context.Context, sel ast.SelectionSet if out.Values[i] == graphql.Null { out.Invalids++ } + case "sdl": + out.Values[i] = ec._SubGraphs_sdl(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } case "subGraphs": out.Values[i] = ec._SubGraphs_subGraphs(ctx, field, obj) if out.Values[i] == graphql.Null { diff --git a/graph/model/models_gen.go b/graph/model/models_gen.go index 975206d..c1dcb42 100644 --- a/graph/model/models_gen.go +++ b/graph/model/models_gen.go @@ -62,6 +62,7 @@ type SubGraph struct { type SubGraphs struct { ID string `json:"id"` MinDelaySeconds int `json:"minDelaySeconds"` + Sdl string `json:"sdl"` SubGraphs []*SubGraph `json:"subGraphs"` } diff --git a/graph/resolver.go b/graph/resolver.go index 98bc974..a27d195 100644 --- a/graph/resolver.go +++ b/graph/resolver.go @@ -12,6 +12,8 @@ import ( ) //go:generate go run github.com/99designs/gqlgen +//go:generate gofumpt -w . +//go:generate goimports -w -local gitlab.com/unboundsoftware/schemas . // This file will not be regenerated automatically. // diff --git a/graph/schema.graphqls b/graph/schema.graphqls index b58b244..79409f7 100644 --- a/graph/schema.graphqls +++ b/graph/schema.graphqls @@ -40,6 +40,7 @@ type Unchanged { type SubGraphs { id: ID! minDelaySeconds: Int! + sdl: String! subGraphs: [SubGraph!]! } diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go index d3c9684..c1f4c3f 100644 --- a/graph/schema.resolvers.go +++ b/graph/schema.resolvers.go @@ -163,9 +163,23 @@ func (r *queryResolver) Supergraph(ctx context.Context, ref string, isAfter *str ChangedAt: sg.ChangedAt, } } + + var serviceSDLs []string + for _, id := range services { + sg, err := r.fetchSubGraph(ctx, id) + if err != nil { + return nil, err + } + serviceSDLs = append(serviceSDLs, sg.Sdl) + } + sdl, err := sdlmerge.MergeSDLs(serviceSDLs...) + if err != nil { + return nil, err + } return &model.SubGraphs{ ID: lastUpdate, SubGraphs: subGraphs, + Sdl: sdl, MinDelaySeconds: 10, }, nil }