Add cookie banner and category dataloaders

Batch-load CookieBanner and CookieCategory entities via
dataloadgen instead of making individual service calls in
GraphQL resolvers, matching the existing dataloader pattern
used for organizations, frameworks, etc.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-27 19:21:33 +04:00
parent d9b0d5f44d
commit b9835f0f25
7 changed files with 217 additions and 36 deletions

View File

@@ -692,6 +692,30 @@ func (s *Service) GetCookieBanner(
return &banner, nil
}
func (s *Service) GetCookieBannersByIDs(
ctx context.Context,
scope coredata.Scoper,
bannerIDs ...gid.GID,
) (coredata.CookieBanners, error) {
var banners coredata.CookieBanners
err := s.pg.WithConn(
ctx,
func(ctx context.Context, conn pg.Querier) error {
if err := banners.LoadByIDs(ctx, conn, scope, bannerIDs); err != nil {
return fmt.Errorf("cannot load cookie banners by ids: %w", err)
}
return nil
},
)
if err != nil {
return nil, err
}
return banners, nil
}
func (s *Service) GetActiveCookieBanner(
ctx context.Context,
bannerID gid.GID,
@@ -1072,6 +1096,30 @@ func (s *Service) GetCookieCategory(
return &category, nil
}
func (s *Service) GetCookieCategoriesByIDs(
ctx context.Context,
scope coredata.Scoper,
categoryIDs ...gid.GID,
) (coredata.CookieCategories, error) {
var categories coredata.CookieCategories
err := s.pg.WithConn(
ctx,
func(ctx context.Context, conn pg.Querier) error {
if err := categories.LoadByIDs(ctx, conn, scope, categoryIDs); err != nil {
return fmt.Errorf("cannot load cookie categories by ids: %w", err)
}
return nil
},
)
if err != nil {
return nil, err
}
return categories, nil
}
func (s *Service) ListCookieCategoriesForBanner(
ctx context.Context,
scope coredata.Scoper,