Add control resolver

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-01-22 16:33:25 +01:00
parent 5c0100f8b2
commit d1531c1fba
4 changed files with 143 additions and 4 deletions

View File

@@ -0,0 +1,30 @@
package types
import (
"github.com/getprobo/probo/pkg/probo/coredata"
"github.com/getprobo/probo/pkg/probo/coredata/page"
)
func NewControlConnection(p *page.Page[*coredata.Control]) *ControlConnection {
var edges = make([]*ControlEdge, len(p.Data))
for i := range edges {
edges[i] = NewControlEdge(p.Data[i])
}
return &ControlConnection{
Edges: edges,
PageInfo: NewPageInfo(p),
}
}
func NewControlEdge(f *coredata.Control) *ControlEdge {
return &ControlEdge{
Cursor: f.CursorKey(),
Node: NewControl(f),
}
}
func NewControl(e *coredata.Control) *Control {
return &Control{}
}

View File

@@ -20,7 +20,14 @@ func (r *controlResolver) Tasks(ctx context.Context, obj *types.Control, first *
// Controls is the resolver for the controls field.
func (r *frameworkResolver) Controls(ctx context.Context, obj *types.Framework, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.ControlConnection, error) {
panic(fmt.Errorf("not implemented: Controls - controls"))
cursor := types.NewCursor(first, after, last, before)
page, err := r.svc.ListFrameworkControls(ctx, obj.ID, cursor)
if err != nil {
return nil, fmt.Errorf("cannot list framework controls: %w", err)
}
return types.NewControlConnection(page, cursor), nil
}
// Frameworks is the resolver for the frameworks field.