Add frameworks totalCount support

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-06-09 20:14:47 -07:00
parent 35dcad829b
commit c7c889e5ca
7 changed files with 211 additions and 18 deletions

View File

@@ -202,9 +202,9 @@ func (r *controlConnectionResolver) TotalCount(ctx context.Context, obj *types.C
return 0, fmt.Errorf("cannot count controls: %w", err)
}
return count, nil
default:
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
}
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
}
// Owner is the resolver for the owner field.
@@ -584,6 +584,22 @@ func (r *frameworkResolver) Controls(ctx context.Context, obj *types.Framework,
return types.NewControlConnection(page, r, obj.ID, controlFilter), nil
}
// TotalCount is the resolver for the totalCount field.
func (r *frameworkConnectionResolver) TotalCount(ctx context.Context, obj *types.FrameworkConnection) (int, error) {
svc := GetTenantService(ctx, r.proboSvc, obj.ParentID.TenantID())
switch obj.Resolver.(type) {
case *organizationResolver:
count, err := svc.Frameworks.CountForOrganizationID(ctx, obj.ParentID)
if err != nil {
return 0, fmt.Errorf("cannot count frameworks: %w", err)
}
return count, nil
}
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
}
// Evidences is the resolver for the evidences field.
func (r *measureResolver) Evidences(ctx context.Context, obj *types.Measure, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.EvidenceOrderBy) (*types.EvidenceConnection, error) {
svc := GetTenantService(ctx, r.proboSvc, obj.ID.TenantID())
@@ -2026,7 +2042,7 @@ func (r *organizationResolver) Frameworks(ctx context.Context, obj *types.Organi
panic(fmt.Errorf("cannot list organization frameworks: %w", err))
}
return types.NewFrameworkConnection(page), nil
return types.NewFrameworkConnection(page, r, obj.ID), nil
}
// Controls is the resolver for the controls field.
@@ -2832,6 +2848,11 @@ func (r *Resolver) Evidence() schema.EvidenceResolver { return &evidenceResolver
// Framework returns schema.FrameworkResolver implementation.
func (r *Resolver) Framework() schema.FrameworkResolver { return &frameworkResolver{r} }
// FrameworkConnection returns schema.FrameworkConnectionResolver implementation.
func (r *Resolver) FrameworkConnection() schema.FrameworkConnectionResolver {
return &frameworkConnectionResolver{r}
}
// Measure returns schema.MeasureResolver implementation.
func (r *Resolver) Measure() schema.MeasureResolver { return &measureResolver{r} }
@@ -2878,6 +2899,7 @@ type documentVersionResolver struct{ *Resolver }
type documentVersionSignatureResolver struct{ *Resolver }
type evidenceResolver struct{ *Resolver }
type frameworkResolver struct{ *Resolver }
type frameworkConnectionResolver struct{ *Resolver }
type measureResolver struct{ *Resolver }
type mutationResolver struct{ *Resolver }
type organizationResolver struct{ *Resolver }