@mercurialweb/nexus-plugin-prisma
v7.1.0
Published
@mercurialweb/nexus-plugin-prisma
Downloads
863
Readme
Latest version of Prisma supported: 7.1.0+
Note: Since the Prisma team is no longer keeping this library up to date with new Prisma versions, we have forked it.
This plugin integrates Prisma into Nexus. It gives you an API you to project fields from models defined in your Prisma schema into your GraphQL API. It also gives you an API to build GraphQL root fields that allow your API clients to query and mutate data.
You can find the documentation on the Nexus website.
Requirements
This plugin requires Prisma 7+ with the new prisma-client generator:
// schema.prisma
generator client {
provider = "prisma-client"
output = "./src/generated/prisma"
}Configuration
Prisma Client Path
By default, the plugin looks for your generated Prisma Client at ./src/generated/prisma. You can customize this path:
import { nexusPrisma } from '@mercurialweb/nexus-plugin-prisma'
nexusPrisma({
inputs: {
prismaClient: './path/to/your/generated/prisma',
},
})Schema Path (Environment Variable)
If your schema.prisma file is not in the default location (prisma/schema.prisma or schema.prisma), you can specify its path using the PRISMA_SCHEMA_PATH environment variable:
PRISMA_SCHEMA_PATH=./custom/path/schema.prisma ts-node your-app.tsNew Features
Automatic Filtering for Relations
By default, all relational fields now include a where parameter allowing you to filter related records, if the underlying Prisma model supports filtering. This makes it easy to query only specific related items without additional configuration.
For example, with a User model related to Posts:
// User type with related Posts
objectType({
name: 'User',
definition(t) {
t.model.id()
t.model.name()
t.model.posts() // automatically includes where parameter for filtering
},
})This allows GraphQL queries like:
{
user(id: 1) {
posts(where: { title: { contains: "Nexus" } }) {
id
title
}
}
}You can disable this behavior by explicitly setting filtering: false when defining the field:
t.model.posts({ filtering: false })Note: If a relation doesn't have filtering capabilities in the generated Prisma client, the filtering parameter will be silently omitted rather than causing an error.
Installation
npm install @mercurialweb/nexus-plugin-prisma
# OR
yarn add @mercurialweb/nexus-plugin-prisma