Add GraphQL dataloaders for batched record lookups
Introduce dataloadgen-based dataloaders to batch individual record-by-ID fetches in GraphQL resolvers into single SQL queries. Each entity type (organization, framework, control, vendor, document, risk, measure, task, file, report, profile) gets a LoadByIDs method in coredata and a GetByIDs service method with variadic arguments and dedicated collection return types. Resolvers now use dataloader.FromContext instead of direct service calls for single-record lookups. Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -447,6 +447,34 @@ func (s FrameworkService) Get(
|
||||
return framework, nil
|
||||
}
|
||||
|
||||
func (s FrameworkService) GetByIDs(
|
||||
ctx context.Context,
|
||||
frameworkIDs ...gid.GID,
|
||||
) (coredata.Frameworks, error) {
|
||||
var frameworks coredata.Frameworks
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := frameworks.LoadByIDs(
|
||||
ctx,
|
||||
conn,
|
||||
s.svc.scope,
|
||||
frameworkIDs,
|
||||
); err != nil {
|
||||
return fmt.Errorf("cannot load frameworks by ids: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return frameworks, nil
|
||||
}
|
||||
|
||||
func (s FrameworkService) Update(
|
||||
ctx context.Context,
|
||||
req UpdateFrameworkRequest,
|
||||
|
||||
Reference in New Issue
Block a user