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:
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'34export 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:
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:
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:
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:
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:
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:
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:
1npm install graphql-iso-date
If you're using TypeScript, you should also install the types of that package:
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'45export 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'34export const schema = makeSchema({5 types: [6 Query,7 Mutation,8 // ... other types+ DateTime10 ]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:
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'34export const Role = enumType({5 name: 'Role',6 members: ['USER', 'ADMIN']7})89export 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'34export const schema = makeSchema({5 types: [6 Query,7 Mutation,8 User,9 // ... other types+ Role11 ]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:
1const User = objectType({2 name: 'User',3 definition(t) {4 t.model.id()5 t.model.name()6 t.model.profile()7 },8})910const 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})1617const 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:
- Use Prisma Client's
findUnique
query for the model that you currently define, in this case:prisma.profile.findUnique(...)
prisma.user.findUnique(...)
- In both cases, the
id
of the target record is carried in the first resolver argument, calledparent
in the code above. - 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:
1const User = objectType({2 name: 'User',3 definition(t) {4 t.model.id()5 t.model.name()6 t.model.posts()7 },8})910const 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})1617const 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:
- Use Prisma Client's
findUnique
query for the model that you currently define, in this case:prisma.post.findUnique(...)
prisma.user.findUnique(...)
- In both cases, the
id
of the target record is carried in the first resolver argument, calledparent
in the code above. - 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:
1const Post = objectType({2 name: 'Post',3 definition(t) {4 t.model.id()5 t.model.title()6 t.model.categories()7 },8})910const 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})1617const 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:
- Use Prisma Client's
findUnique
query for the model that you currently define, in this case:prisma.post.findUnique(...)
prisma.category.findUnique(...)
- In both cases, the
id
of the target record is carried in the first resolver argument, calledparent
in the code above. - 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:
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: true10 })11 },12})1314const 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: String4 posts(5 after: PostWhereUniqueInput,6 before: PostWhereUniqueInput,7 first: Int,8 last: Int,9 orderBy: [PostOrderByInput!],10 where: PostWhereInput11 ): [Post!]!12}1314type 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: UserWhereInput6 authorId: IntNullableFilter7 id: IntFilter8 title: StringFilter9}1011input PostWhereUniqueInput {12 id: Int13}1415input UserWhereInput {16 AND: [UserWhereInput!]17 NOT: [UserWhereInput!]18 OR: [UserWhereInput!]19 id: IntFilter20 name: StringFilter21 posts: PostListRelationFilter22}2324input IntFilter {25 equals: Int26 gt: Int27 gte: Int28 in: [Int!]29 lt: Int30 lte: Int31 not: NestedIntFilter32 notIn: [Int!]33}3435input IntNullableFilter {36 equals: Int37 gt: Int38 gte: Int39 in: [Int!]40 lt: Int41 lte: Int42 not: NestedIntNullableFilter43 notIn: [Int!]44}4546input NestedIntFilter {47 equals: Int48 gt: Int49 gte: Int50 in: [Int!]51 lt: Int52 lte: Int53 not: NestedIntFilter54 notIn: [Int!]55}5657input NestedIntNullableFilter {58 equals: Int59 gt: Int60 gte: Int61 in: [Int!]62 lt: Int63 lte: Int64 not: NestedIntNullableFilter65 notIn: [Int!]66}6768input StringFilter {69 contains: String70 endsWith: String71 equals: String72 gt: String73 gte: String74 in: [String!]75 lt: String76 lte: String77 mode: QueryMode78 not: NestedStringFilter79 notIn: [String!]80 startsWith: String81}8283input StringNullableFilter {84 contains: String85 endsWith: String86 equals: String87 gt: String88 gte: String89 in: [String!]90 lt: String91 lte: String92 not: NestedStringNullableFilter93 notIn: [String!]94 startsWith: String95}9697input NestedStringFilter {98 contains: String99 endsWith: String100 equals: String101 gt: String102 gte: String103 in: [String!]104 lt: String105 lte: String106 not: NestedStringFilter107 notIn: [String!]108 startsWith: String109}110111input PostListRelationFilter {112 every: PostWhereInput113 none: PostWhereInput114 some: PostWhereInput115}116117input PostOrderByInput {118 authorId: SortOrder119 id: SortOrder120 title: SortOrder121}122123enum SortOrder {124 asc125 desc126}
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:
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.user17 .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 || undefined28 },29 })30 },31 })32 },33})3435const SortOrder = enumType({36 name: 'SortOrder',37 members: ['asc', 'desc'],38})3940const PostOrderByInput = inputObjectType({41 name: 'PostOrderByInput',42 definition(t) {43 t.field('title', {44 type: 'SortOrder',45 })46 },47})4849const PostWhereUniqueInput = inputObjectType({50 name: 'PostWhereUniqueInput',51 definition(t) {52 t.int('id')53 },54})5556const PostWhereInput = inputObjectType({57 name: 'PostWhereInput',58 definition(t) {59 t.int('id')60 t.field('title', { type: 'StringFilter' })61 },62})6364const 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 String4 content String?5 authorId Int?6 published Boolean @default(false)7 author User? @relation(fields: [authorId], references: [id])8}910model User {11 id Int @id @default(autoincrement())12 name String?13 email String @unique14 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 post12 }13 })14 }15});
Queries
posts
Assuming you have exposed the following resolver from your Prisma schema:
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})1415const 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:
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:
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: UserCreateNestedOneWithoutPostsInput3 content: String4 published: Boolean5 title: String!6}78input UserCreateNestedOneWithoutPostsInput {9 connect: UserWhereUniqueInput10 connectOrCreate: UserCreateOrConnectWithoutPostsInput11 create: UserCreateWithoutPostsInput12}1314input UserWhereUniqueInput {15 email: String16 id: Int17}1819input UserCreateOrConnectWithoutPostsInput {20 create: UserCreateWithoutPostsInput!21 where: UserWhereUniqueInput!22}2324input UserCreateWithoutPostsInput {25 email: String!26 name: String27}
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})1112const 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});2122const 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});3031const UserWhereUniqueInput = inputObjectType({32 name: "UserWhereUniqueInput",33 definition(t) {34 t.string("email")35 t.int("id")36 }37});3839const UserCreateOrConnectWithoutPostsInput = inputObjectType({40 name: "UserCreateOrConnectWithoutPostsInput",41 definition(t) {42 t.nonNull.field("create", { type: UserCreateWithoutPostsInput })43 t.nonNull.field("where", { type: UserWhereUniqueInput })44 }45});4647const 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:
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: UserUpdateOneWithoutPostsInput3 content: NullableStringFieldUpdateOperationsInput4 published: BoolFieldUpdateOperationsInput5 title: StringFieldUpdateOperationsInput6}78input PostWhereUniqueInput {9 id: Int10}1112input UserUpdateOneWithoutPostsInput {13 connect: UserWhereUniqueInput14 connectOrCreate: UserCreateOrConnectWithoutPostsInput15 create: UserCreateWithoutPostsInput16 delete: Boolean17 disconnect: Boolean18 update: UserUpdateWithoutPostsInput19 upsert: UserUpsertWithoutPostsInput20}2122input NullableStringFieldUpdateOperationsInput {23 set: String24}2526input BoolFieldUpdateOperationsInput {27 set: Boolean28}2930input StringFieldUpdateOperationsInput {31 set: String32}3334input UserUpdateWithoutPostsInput {35 email: StringFieldUpdateOperationsInput36 name: NullableStringFieldUpdateOperationsInput37}3839input 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})1213const 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});2223const PostWhereUniqueInput = inputObjectType({24 name: "PostWhereUniqueInput",25 definition(t) {26 t.int("id")27 }28});2930const 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});4243const NullableStringFieldUpdateOperationsInput = inputObjectType({44 name: "NullableStringFieldUpdateOperationsInput",45 definition(t) {46 t.string("set")47 }48});4950const BoolFieldUpdateOperationsInput = inputObjectType({51 name: "BoolFieldUpdateOperationsInput",52 definition(t) {53 t.boolean("set")54 }55});5657const StringFieldUpdateOperationsInput = inputObjectType({58 name: "StringFieldUpdateOperationsInput",59 definition(t) {60 t.string("set")61 }62});6364const UserUpdateWithoutPostsInput = inputObjectType({65 name: "UserUpdateWithoutPostsInput",66 definition(t) {67 t.field("email", { type: StringFieldUpdateOperationsInput })68 t.field("name", { type: NullableStringFieldUpdateOperationsInput })69 }70});7172const 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:
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})1213const AffectedRowsOutput = objectType({14 name: "AffectedRowsOutput",15 definition(t) {16 t.nonNull.int("count")17 }18})1920const 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:
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:
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:
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.