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
+36 -12
View File
@@ -5,6 +5,8 @@ package graph
import (
"context"
"fmt"
"strings"
"github.com/wundergraph/graphql-go-tools/pkg/federation/sdlmerge"
"gitlab.com/unboundsoftware/eventsourced/eventsourced"
@@ -25,8 +27,12 @@ func (r *mutationResolver) UpdateSubGraph(ctx context.Context, input model.Input
if err != nil {
return nil, err
}
if strings.TrimSpace(input.Sdl) == strings.TrimSpace(subGraph.Sdl) {
return r.toGqlSubGraph(subGraph), nil
}
serviceSDLs := []string{input.Sdl}
for _, id := range r.Cache.Services(input.Ref) {
services, _ := r.Cache.Services(input.Ref, "")
for _, id := range services {
sg, err := r.fetchSubGraph(id)
if err != nil {
return nil, err
@@ -50,20 +56,34 @@ func (r *mutationResolver) UpdateSubGraph(ctx context.Context, input model.Input
if err != nil {
return nil, err
}
return &model.SubGraph{
ID: subGraph.ID.String(),
Service: subGraph.Service,
URL: subGraph.Url,
WsURL: subGraph.WSUrl,
Sdl: subGraph.Sdl,
ChangedBy: subGraph.ChangedBy,
ChangedAt: subGraph.ChangedAt,
}, nil
return r.toGqlSubGraph(subGraph), nil
}
// SubGraphs is the resolver for the subGraphs field.
func (r *queryResolver) SubGraphs(ctx context.Context, ref string) ([]*model.SubGraph, error) {
services := r.Cache.Services(ref)
res, err := r.Supergraph(ctx, ref, nil)
if err != nil {
return nil, err
}
if s, ok := res.(*model.SubGraphs); ok {
return s.SubGraphs, nil
}
return nil, fmt.Errorf("unexpected response")
}
// Supergraph is the resolver for the supergraph field.
func (r *queryResolver) Supergraph(ctx context.Context, ref string, isAfter *string) (model.Supergraph, error) {
after := ""
if isAfter != nil {
after = *isAfter
}
services, lastUpdate := r.Cache.Services(ref, after)
if after == lastUpdate {
return &model.Unchanged{
ID: lastUpdate,
MinDelaySeconds: 10,
}, nil
}
subGraphs := make([]*model.SubGraph, len(services))
for i, id := range services {
sg, err := r.fetchSubGraph(id)
@@ -80,7 +100,11 @@ func (r *queryResolver) SubGraphs(ctx context.Context, ref string) ([]*model.Sub
ChangedAt: sg.ChangedAt,
}
}
return subGraphs, nil
return &model.SubGraphs{
ID: lastUpdate,
SubGraphs: subGraphs,
MinDelaySeconds: 10,
}, nil
}
// Mutation returns generated.MutationResolver implementation.