nexus-prisma
Official Prisma plugin for Nexus.
Currently in development - not to be used in Production. Follow the progress from here.
Example
generator client {
provider = "prisma-client-js"
}
generator nexusPrisma {
// This is a temporary name, soon will be just "nexus-prisma" (pending a change in Prisma core).
provider = "nexus-prisma-2"
}
/// This is a user!
model User {
/// This is an id!
id String @id
}
$ prisma generate
import { User } from 'nexus-prisma'
import { makeSchema, objectType } from 'nexus'
export const schema = makeSchema({
types: [
objectType({
name: User.$name
description: User.$description
definition(t) {
t.field(User.id.name, User.id)
}
})
]
})
Features
Note: ⛑ The following use abbreviated examples that skip a complete setup of passing Nexus type definition to Nexus makeSchema
. If you are new to Nexus, Consider reading the official Nexus tutorial before jumping into Nexus Prisma.
Type-safe seamless generated library code
Following the same philosophy as Prisma Client, Nexus Prisma uses generation to create an API that feels tailor made for your project.
model User {
id String @id
}
import { User } from 'nexus-prisma'
import { objectType } from 'nexus'
objectType({
name: User.$name
description: User.$description
definition(t) {
t.field(User.id.name, {
type: User.id.type,
description: User.id.description
})
}
})
Prisma ID field to GraphQL ID scalar type mapping
All @id
fields in your Prisma Schema get projected as ID
types, not String
types.
model User {
id String @id
}
import { User } from 'nexus-prisma'
import { objectType } from 'nexus'
objectType({
name: User.$name
description: User.$description
definition(t) {
t.field(User.id.name, User.id)
}
})
type User {
id: ID
}
Prisma Schema model & field documentation re-use
GraphQL documentation for your API clients
/// A user.
model User {
/// A stable identifier to find users by.
id String @id
}
import { User } from 'nexus-prisma'
import { objectType } from 'nexus'
User.$description
User.id.description
objectType({
name: User.$name
description: User.$description
definition(t) {
t.field(User.id.name, User.id)
}
})
"""
A user.
"""
type User {
"""
A stable identifier to find users by.
"""
id: ID
}
Internal JSDoc for your team
/// A user.
model User {
/// A stable identifier to find users by.
id String @id
}
import { User } from 'nexus-prisma'
User
User.id
Refined DX
These are finer points that aren't perhaps worth a top-level point but none the less add up toward a thoughtful developer experience.
Default JSDoc Prompts
Fields and models that you do not document will result in a helpful default JSDoc that teaches you about this.
Runtime Proxy
When your project is in a state where the generated Nexus Prisma part is missing (new repo clone, reinstalled deps, etc.) Nexus Prisma gives you a default runtime export named PleaseRunPrismaGenerate
and will error with a clear message.
Opt-outable friendly runtime peer dependency checks
When nexus-prisma
is imported it will validate that your project has peer dependencies setup correctly.
If a peer dependenvy is not installed it nexus-prisma
will log an error and then exit 1. If its version does not satify the range supported by the current version of nexus-prisma
that you have installed, then a warning will be logged. If you want to opt-out of this validation then set an envar as follows:
NO_PEER_DEPENDENCY_CHECK=true|1
PEER_DEPENDENCY_CHECK=false|0