Refract is an open-source CLI tool for merging Prisma schemas from multiple fragments and packages. It enables consistent schema management in monorepos, detects conflicts, generates cache for faster builds, and provides detailed schema statistics.
- Merge
.prismafiles from fragments and packages automatically - Detect conflicts in
model,enum,type, andviewblocks - Content hash-based caching for incremental builds
- Strips
datasourceandgeneratorblocks from package schemas automatically - Generates detailed schema statistics
- Supports custom paths and forced rebuilds
Clone the repository:
git clone https://github.com/johanlabs/refract.git
cd refract
npm installTo install globally:
npm install -g .Run the CLI with default paths:
refractDefault paths:
- Fragments:
./prisma/fragments - Packages:
./src/packages - Output:
./prisma/schema.prisma
| Option | Alias | Type | Description | Default |
|---|---|---|---|---|
--fragments |
-f |
string | Path to fragments directory | ./prisma/fragments |
--packages |
-p |
string | Path to packages schemas | ./src/packages |
--output |
-o |
string | Output path for merged schema | ./prisma/schema.prisma |
--force |
- | boolean | Force rebuild ignoring cache | false |
--help |
-h |
- | Show CLI help | - |
--version |
-v |
- | Show CLI version | - |
Merge using default paths:
refractMerge using custom paths:
refract -f ./custom/fragments -o ./output/schema.prismaForce rebuild ignoring cache:
refract --force- Scans all
.prismafiles in fragments and packages directories. - Fragments can contain
generatoranddatasourceblocks, which are preserved in the final schema. - Package schemas have
generatoranddatasourceblocks removed. - Each block (
model,enum,type,view) is parsed and merged. Conflicts are logged. - Generates a SHA-256 hash of all files for caching.
- Writes the merged schema to the output path and updates
.schema.cache.
After execution, Refract displays:
- Total
models - Total
enums - Total
types - Total
views
This allows for quick verification of the merged schema structure.
- Keep fragments for main schema definitions with
datasourceandgenerator. - Package schemas should only contain additional models, enums, or types.
- Use
--forceif file changes are not reflected due to caching.
Business Source License (BSL).