-
Couldn't load subscription status.
- Fork 619
Open
@dpkass
Description
Problem
Common cases like soft delete and multi-tenancy require adding the same WHERE clause to every query. SDN has no built-in way to apply a predicate to all generated queries for an entity (derived queries, counts/exists, relationship loads). This is easy to miss and error-prone.
Proposal
Introduce an opt-in, entity-scoped restriction that SDN appends to generated Cypher.
@Node("Organization") @QueryRestriction("deletedAt IS NULL") @QueryRestriction("tenantId = $tenantId") // maybe even allow SpEL class Organization { Instant deletedAt; String tenantId; }
- Support simple parameters via a small SPI:
@Bean QueryRestrictionParameters params(TenantResolver r) { return () -> Map.of("tenantId", r.currentTenantId()); }
- Allow per-method opt-out:
@IgnoreQueryRestrictions @Query("MATCH (o:Organization) RETURN o") List<Organization> adminListAll();
Scope
Applied to derived queries (findAll, findById, count, exists, paging) and relationship loads. Does not change custom @query unless opted in/out as above.
Workarounds today
Duplicate predicates everywhere or change labels on delete—both brittle.
Prior art
Hibernate/JPA’s @SQLRestriction (and now deprecated predecessor @where) provide similar per-entity SQL predicates.