Refactor document detail to document layout

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-01-26 18:58:49 +04:00
parent 3f96869b6b
commit fb09bed247
36 changed files with 2861 additions and 2310 deletions

View File

@@ -2889,9 +2889,13 @@ type VendorRiskAssessmentEdge {
node: VendorRiskAssessment!
}
type DocumentVersionConnection {
type DocumentVersionConnection
@goModel(
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.DocumentVersionConnection"
) {
edges: [DocumentVersionEdge!]!
pageInfo: PageInfo!
totalCount: Int! @goField(forceResolver: true)
}
type DocumentVersionEdge {
@@ -4695,10 +4699,7 @@ type DeleteMeasurePayload {
deletedMeasureId: ID!
}
type DocumentVersion implements Node
@goModel(
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.DocumentVersion"
) {
type DocumentVersion implements Node {
id: ID!
document: Document! @goField(forceResolver: true)
status: DocumentStatus!

View File

@@ -65,6 +65,7 @@ type ResolverRoot interface {
Document() DocumentResolver
DocumentConnection() DocumentConnectionResolver
DocumentVersion() DocumentVersionResolver
DocumentVersionConnection() DocumentVersionConnectionResolver
DocumentVersionSignature() DocumentVersionSignatureResolver
Evidence() EvidenceResolver
EvidenceConnection() EvidenceConnectionResolver
@@ -743,8 +744,9 @@ type ComplexityRoot struct {
}
DocumentVersionConnection struct {
Edges func(childComplexity int) int
PageInfo func(childComplexity int) int
Edges func(childComplexity int) int
PageInfo func(childComplexity int) int
TotalCount func(childComplexity int) int
}
DocumentVersionEdge struct {
@@ -2020,6 +2022,9 @@ type DocumentVersionResolver interface {
Permission(ctx context.Context, obj *types.DocumentVersion, action string) (bool, error)
}
type DocumentVersionConnectionResolver interface {
TotalCount(ctx context.Context, obj *types.DocumentVersionConnection) (int, error)
}
type DocumentVersionSignatureResolver interface {
DocumentVersion(ctx context.Context, obj *types.DocumentVersionSignature) (*types.DocumentVersion, error)
@@ -4371,6 +4376,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
}
return e.complexity.DocumentVersionConnection.PageInfo(childComplexity), true
case "DocumentVersionConnection.totalCount":
if e.complexity.DocumentVersionConnection.TotalCount == nil {
break
}
return e.complexity.DocumentVersionConnection.TotalCount(childComplexity), true
case "DocumentVersionEdge.cursor":
if e.complexity.DocumentVersionEdge.Cursor == nil {
@@ -13178,9 +13189,13 @@ type VendorRiskAssessmentEdge {
node: VendorRiskAssessment!
}
type DocumentVersionConnection {
type DocumentVersionConnection
@goModel(
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.DocumentVersionConnection"
) {
edges: [DocumentVersionEdge!]!
pageInfo: PageInfo!
totalCount: Int! @goField(forceResolver: true)
}
type DocumentVersionEdge {
@@ -14984,10 +14999,7 @@ type DeleteMeasurePayload {
deletedMeasureId: ID!
}
type DocumentVersion implements Node
@goModel(
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.DocumentVersion"
) {
type DocumentVersion implements Node {
id: ID!
document: Document! @goField(forceResolver: true)
status: DocumentStatus!
@@ -28742,6 +28754,8 @@ func (ec *executionContext) fieldContext_Document_versions(ctx context.Context,
return ec.fieldContext_DocumentVersionConnection_edges(ctx, field)
case "pageInfo":
return ec.fieldContext_DocumentVersionConnection_pageInfo(ctx, field)
case "totalCount":
return ec.fieldContext_DocumentVersionConnection_totalCount(ctx, field)
}
return nil, fmt.Errorf("no field named %q was found under type DocumentVersionConnection", field.Name)
},
@@ -29663,7 +29677,7 @@ func (ec *executionContext) _DocumentVersionConnection_pageInfo(ctx context.Cont
return obj.PageInfo, nil
},
nil,
ec.marshalNPageInfo2ᚖgoᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐPageInfo,
ec.marshalNPageInfo2goᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐPageInfo,
true,
true,
)
@@ -29692,6 +29706,35 @@ func (ec *executionContext) fieldContext_DocumentVersionConnection_pageInfo(_ co
return fc, nil
}
func (ec *executionContext) _DocumentVersionConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *types.DocumentVersionConnection) (ret graphql.Marshaler) {
return graphql.ResolveField(
ctx,
ec.OperationContext,
field,
ec.fieldContext_DocumentVersionConnection_totalCount,
func(ctx context.Context) (any, error) {
return ec.resolvers.DocumentVersionConnection().TotalCount(ctx, obj)
},
nil,
ec.marshalNInt2int,
true,
true,
)
}
func (ec *executionContext) fieldContext_DocumentVersionConnection_totalCount(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "DocumentVersionConnection",
Field: field,
IsMethod: true,
IsResolver: true,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type Int does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _DocumentVersionEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *types.DocumentVersionEdge) (ret graphql.Marshaler) {
return graphql.ResolveField(
ctx,
@@ -47303,6 +47346,8 @@ func (ec *executionContext) fieldContext_SignableDocument_versions(ctx context.C
return ec.fieldContext_DocumentVersionConnection_edges(ctx, field)
case "pageInfo":
return ec.fieldContext_DocumentVersionConnection_pageInfo(ctx, field)
case "totalCount":
return ec.fieldContext_DocumentVersionConnection_totalCount(ctx, field)
}
return nil, fmt.Errorf("no field named %q was found under type DocumentVersionConnection", field.Name)
},
@@ -75868,13 +75913,49 @@ func (ec *executionContext) _DocumentVersionConnection(ctx context.Context, sel
case "edges":
out.Values[i] = ec._DocumentVersionConnection_edges(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
atomic.AddUint32(&out.Invalids, 1)
}
case "pageInfo":
out.Values[i] = ec._DocumentVersionConnection_pageInfo(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
atomic.AddUint32(&out.Invalids, 1)
}
case "totalCount":
field := field
innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._DocumentVersionConnection_totalCount(ctx, field, obj)
if res == graphql.Null {
atomic.AddUint32(&fs.Invalids, 1)
}
return res
}
if field.Deferrable != nil {
dfs, ok := deferred[field.Deferrable.Label]
di := 0
if ok {
dfs.AddField(field)
di = len(dfs.Values) - 1
} else {
dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
deferred[field.Deferrable.Label] = dfs
}
dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
return innerFunc(ctx, dfs)
})
// don't run the out.Concurrently() call below
out.Values[i] = graphql.Null
continue
}
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
default:
panic("unknown field " + strconv.Quote(field.Name))
}

View File

@@ -15,41 +15,30 @@
package types
import (
"time"
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/page"
)
type (
DocumentVersion struct {
ID gid.GID `json:"id"`
OrganizationID gid.GID `json:"-"`
Document *Document `json:"document"`
Status coredata.DocumentStatus `json:"status"`
Version int `json:"version"`
Content string `json:"content"`
Changelog string `json:"changelog"`
Title string `json:"title"`
Classification coredata.DocumentClassification `json:"classification"`
Owner *People `json:"owner"`
Signatures *DocumentVersionSignatureConnection `json:"signatures"`
PublishedAt *time.Time `json:"publishedAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
DocumentVersionOrderBy OrderBy[coredata.DocumentVersionOrderField]
DocumentVersionConnection struct {
TotalCount int
Edges []*DocumentVersionEdge
PageInfo PageInfo
Resolver any
ParentID gid.GID
Filters *coredata.DocumentVersionFilter
}
)
func (DocumentVersion) IsNode() {}
func (d DocumentVersion) GetID() gid.GID {
return d.ID
}
func NewDocumentVersionConnection(page *page.Page[*coredata.DocumentVersion, coredata.DocumentVersionOrderField]) *DocumentVersionConnection {
func NewDocumentVersionConnection(
page *page.Page[*coredata.DocumentVersion, coredata.DocumentVersionOrderField],
parentType any,
parentID gid.GID,
) *DocumentVersionConnection {
edges := make([]*DocumentVersionEdge, len(page.Data))
for i, documentVersion := range page.Data {
edges[i] = NewDocumentVersionEdge(documentVersion, page.Cursor.OrderBy.Field)
@@ -57,7 +46,10 @@ func NewDocumentVersionConnection(page *page.Page[*coredata.DocumentVersion, cor
return &DocumentVersionConnection{
Edges: edges,
PageInfo: NewPageInfo(page),
PageInfo: *NewPageInfo(page),
Resolver: parentType,
ParentID: parentID,
}
}
@@ -80,8 +72,7 @@ func NewDocumentVersionEdge(documentVersion *coredata.DocumentVersion, orderBy c
func NewDocumentVersion(documentVersion *coredata.DocumentVersion) *DocumentVersion {
return &DocumentVersion{
ID: documentVersion.ID,
OrganizationID: documentVersion.OrganizationID,
ID: documentVersion.ID,
Document: &Document{
ID: documentVersion.DocumentID,
},

View File

@@ -1156,11 +1156,27 @@ type DocumentFilter struct {
Query *string `json:"query,omitempty"`
}
type DocumentVersionConnection struct {
Edges []*DocumentVersionEdge `json:"edges"`
PageInfo *PageInfo `json:"pageInfo"`
type DocumentVersion struct {
ID gid.GID `json:"id"`
Document *Document `json:"document"`
Status coredata.DocumentStatus `json:"status"`
Version int `json:"version"`
Content string `json:"content"`
Changelog string `json:"changelog"`
Title string `json:"title"`
Classification coredata.DocumentClassification `json:"classification"`
Owner *People `json:"owner"`
Signatures *DocumentVersionSignatureConnection `json:"signatures"`
Signed bool `json:"signed"`
PublishedAt *time.Time `json:"publishedAt,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Permission bool `json:"permission"`
}
func (DocumentVersion) IsNode() {}
func (this DocumentVersion) GetID() gid.GID { return this.ID }
type DocumentVersionEdge struct {
Cursor page.CursorKey `json:"cursor"`
Node *DocumentVersion `json:"node"`

View File

@@ -939,7 +939,7 @@ func (r *documentResolver) Versions(ctx context.Context, obj *types.Document, fi
panic(fmt.Errorf("cannot list document versions: %w", err))
}
return types.NewDocumentVersionConnection(page), nil
return types.NewDocumentVersionConnection(page, r, obj.ID), nil
}
// Controls is the resolver for the controls field.
@@ -1120,6 +1120,32 @@ func (r *documentVersionResolver) Permission(ctx context.Context, obj *types.Doc
return r.Resolver.Permission(ctx, obj, action)
}
// TotalCount is the resolver for the totalCount field.
func (r *documentVersionConnectionResolver) TotalCount(ctx context.Context, obj *types.DocumentVersionConnection) (int, error) {
if err := r.authorize(ctx, obj.ParentID, probo.ActionEvidenceList); err != nil {
return 0, err
}
prb := r.ProboService(ctx, obj.ParentID.TenantID())
switch obj.Resolver.(type) {
case *documentResolver:
filter := &coredata.DocumentVersionFilter{}
if obj.Filters != nil {
filter = obj.Filters
}
count, err := prb.Documents.CountVersionsForDocumentID(ctx, obj.ParentID, filter)
if err != nil {
// TODO no panic use gqlutils.InternalError
panic(fmt.Errorf("cannot count tasks: %w", err))
}
return count, nil
}
// TODO no panic use gqlutils.InternalError
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
}
// DocumentVersion is the resolver for the documentVersion field.
func (r *documentVersionSignatureResolver) DocumentVersion(ctx context.Context, obj *types.DocumentVersionSignature) (*types.DocumentVersion, error) {
if err := r.authorize(ctx, obj.ID, probo.ActionDocumentVersionGet); err != nil {
@@ -7156,7 +7182,7 @@ func (r *signableDocumentResolver) Versions(ctx context.Context, obj *types.Sign
panic(fmt.Errorf("cannot list signable document versions: %w", err))
}
return types.NewDocumentVersionConnection(page), nil
return types.NewDocumentVersionConnection(page, r, obj.ID), nil
}
// Organization is the resolver for the organization field.
@@ -8522,6 +8548,11 @@ func (r *Resolver) DocumentVersion() schema.DocumentVersionResolver {
return &documentVersionResolver{r}
}
// DocumentVersionConnection returns schema.DocumentVersionConnectionResolver implementation.
func (r *Resolver) DocumentVersionConnection() schema.DocumentVersionConnectionResolver {
return &documentVersionConnectionResolver{r}
}
// DocumentVersionSignature returns schema.DocumentVersionSignatureResolver implementation.
func (r *Resolver) DocumentVersionSignature() schema.DocumentVersionSignatureResolver {
return &documentVersionSignatureResolver{r}
@@ -8754,6 +8785,7 @@ type datumConnectionResolver struct{ *Resolver }
type documentResolver struct{ *Resolver }
type documentConnectionResolver struct{ *Resolver }
type documentVersionResolver struct{ *Resolver }
type documentVersionConnectionResolver struct{ *Resolver }
type documentVersionSignatureResolver struct{ *Resolver }
type evidenceResolver struct{ *Resolver }
type evidenceConnectionResolver struct{ *Resolver }