dataLayer() function
Build the whole data layer from an emitted contract, in one call.
Signature:
export declare function dataLayer(options: DataLayerOptions): DataLayer;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
options |
The contract, what cannot be derived, and the resolvers. |
Returns:
The middleware array and a teardown hook.
Exceptions
When scope names a model the contract does not define.
Remarks
The middlewares are returned already composed, which is the point: a caller never orders them and so cannot order them wrongly. Under Prisma 7 this was five $extends calls whose sequence every service repeated and any service could get wrong, with a soft delete losing its deletedBy and nothing reporting it. Here the two halves that were order-dependent are one middleware, and what remains genuinely commutes.
Reach for the individual factories only to compose something this does not cover; for the ordinary case this is the entry point.
Example
const layer = dataLayer({
contract: contractJson,
scope: { Portfolio: { portfolio: ['id'] } },
resolvers: { portfolio: () => currentPortfolioIds() },
getActorId: currentActorId,
});
export const db = postgres<Contract>({
contractJson,
url: config.db.url,
middleware: layer.middleware,
});
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.