YeonHoPark
02/08/2021, 12:35 AMnikolasburk
every
instead of some
inside the resolver. But I'm not sure if that's what you're looking for? Also, this docs page might be relevant for you šYeonHoPark
02/09/2021, 1:02 AMYeonHoPark
02/09/2021, 1:02 AMYeonHoPark
02/09/2021, 1:04 AMYeonHoPark
02/09/2021, 1:05 AMAlex Ruheni
User
and Post
object types in the code that is on the right in the first screenshot. Could you kindly clarify why you've commented it out?YeonHoPark
02/09/2021, 7:51 AMAlex Ruheni
User
object Type, you can resolve your posts
field with this:
const User = objectType({
name: 'User',
definition(t) {
t.model.id()
t.model.name()
t.model.age()
t.list.field("posts", {
type: "Post",
resolve: (parent, _args, ctx) => {
return ctx.prisma.user.findUnique({
where: {
id: parent.id
}
}).posts({
where: {
isActive: true
}
})
}
})
},
})
And in your Query
type, you can make the following modification:
const Query = extendType({
type: 'Query',
definition(t) {
t.list.field('nexusGetUser', {
type: "User",
resolve: async (_parent, args, ctx) => {
const result = await ctx.prisma.user.findMany()
return result
}
})
},
})
In the above solution, the posts
field has been resolved manually on the User
object type.
I made the assumption that you wanted to filter a user's whose posts isActive
field is set to true
. If this is not the case, let me know š
and btw, we are currently not actively maintaining nexus-prisma-plugin. You can find follow the discussion on GitHub.YeonHoPark
02/10/2021, 12:10 AMYeonHoPark
02/10/2021, 1:02 AMYeonHoPark
02/10/2021, 1:03 AMnikolasburk
User
that's implemented in this case which will resolve the posts
relation. If you want to understand more about this, I'd recommend this article: https://www.prisma.io/blog/graphql-server-basics-the-schema-ac5e2950214eYeonHoPark
02/10/2021, 8:53 AM