Skip to content

Releases: graphql-nexus/nexus-plugin-prisma

v0.5.0

17 Oct 10:06
Compare
Choose a tag to compare

Features

Fixes

  • d59b9e8 fix: publish scalars from input types (#487)
  • 63277cc fix: only publish non-null list + list members (#452)
  • 758da5b fix: publish object types that don't map to prisma models… (#451)
  • 6551222 fix(publishing): publish dmmf objects (#441)
  • d7d59d8 fix(typegen): enum-field publishing on models (#443)
  • 827ec4e fix(deps): make @prisma/photon a prod dep
  • ec1d848 fix(typegen): delete prev file before writing next (#454)

Other

  • 7460d1b docs: intro, concepts, reference (#459)
  • b008c71 docs: show gql null args flowing into photon

BREAKING CHANGES:

  1. You will need nexus@0.12.0-beta.14

  2. ca22bb0 fix: generated publishers are now all camel-cased (#481)

    import { objectType } from 'nexus-prisma'
    
    const Query = objectType({
      name: 'Query',
      definition(t) {
    -    t.modelnames()
    -    t.modelname()
    +    t.modelName()
    +    t.modelNames()
      }
    })
  3. You now use nexus-prisma as a nexus plugin

    import { nexusPrismaPlugin } from 'nexus-prisma
    import { makeSchema } from 'nexus'
    import * as types from './types'
    
    makeSchema({
    - types: [types, nexusPrismaPlugin({ types })],
    + types,
    + plugins: [nexusPrismaPlugin()]
    })
  4. export NexusPrismaParams renamed to Options

v0.4.2

26 Sep 16:16
Compare
Choose a tag to compare

Fixes

  • An issue where tsc build would fail without skipLibCheck present is resolved.

v0.4.1

26 Sep 03:40
Compare
Choose a tag to compare

Features

  • add support for Prisma 2

BREAKING CHANGES:

  • Support for Prisma 1 has been dropped.
    See the announcement here. For now please refer to the examples folder for how an app with nexus-prisma now looks. A migration guide will be coming soon.

Migrating From 0.4 Pre-Releases

Pre-releases of 0.4 were a Prisma generator. Here's how to migrate from that.

  1. Remove generator nexus_prisma from your schema.prisma:

    - generator nexus_prisma {
    -   provider = "nexus-prisma"
    - }
  2. Install nexus-prisma

    npm install nexus-prisma
    
  3. Update how you import nexus-prisma:

    - const { nexusPrismaPlugin } = require('@generated/nexus-prisma')
    + const { nexusPrismaPlugin } = require('nexus-prisma')
    - import { nexusPrismaPlugin } from '@generated/nexus-prisma'
    + import { nexusPrismaPlugin } from 'nexus-prisma'

Migrating from 0.3.x

nexus-prisma@0.4.x now uses Prisma 2. Learn more about how to setup Prisma 2 here

NOTE: ⚠️ nexus-prisma@0.4.x is still in preview and might break at any moment. We advise not to upgrade yet if you're running in production.

  1. makePrismaSchema

    nexus-prisma is now a nexus plugin. It means we no longer use makePrismaSchema but Nexus' makeSchema function instead.

    - import { makePrismaSchema } from 'nexus-prisma'
    + import { nexusPrismaPlugin } from 'nexus-prisma'
    + import { makeSchema } from 'nexus'
      import * as types from './graphql'
    
    - const schema = makePrismaSchema({
    + const schema = makeSchema({
    -   types
    +   types: [types, nexusPrismaPlugin({ types })],
      })
  2. prismaObjectType

    This function no longer exists. Instead, use objectType from nexus.

    t.prismaFields(...) was removed in favor of two new properties: t.model & t.crud.

    NOTE: t.prismaFields(['*']) has no equivalent anymore. See #299

    For the Query & Mutation types

    t.crud is available only on the Query and Mutation type. It replaces t.prismaFields(...)

    - import { prismaObjectType } from 'nexus-prisma'
    + import { objectType } from 'nexus'
    
    - const Query = prismaObjectType({
    + const Query = objectType({
        name: 'Query',
        definition(t) {
    -      t.prismaFields(['user', 'users'])
    +      t.crud.user()
    +      t.crud.users({ filtering: true, ordering: true })
        }
    })

    For types that maps to Prisma model

    t.model becomes available. It replaces t.prismaFields(...).

    NOTE: You can now have object types that have different names that your prisma models. If that's the case, use t.model('<PrismaModelName>').someField().

    - import { prismaObjectType } from 'nexus-prisma'
    + import { objectType } from 'nexus'
    
    - const User = prismaObjectType({
    + const User = objectType({
        name: 'User',
        definition(t) {
    -      t.prismaFields(['id', 'name', 'age'])
    +      t.model.id()
    +      t.model.name()
    +      t.model.age()
        }
    })
  3. prismaInputObjectType

    This function no longer exists and don't have equivalent yet. See #477

  4. prismaExtendType

    This function no longer exists and don't have equivalent yet.

  5. t.prismaType

    This property no longer exists and don't have equivalent yet. See #303

v0.3.7

26 Apr 13:49
Compare
Choose a tag to compare
  • Add better support for subscriptions.
  • Rollback nexus-prisma-generate: --output option needs to be inputted from the root path of the project again instead of relatively

WARNING:

Susbcriptions are still not supported through t.prismaFields(). They are however better supported with nexus + the prisma-client without having to do the following: graphql-nexus/nexus#86 (comment)

Guide

Given the following datamodel:

type User {
  id: ID! @id
  name: String!
}
  1. Use the nexus' subscriptionField method.
export const UserSubscription = subscriptionField('user', {
  type: 'UserSubscriptionPayload', // Use prisma's subscription type as output
  subscribe(root, args, ctx) {
    return ctx.prisma.$subscribe.user() as any // Cast to any because of typings mismatch
  },
  resolve(payload) {
    return payload
  },
})
  1. UserSubscriptionPayload is Prisma's graphql output type for subscriptions. For a Post type, it would have been PostSubscriptionPayload.

This is what the type actually looks like:

type UserSubscriptionPayload {
  mutation: MutationType!
  node: User
  previousValues: UserPreviousValues
  updatedFields: [String!]
}

type UserPreviousValues {
  createdAt: DateTime!
  email: String!
  gender: GENDER!
  id: ID!
  name: String
  updatedAt: DateTime!
}

enum MutationType {
  CREATED
  DELETED
  UPDATED
}

Because nexus-prisma automatically look for missing types in Prisma's GraphQL schema, all these types will magically be imported for you under the hood by simply referencing UserSubscriptionPayload.

  1. There's currently still a mismatch between prisma's typings and nexus' ones. For now, please cast prisma.$subscribe.user() to any. graphql-nexus/nexus#120 should be merged soon and will fix that problem

  2. Don't forget to export export const Something = subscriptionField into makePrismaSchema.types property

  3. Enjoy 🙏

v0.3.6

26 Apr 10:09
Compare
Choose a tag to compare

nexus-prisma

  • Fixed enums fetched twice (9fd481e)

nexus-prisma-generate

  • BREAKING: Consolidated file paths with the prisma-client. You should now use relative path for the --output option (instead of relative to the root of project as before)
  • Add --project option to point to a prisma.yml file in cases where we cannot find it automatically

v0.3.5

11 Mar 19:21
Compare
Choose a tag to compare
  • Update nexus@0.11.2
  • Fixes #199

v0.3.4

02 Mar 14:46
55c39fb
Compare
Choose a tag to compare
  • (BREAKING) Fixes bug with embedded types (when using mongo)
    • This required adding an embeddedTypes property to the generated datamodelInfo
  • (BREAKING): Remove Query.node field from generated API (and from the typings)
  • Fixes nexus-prisma-generate wrongly resolving prisma-client path when omitting --client option

Please, re-run nexus-prisma-generate to fix the breaking changes

v0.3.3

23 Feb 14:48
Compare
Choose a tag to compare
  • Update nexus@0.9.17 and unpin nexus version
  • Update other dependencies

v0.3.2

21 Feb 16:34
Compare
Choose a tag to compare
  • Make nexus-prisma-generate --client option optional. If no --client option is provided, the path will be resolved from the prisma.yml file
  • (BREAKING) Add clientPath property to datamodelInfo. Re-run nexus-prisma-generate