feat: add full SDL to SupGraph response

This commit is contained in:
2024-03-25 21:46:15 +01:00
parent be878a3f2a
commit 6cd3b935e4
5 changed files with 77 additions and 0 deletions
+59
View File
@@ -16,6 +16,7 @@ import (
"github.com/99designs/gqlgen/graphql/introspection" "github.com/99designs/gqlgen/graphql/introspection"
gqlparser "github.com/vektah/gqlparser/v2" gqlparser "github.com/vektah/gqlparser/v2"
"github.com/vektah/gqlparser/v2/ast" "github.com/vektah/gqlparser/v2/ast"
"gitlab.com/unboundsoftware/schemas/graph/model" "gitlab.com/unboundsoftware/schemas/graph/model"
) )
@@ -89,6 +90,7 @@ type ComplexityRoot struct {
SubGraphs struct { SubGraphs struct {
ID func(childComplexity int) int ID func(childComplexity int) int
MinDelaySeconds func(childComplexity int) int MinDelaySeconds func(childComplexity int) int
Sdl func(childComplexity int) int
SubGraphs 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 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": case "SubGraphs.subGraphs":
if e.complexity.SubGraphs.SubGraphs == nil { if e.complexity.SubGraphs.SubGraphs == nil {
break break
@@ -503,6 +512,7 @@ type Unchanged {
type SubGraphs { type SubGraphs {
id: ID! id: ID!
minDelaySeconds: Int! minDelaySeconds: Int!
sdl: String!
subGraphs: [SubGraph!]! subGraphs: [SubGraph!]!
} }
@@ -2155,6 +2165,50 @@ func (ec *executionContext) fieldContext_SubGraphs_minDelaySeconds(ctx context.C
return fc, nil 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) { 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) fc, err := ec.fieldContext_SubGraphs_subGraphs(ctx, field)
if err != nil { if err != nil {
@@ -4622,6 +4676,11 @@ func (ec *executionContext) _SubGraphs(ctx context.Context, sel ast.SelectionSet
if out.Values[i] == graphql.Null { if out.Values[i] == graphql.Null {
out.Invalids++ out.Invalids++
} }
case "sdl":
out.Values[i] = ec._SubGraphs_sdl(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
}
case "subGraphs": case "subGraphs":
out.Values[i] = ec._SubGraphs_subGraphs(ctx, field, obj) out.Values[i] = ec._SubGraphs_subGraphs(ctx, field, obj)
if out.Values[i] == graphql.Null { if out.Values[i] == graphql.Null {
+1
View File
@@ -62,6 +62,7 @@ type SubGraph struct {
type SubGraphs struct { type SubGraphs struct {
ID string `json:"id"` ID string `json:"id"`
MinDelaySeconds int `json:"minDelaySeconds"` MinDelaySeconds int `json:"minDelaySeconds"`
Sdl string `json:"sdl"`
SubGraphs []*SubGraph `json:"subGraphs"` SubGraphs []*SubGraph `json:"subGraphs"`
} }
+2
View File
@@ -12,6 +12,8 @@ import (
) )
//go:generate go run github.com/99designs/gqlgen //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. // This file will not be regenerated automatically.
// //
+1
View File
@@ -40,6 +40,7 @@ type Unchanged {
type SubGraphs { type SubGraphs {
id: ID! id: ID!
minDelaySeconds: Int! minDelaySeconds: Int!
sdl: String!
subGraphs: [SubGraph!]! subGraphs: [SubGraph!]!
} }
+14
View File
@@ -163,9 +163,23 @@ func (r *queryResolver) Supergraph(ctx context.Context, ref string, isAfter *str
ChangedAt: sg.ChangedAt, 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{ return &model.SubGraphs{
ID: lastUpdate, ID: lastUpdate,
SubGraphs: subGraphs, SubGraphs: subGraphs,
Sdl: sdl,
MinDelaySeconds: 10, MinDelaySeconds: 10,
}, nil }, nil
} }