Usage
Install dependencies
npm add nexus-prisma nexus graphql @prisma/client npm add --dev prisma
nexus
graphql
and@prisma/client
are peer dependencies.prisma
is for the Prisma CLI which you'll probably want during development.If you use
nexus@=<1.0
then you must uset.field(<NAME>, <CONFIG>)
instead oft.field(<CONFIG>)
. The Nexus Prisma docs assume the latter form.Add a
nexus-prisma
generator block to your Prisma Schema.Run
prisma generate
in your terminal.Import models from
nexus-prisma
and 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 } }) ]})