Plugins / Prisma

Removing nexus-plugin-prisma from your project

Overview

This page describes how you can remove the nexus-plugin-prisma from your GraphQL schema implementation and only use plain Nexus.

Note: The Prisma team is currently rewriting the plugin to make it maintainable longterm.

Removing the plugin from your project

Uninstall the npm package

Nexus You can remove the npm package from your project using the following command:

npm
Yarn
1npm uninstall nexus-plugin-prisma

Remove the plugin from plugins in makeSchema

You can remove the plugin from your project by removing the nexusPrisma() function call from the plugins section inside makeSchema:

1import { makeSchema } from 'nexus'
-import { nexusPrisma } from 'nexus-plugin-prisma'
3
4export const schema = makeSchema({
5 types: [Query, Mutation, Post, User],
- plugins: [nexusPrisma({ experimentalCRUD: true })],
7 outputs: {
8 schema: __dirname + '/../schema.graphql',
9 typegen: __dirname + '/generated/nexus.ts',
10 },
11 sourceTypes: {
12 modules: [
13 {
14 module: '@prisma/client',
15 alias: 'prisma',
16 },
17 ],
18 },
19})

Using the SDL Converter

Nexus and nexus-plugin-prisma generates and emits GraphQL types into a .graphql file in your project. Copy and paste the generated types into the SDL Converter to convert your existing SDL into Nexus code.

Migrating from t.model() to plain Nexus

t.model() is a function that's exposed by the nexus-plugin-prisma which allows you to project the field of a Prisma model to your GraphQL API inside of an objectType definition.

This section explains how you can replace your calls to t.model() with the plain Nexus API.

String

Assume you currently project the following String field via t.model() from Prisma to GraphQL:

Nexus type
Prisma model
GraphQL type
1const User = objectType({
2 name: 'User',
3 definition(t) {
4 t.model.id()
5 t.model.name()
6 },
7})

The field can be migrated to plain Nexus using the following change:

1const User = objectType({
2 name: 'User',
3 definition(t) {
4 t.nonNull.int('id')
5 t.nonNull.string('name')
6 },
7})

Note that Nexus field definitions inside objectType are nullable by default, so you have to be explicit about making the field required by adding the nonNull operator to the definition.

Int

Assume you currently project the following Int field via t.model() from Prisma to GraphQL:

Nexus type
Prisma model
GraphQL type
1const Post = objectType({
2 name: 'Post',
3 definition(t) {
4 t.model.id()
5 t.model.viewCount()
6 },
7})

The field can be migrated to plain Nexus using the following change:

1const Post = objectType({
2 name: 'Post',
3 definition(t) {
4 t.nonNull.int('id')
5 t.nonNull.int('viewCount')
6 },
7})

Note that Nexus field definitions inside objectType are nullable by default, so you have to be explicit about making the field required by adding the nonNull operator to the definition.

Float

Assume you currently project the following Float field via t.model() from Prisma to GraphQL:

Nexus type
Prisma model
GraphQL type
1const Post = objectType({
2 name: 'Post',
3 definition(t) {
4 t.model.id()
5 t.model.rating()
6 },
7})

The field can be migrated to plain Nexus using the following change:

1const Post = objectType({
2 name: 'Post',
3 definition(t) {
4 t.nonNull.int('id')
5 t.nonNull.float('rating')
6 },
7})

Note that Nexus field definitions inside objectType are nullable by default, so you have to be explicit about making the field required by adding the nonNull operator to the definition.

Boolean

Assume you currently project the following Boolean field via t.model() from Prisma to GraphQL:

Nexus type
Prisma model
GraphQL type
1const Post = objectType({
2 name: 'Post',
3 definition(t) {
4 t.model.id()
5 t.model.published()
6 },
7})

The field can be migrated to plain Nexus using the following change:

1const Post = objectType({
2 name: 'Post',
3 definition(t) {
4 t.nonNull.int('id')
5 t.nonNull.boolean('published')
6 },
7})

Note that Nexus field definitions inside objectType are nullable by default, so you have to be explicit about making the field required by adding the nonNull operator to the definition.

Json

Assume you currently project the following Json field via t.model() from Prisma to GraphQL:

Nexus type
Prisma model
GraphQL type
1const Post = objectType({
2 name: 'Post',
3 definition(t) {
4 t.model.id()
5 t.model.jsonData()
6 },
7})

The field can be migrated to plain Nexus using the following change:

1const Post = objectType({
2 name: 'Post',
3 definition(t) {
4 t.nonNull.int('id')
5 t.nonNull.field('jsonData', {
6 type: 'Json'
7 })
8 },
9})

Note that Nexus field definitions inside objectType are nullable by default, so you have to be explicit about making the field required by adding the nonNull operator to the definition.

DateTime

Assume you currently project the following DateTime fields via t.model() from Prisma to GraphQL:

Nexus type
Prisma model
GraphQL type
1const Post = objectType({
2 name: 'Post',
3 definition(t) {
4 t.model.id()
5 t.model.createdAt()
6 t.model.updatedAt()
7},
8})

The DateTime type is not natively supported by GraphQL (nor by Nexus), so you need to first add it to your GraphQL schema. You can use the standard ISO date implementation for GraphQL scalars from the graphql-iso-date npm package.

First, add the package to your project:

npm
Yarn
1npm install graphql-iso-date

If you're using TypeScript, you should also install the types of that package:

npm
Yarn
1npm install @types/graphql-iso-date --save-dev

Next, you need to add the DateTime type to your GraphQL schema using the Nexus API:

1// e.g. in `src/types/DateTime.ts`
2import { GraphQLDateTime } from 'graphql-iso-date'
3import { asNexusMethod } from 'nexus'
4
5export const DateTime = asNexusMethod(GraphQLDateTime, 'date')

To make it available via GraphQL, you can now add it to Nexu's makeSchema function:

1// e.g. in `src/schema.ts`
2import { DateTime } from './types/DateTime'
3
4export const schema = makeSchema({
5 types: [
6 Query,
7 Mutation,
8 // ... other types
+ DateTime
10 ]
11})

The fields can now be migrated to plain Nexus using the following change:

1const Post = objectType({
2 name: 'Post',
3 definition(t) {
4 t.nonNull.int('id')
5 t.nonNull.field('createdAt', {
6 type: 'DateTime'
7 })
8 t.nonNull.field('updatedAt', {
9 type: 'DateTime'
10 })
11 },
12})

Note that Nexus field definitions inside objectType are nullable by default, so you have to be explicit about making the field required by adding the nonNull operator to the definition.

enum

Assume you currently project the following enum field via t.model() from Prisma to GraphQL:

Nexus type
Prisma model
GraphQL type
1const User = objectType({
2 name: 'User',
3 definition(t) {
4 t.model.id()
5 t.model.role()
6 },
7})

The field can be migrated to plain Nexus using the following change:

1// e.g. in `src/types/User.ts`
2import { objectType, enumType } from 'nexus'
3
4export const Role = enumType({
5 name: 'Role',
6 members: ['USER', 'ADMIN']
7})
8
9export const User = objectType({
10 name: 'User',
11 definition(t) {
12 t.nonNull.int('id')
13 t.nonNull.field('role', {
14 type: 'Role'
15 })
16 }
17}

Note that Nexus field definitions inside objectType are nullable by default, so you have to be explicit about making the field required by adding the nonNull operator to the definition.

You also need to make sure the Role type is added to your GraphQL schema by passing it to Nexus' makeSchema function:

1// e.g. in `src/schema.ts`
2import { Role } from './types/User.ts'
3
4export const schema = makeSchema({
5 types: [
6 Query,
7 Mutation,
8 User,
9 // ... other types
+ Role
11 ]
12})

Relation fields

Using t.model() automatically resolves relation fields from the Prisma schema in your GraphQL API implementation. When migrating away from t.model(), you need to manually resolve relation fields.

Note that there's a clear pattern for implementing the resolvers by using the first GraphQL resolver argument, typically called parent or root. The following sections explain this pattern and show how to migrate 1-1, 1-n and m-n relations from t.model() to plain Nexus.

Note: If you want to learn more about the underlying mechanics of resolving relations in GraphQL, check out this article: GraphQL Server Basics: GraphQL Schemas, TypeDefs & Resolvers Explained

1-1 relations

Assume you currently project the following relation fields via t.model() from Prisma to GraphQL:

Nexus types
Prisma models
GraphQL types
1const User = objectType({
2 name: 'User',
3 definition(t) {
4 t.model.id()
5 t.model.name()
6 t.model.profile()
7 },
8})
9
10const Profile = objectType({
11 name: 'Profile',
12 definition(t) {
13 t.model.id()
14 t.model.bio()
15 t.model.user()
16 },
17})

The fields can be migrated to plain Nexus using the following changes to resolve the relation fields manually:

1const User = objectType({
2 name: 'User',
3 definition(t) {
4 t.nonNull.int('id')
5 t.nonNull.string('name')
6 t.field('profile', {
7 type: 'Profile',
8 resolve: (parent, _, context) => {
9 return context.prisma.user.findUnique({
10 where: { id: parent.id }
11 }).profile()
12 }
13 })
14 },
15})
16
17const Profile = objectType({
18 name: 'Profile',
19 definition(t) {
20 t.nonNull.int('id')
21 t.nonNull.string('bio')
22 t.nonNull.field('user', {
23 type: 'User',
24 resolve: (parent, _, context) => {
25 return context.prisma.profile.findUnique({
26 where: { id: parent.id }
27 }).user()
28 }
29 })
30 },
31})

Note that Nexus field definitions inside objectType are nullable by default, so you have to be explicit about making the field required by adding the nonNull operator to the definition.

The pattern for resolving the relation is:

  1. Use Prisma Client's findUnique query for the model that you currently define, in this case:
    • prisma.profile.findUnique(...)
    • prisma.user.findUnique(...)
  2. In both cases, the id of the target record is carried in the first resolver argument, called parent in the code above.
  3. Use Prisma Client's fluent API to retrieve the target relation of the returned record:
    • prisma.profile.findUnique(...).user()
    • prisma.user.findUnique(...).profile()

1-n relations

Assume you currently project the following relation fields via t.model() from Prisma to GraphQL:

Nexus types
Prisma models
GraphQL types
1const User = objectType({
2 name: 'User',
3 definition(t) {
4 t.model.id()
5 t.model.name()
6 t.model.posts()
7 },
8})
9
10const Post = objectType({
11 name: 'Post',
12 definition(t) {
13 t.model.id()
14 t.model.title()
15 t.model.author()
16 },
17})

The fields can be migrated to plain Nexus using the following changes to resolve the relation fields manually:

1const User = objectType({
2 name: 'User',
3 definition(t) {
4 t.nonNull.int('id')
5 t.nonNull.string('name')
6 t.nonNull.list.nonNull.field('posts', {
7 type: 'Post',
8 resolve: (parent, _, context) => {
9 return context.prisma.user.findUnique({
10 where: { id: parent.id }
11 }).posts()
12 }
13 })
14 },
15})
16
17const Post = objectType({
18 name: 'Post',
19 definition(t) {
20 t.nonNull.int('id')
21 t.nonNull.string('bio')
22 t.nonNull.field('author', {
23 type: 'User',
24 resolve: (parent, _, context) => {
25 return context.prisma.post.findUnique({
26 where: { id: parent.id }
27 }).author()
28 }
29 })
30 },
31})

Note that Nexus field definitions inside objectType are nullable by default, so you have to be explicit about making the field required by adding the nonNull operator to the definition. In this case, you want to make the list itself and its elements required, so you have to add the nonNull operator twice. You can learn more about nullability in Nexus here.

The pattern for resolving the relation is:

  1. Use Prisma Client's findUnique query for the model that you currently define, in this case:
    • prisma.post.findUnique(...)
    • prisma.user.findUnique(...)
  2. In both cases, the id of the target record is carried in the first resolver argument, called parent in the code above.
  3. Use Prisma Client's fluent API to retrieve the target relation of the returned record:
    • prisma.post.findUnique(...).author()
    • prisma.user.findUnique(...).posts()

m-n relations

Assume you currently project the following relation fields via t.model() from Prisma to GraphQL:

Nexus types
Prisma models
GraphQL types
1const Post = objectType({
2 name: 'Post',
3 definition(t) {
4 t.model.id()
5 t.model.title()
6 t.model.categories()
7 },
8})
9
10const Category = objectType({
11 name: 'Category',
12 definition(t) {
13 t.model.id()
14 t.model.name()
15 t.model.posts()
16 },
17})
18

The fields can be migrated to plain Nexus using the following changes to resolve the relation fields manually:

1const Post = objectType({
2 name: 'Post',
3 definition(t) {
4 t.nonNull.int('id')
5 t.nonNull.string('bio')
6 t.nonNull.list.nonNull.field('categories', {
7 type: 'Category',
8 resolve: (parent, _, context) => {
9 return context.prisma.post.findUnique({
10 where: { id: parent.id }
11 }).categories()
12 }
13 })
14 },
15})
16
17const Category = objectType({
18 name: 'Category',
19 definition(t) {
20 t.nonNull.int('id')
21 t.nonNull.string('name')
22 t.nonNull.list.nonNull.field('posts', {
23 type: 'Post',
24 resolve: (parent, _, context) => {
25 return context.prisma.category.findUnique({
26 where: { id: parent.id }
27 }).posts()
28 }
29 })
30 },
31})
32

Note that Nexus field definitions inside objectType are nullable by default, so you have to be explicit about making the field required by adding the nonNull operator to the definition. In this case, you want to make the list itself and its elements required, so you have to add the nonNull operator twice. You can learn more about nullability in Nexus here.

The pattern for resolving the relation is:

  1. Use Prisma Client's findUnique query for the model that you currently define, in this case:
    • prisma.post.findUnique(...)
    • prisma.category.findUnique(...)
  2. In both cases, the id of the target record is carried in the first resolver argument, called parent in the code above.
  3. Use Prisma Client's fluent API to retrieve the target relation of the returned record:
    • prisma.post.findUnique(...).categories()
    • prisma.category.findUnique(...).posts()

Pagination, filtering, sorting

When using t.model() resolve relation fields, you can enable filtering, pagination and ordering on to-many-relations (i.e., when the relation field is specified as a list).

Consider this example:

Nexus types
Prisma models
1const User = objectType({
2 name: 'User',
3 definition(t) {
4 t.model.id()
5 t.model.name()
6 t.model.posts({
7 pagination: true,
8 filtering: true,
9 ordering: true
10 })
11 },
12})
13
14const Post = objectType({
15 name: 'Post',
16 definition(t) {
17 t.model.id()
18 t.model.title()
19 t.model.author()
20 },
21})

The following GraphQL types are generated based on the Nexus type definition above:

1type User {
2 id: Int!
3 name: String
4 posts(
5 after: PostWhereUniqueInput,
6 before: PostWhereUniqueInput,
7 first: Int,
8 last: Int,
9 orderBy: [PostOrderByInput!],
10 where: PostWhereInput
11 ): [Post!]!
12}
13
14type Post {
15 id: Int!
16 title: String!
17 author: User!
18}

The referenced PostWhereInput, PostWhereUniqueInput and PostOrderByInput types as well as the types they reference look as follows:

1input PostWhereInput {
2 AND: [PostWhereInput!]
3 NOT: [PostWhereInput!]
4 OR: [PostWhereInput!]
5 author: UserWhereInput
6 authorId: IntNullableFilter
7 id: IntFilter
8 title: StringFilter
9}
10
11input PostWhereUniqueInput {
12 id: Int
13}
14
15input UserWhereInput {
16 AND: [UserWhereInput!]
17 NOT: [UserWhereInput!]
18 OR: [UserWhereInput!]
19 id: IntFilter
20 name: StringFilter
21 posts: PostListRelationFilter
22}
23
24input IntFilter {
25 equals: Int
26 gt: Int
27 gte: Int
28 in: [Int!]
29 lt: Int
30 lte: Int
31 not: NestedIntFilter
32 notIn: [Int!]
33}
34
35input IntNullableFilter {
36 equals: Int
37 gt: Int
38 gte: Int
39 in: [Int!]
40 lt: Int
41 lte: Int
42 not: NestedIntNullableFilter
43 notIn: [Int!]
44}
45
46input NestedIntFilter {
47 equals: Int
48 gt: Int
49 gte: Int
50 in: [Int!]
51 lt: Int
52 lte: Int
53 not: NestedIntFilter
54 notIn: [Int!]
55}
56
57input NestedIntNullableFilter {
58 equals: Int
59 gt: Int
60 gte: Int
61 in: [Int!]
62 lt: Int
63 lte: Int
64 not: NestedIntNullableFilter
65 notIn: [Int!]
66}
67
68input StringFilter {
69 contains: String
70 endsWith: String
71 equals: String
72 gt: String
73 gte: String
74 in: [String!]
75 lt: String
76 lte: String
77 mode: QueryMode
78 not: NestedStringFilter
79 notIn: [String!]
80 startsWith: String
81}
82
83input StringNullableFilter {
84 contains: String
85 endsWith: String
86 equals: String
87 gt: String
88 gte: String
89 in: [String!]
90 lt: String
91 lte: String
92 not: NestedStringNullableFilter
93 notIn: [String!]
94 startsWith: String
95}
96
97input NestedStringFilter {
98 contains: String
99 endsWith: String
100 equals: String
101 gt: String
102 gte: String
103 in: [String!]
104 lt: String
105 lte: String
106 not: NestedStringFilter
107 notIn: [String!]
108 startsWith: String
109}
110
111input PostListRelationFilter {
112 every: PostWhereInput
113 none: PostWhereInput
114 some: PostWhereInput
115}
116
117input PostOrderByInput {
118 authorId: SortOrder
119 id: SortOrder
120 title: SortOrder
121}
122
123enum SortOrder {
124 asc
125 desc
126}

Note that depending on which scalar types are used on the fields of your Prisma models, there are multiple combinations of the TYPEFilter, NestedTYPEFilter, NullableTYPEFilter and NestedNullableTYPEFilter where TYPE is the name of a scalar type.

For example, in the case above, the Prisma models have fields of types Int and String so the generated types include StringFilter, NestedStringFilter, NullableStringFilter and NestedNullableStringFilter as well as IntFilter, NestedIntFilter, NullableIntFilter and NestedNullableIntFilter.

When migrating, it's not practical to try and replicate all the generated types but instead implement the concrete types and operations you actually want to expose in your API.

As an example, this guide shows how to replicate some of the generated pagination, filtering and ordering capabilities.

To implement these capabilities, you follow Nexus' approach for defining arguments for fields and using these inside of your resolver functions. Here's a version of the t.model() code from above that offers similar capabilities:

Nexus types
GraphQL types
1const User = objectType({
2 name: 'User',
3 definition(t) {
4 t.nonNull.int('id')
5 t.string('name')
6 t.nonNull.list.nonNull.field('posts', {
7 type: 'Post',
8 args: {
9 cursor: arg({ type: 'PostWhereUniqueInput' }),
10 take: intArg(),
11 skip: intArg(),
12 orderBy: arg({ type: 'PostOrderByInput' }),
13 where: arg({ type: 'PostWhereInput' }),
14 },
15 resolve: (parent, args, context) => {
16 return context.prisma.user
17 .findUnique({
18 where: { id: parent.id },
19 })
20 .posts({
21 cursor: args.cursor || undefined,
22 take: args.take || undefined,
23 skip: args.skip || undefined,
24 orderBy: args.orderBy || undefined,
25 where: {
26 id: args.where?.id || undefined,
27 title: args.where?.title || undefined
28 },
29 })
30 },
31 })
32 },
33})
34
35const SortOrder = enumType({
36 name: 'SortOrder',
37 members: ['asc', 'desc'],
38})
39
40const PostOrderByInput = inputObjectType({
41 name: 'PostOrderByInput',
42 definition(t) {
43 t.field('title', {
44 type: 'SortOrder',
45 })
46 },
47})
48
49const PostWhereUniqueInput = inputObjectType({
50 name: 'PostWhereUniqueInput',
51 definition(t) {
52 t.int('id')
53 },
54})
55
56const PostWhereInput = inputObjectType({
57 name: 'PostWhereInput',
58 definition(t) {
59 t.int('id')
60 t.field('title', { type: 'StringFilter' })
61 },
62})
63
64const StringFilter = inputObjectType({
65 name: 'StringFilter',
66 definition(t) {
67 t.string('contains')
68 t.string('endsWith')
69 t.string('equals')
70 t.string('gt')
71 t.string('gte')
72 t.list.nonNull.string('in')
73 t.string('lt')
74 t.string('lte')
75 t.list.nonNull.string('notIn')
76 t.string('startsWith')
77 },
78})

Migrating from t.crud() to plain Nexus

t.crud is an experimental feature provided by the nexus-plugin-prisma. t.crud contains configurable GraphQL Query and Mutation resolvers that allow you to use create, read, update and delete operations against your Prisma models.

This section provides instructions how you can replace your t.crud() using the plain Nexus API.

The migration guide will be based on the following example Prisma schema:

1model Post {
2 id Int @id @default(autoincrement())
3 title String
4 content String?
5 authorId Int?
6 published Boolean @default(false)
7 author User? @relation(fields: [authorId], references: [id])
8}
9
10model User {
11 id Int @id @default(autoincrement())
12 name String?
13 email String @unique
14 posts Post[]
15}

Resolvers

Queries and mutations require the resolve property to generate their appropriate responses.

This section gives an example how you can write your own resolvers for the different GraphQL operations.

Query

Here is an example query resolver:

1const Query = objectType({
2 name: 'Query',
3 definition(t) {
4 t.field('posts', {
5 type: 'Post',
6 args: { /** ... query arguments */ },
7 resolve: async (parent, args, ctx) => {
8 const posts = ctx.prisma.post.findMany({
9 where: { /** ...query PostWhereInput */ }
10 })
11 }
12 })
13 }
14})

Mutation

Here is an example of a mutation resolver:

1const Mutation = objectType({
2 name: "Mutation",
3 definition(t) {
4 t.field('createOnePost', {
5 type: Post,
6 args: { /** ...mutation arguments */ },
7 resolve: async (parent, args, context) => {
8 const post = await context.prisma.post.create({
9 data: { /** ...mutation UserCreateInput */ }
10 })
11 return post
12 }
13 })
14 }
15});

Queries

posts

Assuming you have exposed the following resolver from your Prisma schema:

Nexus types
GraphQL types
1const Query = queryType({
2 definition(t) {
3 t.crud.posts()
4 }
5})
6

The above Query can be migrated to vanilla Nexus by making the following changes:

1const Query = objectType({
2 name: "Query",
3 definition(t) {
4 t.nonNull.list.nonNull.field("posts", {
5 type: Post,
6 args: {
7 after: arg({ type: PostWhereUniqueInput }),
8 before: arg({ type: PostWhereUniqueInput }),
9 first: intArg(),
10 last: intArg(),
11 },
12 })
13})
14
15const PostWhereUniqueInput = inputObjectType({
16 name: "PostWhereUniqueInput",
17 definition(t) {
18 t.int("id")
19 }
20});

Note: Convert your existing SDL to Nexus code with the SDL Converter. Refer to the resolvers section on how to add the resolve property to your GraphQL operation.

post

Assume you have the post query available in your API:

Nexus types
GraphQL types
1const Query = queryType({
2 definition(t) {
3 t.crud.post()
4 }
5})
6

The fields can be migrated to plain Nexus by making the following changes:

1const Query = objectType({
2 name: "Query",
3 definition(t) {
4 t.field("post", {
5 type: Post,
6 args: {
7 where: arg({ type: nonNull(PostWhereUniqueInput) }),
8 },
9 })
10})

Note: Convert your existing SDL to Nexus code with the SDL Converter. Refer to the resolvers section on how to add the resolve property to your GraphQL operation.

Mutations

createOnePost

Assume the createOnePost mutation is made available in your API as follows:

Nexus types
GraphQL types
1const Mutation = mutationType({
2 definition(t) {
3 t.crud.createOnePost()
4 }
5})
6

createOnePost is dependent on a number of inputTypes that are referenced in the existing API as follows:

1input PostCreateInput {
2 author: UserCreateNestedOneWithoutPostsInput
3 content: String
4 published: Boolean
5 title: String!
6}
7
8input UserCreateNestedOneWithoutPostsInput {
9 connect: UserWhereUniqueInput
10 connectOrCreate: UserCreateOrConnectWithoutPostsInput
11 create: UserCreateWithoutPostsInput
12}
13
14input UserWhereUniqueInput {
15 email: String
16 id: Int
17}
18
19input UserCreateOrConnectWithoutPostsInput {
20 create: UserCreateWithoutPostsInput!
21 where: UserWhereUniqueInput!
22}
23
24input UserCreateWithoutPostsInput {
25 email: String!
26 name: String
27}

The Query can be migrated to plain Nexus as follows:

1const Mutation = objectType({
2 name: "Mutation",
3 definition(t) {
4 t.nonNull.field("createOnePost", {
5 type: Post,
6 args: {
7 data: arg({ type: nonNull(PostCreateInput) }),
8 },
9 })
10})
11
12const PostCreateInput = inputObjectType({
13 name: "PostCreateInput",
14 definition(t) {
15 t.field("author", { type: UserCreateNestedOneWithoutPostsInput })
16 t.string("content")
17 t.boolean("published")
18 t.nonNull.string("title")
19 }
20});
21
22const UserCreateNestedOneWithoutPostsInput = inputObjectType({
23 name: "UserCreateNestedOneWithoutPostsInput",
24 definition(t) {
25 t.field("connect", { type: UserWhereUniqueInput })
26 t.field("connectOrCreate", { type: UserCreateOrConnectWithoutPostsInput })
27 t.field("create", { type: UserCreateWithoutPostsInput })
28 }
29});
30
31const UserWhereUniqueInput = inputObjectType({
32 name: "UserWhereUniqueInput",
33 definition(t) {
34 t.string("email")
35 t.int("id")
36 }
37});
38
39const UserCreateOrConnectWithoutPostsInput = inputObjectType({
40 name: "UserCreateOrConnectWithoutPostsInput",
41 definition(t) {
42 t.nonNull.field("create", { type: UserCreateWithoutPostsInput })
43 t.nonNull.field("where", { type: UserWhereUniqueInput })
44 }
45});
46
47const UserCreateWithoutPostsInput = inputObjectType({
48 name: "UserCreateWithoutPostsInput",
49 definition(t) {
50 t.nonNull.string("email")
51 t.string("name")
52 }
53});

Note: Convert your existing SDL to Nexus code with the SDL Converter. Refer to the resolvers section on how to add the resolve property to your GraphQL operation.

updateOnePost

Assume your updateOnePost mutation is made available in your API:

Nexus types
GraphQL types
1const Mutation = mutationType({
2 definition(t) {
3 t.crud.updateOnePost()
4 }
5})
6

The referenced input types mentioned in updateOnePost mutation are as follows:

1input PostUpdateInput {
2 author: UserUpdateOneWithoutPostsInput
3 content: NullableStringFieldUpdateOperationsInput
4 published: BoolFieldUpdateOperationsInput
5 title: StringFieldUpdateOperationsInput
6}
7
8input PostWhereUniqueInput {
9 id: Int
10}
11
12input UserUpdateOneWithoutPostsInput {
13 connect: UserWhereUniqueInput
14 connectOrCreate: UserCreateOrConnectWithoutPostsInput
15 create: UserCreateWithoutPostsInput
16 delete: Boolean
17 disconnect: Boolean
18 update: UserUpdateWithoutPostsInput
19 upsert: UserUpsertWithoutPostsInput
20}
21
22input NullableStringFieldUpdateOperationsInput {
23 set: String
24}
25
26input BoolFieldUpdateOperationsInput {
27 set: Boolean
28}
29
30input StringFieldUpdateOperationsInput {
31 set: String
32}
33
34input UserUpdateWithoutPostsInput {
35 email: StringFieldUpdateOperationsInput
36 name: NullableStringFieldUpdateOperationsInput
37}
38
39input UserUpsertWithoutPostsInput {
40 create: UserCreateWithoutPostsInput!
41 update: UserUpdateWithoutPostsInput!
42}

The above can be migrated to vanilla Nexus as follows:

1const Mutation = objectType({
2 name: "Mutation",
3 definition(t) {
4 t.field("updateOnePost", {
5 type: Post,
6 args: {
7 data: arg({ type: nonNull(PostUpdateInput) }),
8 where: arg({ type: nonNull(PostWhereUniqueInput) }),
9 },
10 })
11})
12
13const PostUpdateInput = inputObjectType({
14 name: "PostUpdateInput",
15 definition(t) {
16 t.field("author", { type: UserUpdateOneWithoutPostsInput })
17 t.field("content", { type: NullableStringFieldUpdateOperationsInput })
18 t.field("published", { type: BoolFieldUpdateOperationsInput })
19 t.field("title", { type: StringFieldUpdateOperationsInput })
20 }
21});
22
23const PostWhereUniqueInput = inputObjectType({
24 name: "PostWhereUniqueInput",
25 definition(t) {
26 t.int("id")
27 }
28});
29
30const UserUpdateOneWithoutPostsInput = inputObjectType({
31 name: "UserUpdateOneWithoutPostsInput",
32 definition(t) {
33 t.field("connect", { type: UserWhereUniqueInput })
34 t.field("connectOrCreate", { type: UserCreateOrConnectWithoutPostsInput })
35 t.field("create", { type: UserCreateWithoutPostsInput })
36 t.boolean("delete")
37 t.boolean("disconnect")
38 t.field("update", { type: UserUpdateWithoutPostsInput })
39 t.field("upsert", { type: UserUpsertWithoutPostsInput })
40 }
41});
42
43const NullableStringFieldUpdateOperationsInput = inputObjectType({
44 name: "NullableStringFieldUpdateOperationsInput",
45 definition(t) {
46 t.string("set")
47 }
48});
49
50const BoolFieldUpdateOperationsInput = inputObjectType({
51 name: "BoolFieldUpdateOperationsInput",
52 definition(t) {
53 t.boolean("set")
54 }
55});
56
57const StringFieldUpdateOperationsInput = inputObjectType({
58 name: "StringFieldUpdateOperationsInput",
59 definition(t) {
60 t.string("set")
61 }
62});
63
64const UserUpdateWithoutPostsInput = inputObjectType({
65 name: "UserUpdateWithoutPostsInput",
66 definition(t) {
67 t.field("email", { type: StringFieldUpdateOperationsInput })
68 t.field("name", { type: NullableStringFieldUpdateOperationsInput })
69 }
70});
71
72const UserUpsertWithoutPostsInput = inputObjectType({
73 name: "UserUpsertWithoutPostsInput",
74 definition(t) {
75 t.nonNull.field("create", { type: UserCreateWithoutPostsInput })
76 t.nonNull.field("update", { type: UserUpdateWithoutPostsInput })
77 }
78});

Note: Convert your existing SDL to Nexus code with the SDL Converter. Refer to the resolvers section on how to add the resolve property to your GraphQL operation.

updateManyPost

Assume you have made your updateManyPost mutation available in your API:

Nexus types
GraphQL types
1const Mutation = mutationType({
2 definition(t) {
3 t.crud.updateManyPost()
4 }
5})

You can migrate the Mutation to plain Nexus as follows:

1const Mutation = objectType({
2 name: "Mutation",
3 definition(t) {
4 t.nonNull.field("updateManyPost", {
5 type: AffectedRowsOutput,
6 args: {
7 data: arg({ type: nonNull(PostUpdateManyMutationInput) }),
8 where: arg({ type: PostWhereInput }),
9 },
10 })
11})
12
13const AffectedRowsOutput = objectType({
14 name: "AffectedRowsOutput",
15 definition(t) {
16 t.nonNull.int("count")
17 }
18})
19
20const PostUpdateManyMutationInput = inputObjectType({
21 name: "PostUpdateManyMutationInput",
22 definition(t) {
23 t.field("content", { type: NullableStringFieldUpdateOperationsInput })
24 t.field("published", { type: BoolFieldUpdateOperationsInput })
25 t.field("title", { type: StringFieldUpdateOperationsInput })
26 }
27});

Note: Convert your existing SDL to Nexus code with the SDL Converter. Refer to the resolvers section on how to add the resolve property to your GraphQL operation.

upsertOnePost

Assume the upsertOnePost GraphQL operation is available in your API:

Nexus types
GraphQL types
1const Mutation = mutationType({
2 definition(t) {
3 t.crud.upsertOnePost()
4 }
5})

The above field can be migrated to vanilla Nexus by making the following change:

1const Mutation = objectType({
2 name: "Mutation",
3 definition(t) {
4 t.nonNull.field("upsertOnePost", {
5 type: Post,
6 args: {
7 create: arg({ type: nonNull(PostCreateInput) }),
8 update: arg({ type: nonNull(PostUpdateInput) }),
9 where: arg({ type: nonNull(PostWhereUniqueInput) }),
10 },
11 })
12})

Note: Convert your existing SDL to Nexus code with the SDL Converter. Refer to the resolvers section on how to add the resolve property to your GraphQL operation.

deleteOnePost

Assume the deleteOnePost mutation is made available in your API:

Nexus types
GraphQL types
1const Mutation = mutationType({
2 definition(t) {
3 t.crud.deleteOnePost()
4 }
5})

The above Mutation can be migrated to plain Nexus by making the following changes:

1const Mutation = objectType({
2 name: "Mutation",
3 definition(t) {
4 t.field("deleteOnePost", {
5 type: Post,
6 args: {
7 where: arg({ type: nonNull(PostWhereUniqueInput) }),
8 },
9 })
10})

Note: Convert your existing SDL to Nexus code with the SDL Converter. Refer to the resolvers section on how to add the resolve property to your GraphQL operation.

deleteManyPost

Assume you have the deleteManyPost available in your API:

Nexus types
GraphQL types
1const Mutation = mutationType({
2 definition(t) {
3 t.crud.deleteManyPost()
4 }
5})

You can migrate it to plain Nexus by making the following changes:

1const Mutation = objectType({
2 name: "Mutation",
3 definition(t) {
4 t.nonNull.field("deleteManyPost", {
5 type: AffectedRowsOutput,
6 args: {
7 where: arg({ type: PostWhereInput }),
8 },
9 })
10})

Note: Convert your existing SDL to Nexus code with the SDL Converter. Refer to the resolvers section on how to add the resolve property to your GraphQL operation.

Edit this page on Github