[go: up one dir, main page]

Skip to content

A generator for Prisma 2 to produce Mongo-compatible $jsonSchema and perform data validation with it

License

Notifications You must be signed in to change notification settings

joindeed/prisma-mongo-json-schema-generator

Repository files navigation

Prisma Mongo JSON Schema Generator

This package contains two things:

Why?

Because Prisma would blow up at the very wrong moment if the underlying data is invalid. Read this thread to understand the problem better:

image

Credit

This package is a fork of prisma-json-schema-generator, an amazing work by Valentin Palkovic!

Getting Started

1. Install

npm:

npm install prisma-mongo-json-schema-generator --save-dev

yarn:

yarn add -D prisma-mongo-json-schema-generator

2. Apply the schema to database

PRISMA_SCHEMA_FILE=prisma/prisma.schema MONGO_URI=mongodb://localhost:27017/your-database yarn prisma-mongo-json-schema-generator-apply

If you are getting AuthenticationFailed errors, make sure that you are specifying the correct auth database in the connection URI by using the authSource query parameter (ex: authSource=admin).

The package is configurable via environment variables:

Env name Default value
MONGO_URI required
PRISMA_SCHEMA_FILE prisma/prisma.schema
VALIDATION_LEVEL strict
VALIDATION_ACTION error

If you want to omit some property from being included in the schema, add @MongoSchema.omit to its documentation in the Prisma schema:

model SomeModel {
  /// @MongoSchema.omit
  someProperty String
}

3. Validate collections according to the schema

PRISMA_SCHEMA_FILE=prisma/prisma.schema MONGO_URI=mongodb://localhost:27017/your-database yarn prisma-mongo-json-schema-generator-verify

About

A generator for Prisma 2 to produce Mongo-compatible $jsonSchema and perform data validation with it

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published