Releases: graphql-nexus/nexus-plugin-prisma
0.11.1
0.11.0
Features
- Partial support for Prisma2 Preview 23
- Various bug fixes
BREAKING CHANGES:
- You must use
@prisma/client
Preview 23 or higher
Partial Prisma2 Preview 23 support
We do not support yet a lot of the new Prisma2 features. These includes:
- Models without IDs
- Composite primary keys
- Composite unique indexes / constraints
We however support the new query batching done by the Prisma Client.
0.10.0
Features
- Support for Prisma 2 Preview 22
- Support for Nexus Transition
BREAKING CHANGES:
-
You must use
@prisma/client
Preview 22 or higher -
You must use
nexus
0.12.0-rc.13
or higher. This is to support the Nexus Transition -
GraphQL API consumers will see a change schema as it concerns pagination. Take a look at the pagination docs for technical detail. Here is a before/after example:
Before:
type Query { users(where: UserWhereInput, skip: Int, after: Int, before: Int, first: Int, last: Int): [User!]! }
After:
type Query { users(where: UserWhereInput, skip: Int, after: UserWhereUniqueInput, before: UserWhereUniqueInput, first: Int, last: Int): [User!]! } input UserWhereUniqueInput { id: Int }
0.9.1
0.9.0
Fixes
- fix: support id fields not called id (#590)
Features
- Support for Prisma 2 Preview 21
BREAKING CHANGES:
- You must use Prisma 2 Preview 21 or higher
0.8.0
v0.7.0
Overview
Features
- new
t.crud()
optioncomputedInputs
by @ssalbdivad (#540) (See more about it in the highlights section) - Better error messages
BREAKING CHANGE
Add support for latest prisma2
and @prisma/photon
(renamed @prisma/client
)
To use the latest prisma2
, please uninstall @prisma/photon
and install to @prisma/client
.
You will not be able to use the latest nexus-prisma
unless you uninstall @prisma/photon
and use @prisma/client
instead
For more information about the breaking changes of the latest Prisma 2 preview, checkout the release page
Migration guide
- Uninstall
@prisma/photon
and install@prisma/client
npm uninstall @prisma/photon
npm install @prisma/client
- Upgrade
prisma2
npm install --save-dev prisma2
- Update generator block in
schema.prisma
generator client {
- provider = "photon"
+ provider = "prisma-client-js"
}
- Generate new Prisma Client
prisma2 generate
- Update the Prisma Client instance passed in your GraphQL server context
-import { Photon } from '@prisma/photon'
+import { PrismaClient } from '@prisma/client'
-const photon = new Photon()
+const prisma = new PrismaClient()
new GraphQLServer({
- context: { photon }
+ context: { prisma }
})
- (Optional) Update your Typescript
Context
type
-import { Photon } from '@prisma/photon'
+import { PrismaClient } from '@prisma/client'
export type Context {
- photon: Photon
+ prisma: PrismaClient
}
- (Optional) Update nexus
typegenAutoConfig
import { makeSchema } from 'nexus'
makeSchema({
typegenAutoConfig: {
sources: [
{
- source: '@prisma/photon',
- alias: 'photon',
+ source: '@prisma/client',
+ alias: 'prisma',
}
]
}
})
- (Optional) Update
nexus-prisma
constructor if you were not using the defaults
import { nexusPrismaPlugin } from 'nexus-prisma'
import { makeSchema } from 'nexus'
makeSchema({
plugins: [
nexusPrismaPlugin({
- photon: ctx => ctx.photon,
+ prismaClient: ctx => ctx.prisma,
- inputs: { photon: '@prisma/photon' },
+ inputs: { photon: '@prisma/client' },
})
]
})
Highlights
computedInputs
Shoutout to @ssalbdivad for doing this awesome work! 🎉
Allow clients to omit fields from mutations corresponding input type and infer the value of those fields from the resolver's params (args, context, info) at runtime when determining what to pass to Prisma Client JS.
The mutation's input type fields with a name that is in the ComputedInputs object are omitted from the GraphQL schema. This modifies one existing input type but does not add new types or remove existing types.
Most common use-cases 👇
Publish Autogenerated Mutations with Computed Input Values
mutationType({
definition(t) {
/*
Assuming our prisma model for User has a createdByBrowser field,
this removes it from the input type but ensures the value is
inferred from context and passed to Prisma Client JS.
*/
t.crud.createOneUser({
computedInputs: {
createdByBrowser: ({ args, ctx, info }) => ctx.session.browser,
},
})
},
})
Globally Remove a Field from Input Types and Infer its Value
nexusPrismaPlugin({
...other config...
/*
Remove fields named "user" from all input types. When resolving
a request whose data contains any of these types, the value is inferred
from context and passed to Prisma Client JS, even if it's nested. This is great for
creating data associated with one user's account.
*/
computedInputs: {
user: ({ args, ctx, info }) => ({
connect: {
id: ctx.userId,
},
}),
},
})
mutationType({
definition(t) {
t.crud.createOnePost()
},
})
Without computedInputs:
mutation createOnePost {
createOnePost(
data: {
title: "Automatically generate clean APIs!"
image: {
url: "https://example.com/images/prancing-unicorns"
user: { connect: { id: 1 } }
}
user: { connect: { id: 1 } }
}
)
}
With computedInputs:
mutation createOnePost {
createOnePost(
data: {
title: "Automatically generate clean APIs!"
image: { url: "https://example.com/images/prancing-unicorns" }
}
)
}
Checkout the docs for more information
v0.6.1
Overview
Features
- 68ed3cc feat: add support for latest prisma 2 (#539)
- e870ee4 feat: prevent errors if a wrong field is projected (#535)
Fixes
- ea329e4 fix: when photon import fails, show error instead of assuming
BREAKING CHANGES
-
68ed3cc feat: add support for latest prisma 2 (#539)
Your app must now depend on
@prisma/photon
. It is also now a peer dependency ofnexus-prisma
so you should get warnings that help you do the right thing. But to state it here explicitly:npm install @prisma/photon@alpha
Highlights
-
68ed3cc feat: add support for latest prisma 2 (#539)
Support for photon facade package!
-
e870ee4 feat: prevent errors if a wrong field is projected (#535)
nexus-prisma
has better support for incremental development when syncing api layer with prisma model changes.It used to be that
.crud
and.model
errors would prevent your app from booting. This hindered the inner loop of a development workflow. There should be two benefits you experience in your day-to-day now:-
You will see clear domain-specific log warnings in your terminal instead of large generic stack traces/runtime errors. NOTE the old behaviour is still the case in production, because that's what you'd want.
-
Changes to your Prisma schema often cascade to the API layer in ways that break it, requiring new mapping, type handling, etc. During development you can now still run your server while in a de-synced state, and so take care of the cascading changes incrementally.
-
v0.5.2
v0.5.1
Fixes
- Support for TypeScript 3.7
- Support for Nexus 0.12.0
- Updated examples
Notes
Support for NEXUS_SHOULD_GENERATE_ARTIFACTS
has been removed from Nexus. This may lead to instances of Property 'model' does not exist
. To remedy, you should now use NODE_ENV=development
in your generate:nexus
npm script.