Are these two same thing #82
Replies: 1 comment
-
From what I have seen they are indeed the same thing with a minor difference. With nexus-prisma you don't need to specify that the field is a list with t.field(Device.favoriteDevices.name, Device.favoriteDevices); and if you are using t.field(Device.favoriteDevices); For a more complete example consider this really simple user/post schema model User {
id Int @id @default(autoincrement())
name String
posts Post[]?
}
model Post {
id Int @id @default(autoincrement())
title String
author User @relation(fields: [authorId], references: [id])
authorId Int
} The related API schema would look something like this import { User, Post } from 'nexus-prisma'
const Query = queryType({
definition(t) {
t.nonNull.list.nonNull.field('users', {
type: 'User',
resolve(_parent, _args, ctx) {
return ctx.prisma.user.findMany()
},
})
},
})
const User = objectType({
name: User.$name,
description: User.$description,
definition(t) {
t.field(User.id);
t.field(User.name);
t.field(User.posts);
},
})
const Post = objectType({
name: Post.$name,
description: Post.$description,
definition(t) {
t.field(Post.id)
t.field(Post.title)
t.field(Post.author)
},
}) Note that in the This is an example I took from the features section at nexus.prisma.io and slightly modified. You can find more information on the plugin's usage in the official documentation, and if you have any more questions feel free to ask. |
Beta Was this translation helpful? Give feedback.
-
I am little confused do I even need to write relation resolvers with new nexus-prisma plugin?
Are these two same?
Beta Was this translation helpful? Give feedback.
All reactions