feat: initial commit
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package graph
|
||||
|
||||
// This file will be automatically regenerated based on the schema, any resolver implementations
|
||||
// will be copied through when generating and any unknown code will be moved to the end.
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/wundergraph/graphql-go-tools/pkg/federation/sdlmerge"
|
||||
"gitlab.com/unboundsoftware/eventsourced/eventsourced"
|
||||
|
||||
"gitlab.com/unboundsoftware/schemas/domain"
|
||||
"gitlab.com/unboundsoftware/schemas/graph/generated"
|
||||
"gitlab.com/unboundsoftware/schemas/graph/model"
|
||||
)
|
||||
|
||||
// UpdateSubGraph is the resolver for the updateSubGraph field.
|
||||
func (r *mutationResolver) UpdateSubGraph(ctx context.Context, input model.InputSubGraph) (*model.SubGraph, error) {
|
||||
subGraphId := r.Cache.SubGraphId(input.Ref, input.Service)
|
||||
subGraph := &domain.SubGraph{}
|
||||
if subGraphId != "" {
|
||||
subGraph.BaseAggregate = eventsourced.BaseAggregateFromString(subGraphId)
|
||||
}
|
||||
handler, err := r.handler(subGraph)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
serviceSDLs := []string{input.Sdl}
|
||||
for _, id := range r.Cache.Services(input.Ref) {
|
||||
sg, err := r.fetchSubGraph(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if sg.Service != input.Service {
|
||||
serviceSDLs = append(serviceSDLs, sg.Sdl)
|
||||
}
|
||||
}
|
||||
_, err = sdlmerge.MergeSDLs(serviceSDLs...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = handler.Handle(domain.UpdateSubGraph{
|
||||
Ref: input.Ref,
|
||||
Service: input.Service,
|
||||
Url: input.URL,
|
||||
WSUrl: input.WsURL,
|
||||
Sdl: input.Sdl,
|
||||
Initiator: "Fetch name from API-key?",
|
||||
})
|
||||
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
|
||||
}
|
||||
|
||||
// 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)
|
||||
subGraphs := make([]*model.SubGraph, len(services))
|
||||
for i, id := range services {
|
||||
sg, err := r.fetchSubGraph(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
subGraphs[i] = &model.SubGraph{
|
||||
ID: sg.ID.String(),
|
||||
Service: sg.Service,
|
||||
URL: sg.Url,
|
||||
WsURL: sg.WSUrl,
|
||||
Sdl: sg.Sdl,
|
||||
ChangedBy: sg.ChangedBy,
|
||||
ChangedAt: sg.ChangedAt,
|
||||
}
|
||||
}
|
||||
return subGraphs, nil
|
||||
}
|
||||
|
||||
// Mutation returns generated.MutationResolver implementation.
|
||||
func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResolver{r} }
|
||||
|
||||
// Query returns generated.QueryResolver implementation.
|
||||
func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }
|
||||
|
||||
type (
|
||||
mutationResolver struct{ *Resolver }
|
||||
queryResolver struct{ *Resolver }
|
||||
)
|
||||
Reference in New Issue
Block a user