Skip to content

Releases: graphql-nexus/nexus-plugin-prisma

0.11.1

09 Mar 10:42
a3ee91c
Compare
Choose a tag to compare

Fixes

  • Some TS errors were preventing nexus-prisma to compile when no mutation type were defined in the schema
  • Properly handled a case where the Prisma Client could not be generated and nexus-prisma would try to import it

0.11.0

09 Mar 10:38
dd6cae3
Compare
Choose a tag to compare

Features

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

21 Feb 17:09
Compare
Choose a tag to compare

Features

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

03 Feb 10:04
8781426
Compare
Choose a tag to compare

Fixes

  • fix: supports camel-cased models (#595)

0.9.0

30 Jan 18:11
409da8c
Compare
Choose a tag to compare

Fixes

  • fix: support id fields not called id (#590)

Features

BREAKING CHANGES:

  • You must use Prisma 2 Preview 21 or higher

0.8.0

30 Jan 18:07
Compare
Choose a tag to compare

Fixes

  • fix: type error Type 'string' does not satisfy the constraint (#586)

BREAKING CHANGES:

  • requires nexus 0.12.0-rc.9 or higher

v0.7.0

27 Jan 10:12
Compare
Choose a tag to compare

Overview

Features

  • new t.crud() option computedInputs 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

  1. Uninstall @prisma/photon and install @prisma/client
npm uninstall @prisma/photon
npm install @prisma/client
  1. Upgrade prisma2
npm install --save-dev prisma2
  1. Update generator block in schema.prisma
generator client {
-  provider = "photon"
+  provider = "prisma-client-js"
}
  1. Generate new Prisma Client
prisma2 generate
  1. 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 }
})
  1. (Optional) Update your Typescript Context type
-import { Photon } from '@prisma/photon'
+import { PrismaClient } from '@prisma/client'

export type Context {
- photon: Photon
+ prisma: PrismaClient
}
  1. (Optional) Update nexus typegenAutoConfig
import { makeSchema } from 'nexus'

makeSchema({
  typegenAutoConfig: {
    sources: [
      {
-       source: '@prisma/photon',
-       alias: 'photon',
+       source: '@prisma/client',
+       alias: 'prisma',
      }
    ]
  }
})
  1. (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

22 Nov 17:57
Compare
Choose a tag to compare

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 of nexus-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:

    1. 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.

    2. 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

07 Nov 21:13
Compare
Choose a tag to compare

Fixes

  • cfc4e72 fix(deps): add @prisma/sdk until photon drops peer dep on it
    closes #524

v0.5.1

07 Nov 18:22
Compare
Choose a tag to compare

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.