Usage
-
Install dependencies
npm add nexus-prisma nexus graphql @prisma/client npm add --dev prisma💡nexusgraphqland@prisma/clientare peer dependencies.prismais for the Prisma CLI which you'll probably want during development.💡If you use
nexus@=<1.0then you must uset.field(<NAME>, <CONFIG>)instead oft.field(<CONFIG>). The Nexus Prisma docs assume the latter form. -
Add a
nexus-prismagenerator block to your Prisma Schema. -
Run
prisma generatein your terminal. -
Import models from
nexus-prismaand then pass them to your Nexus type definition and field definition configurations. In this way you will be effectively projecting models from your data layer into GraphQL types in your API layer.
Example
generator client {
provider = "prisma-client-js"
}
generator nexusPrisma {
provider = "nexus-prisma"
}
/// 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)
// t.field(User.id.name, User.id) <-- For nexus@=<1.0 users
}
})
]
})Last updated on August 17, 2022