Does anyone who knows how to resolve this issue ?:...
# orm-help
y
Does anyone who knows how to resolve this issue ?šŸ™
n
Hey @YeonHoPark šŸ‘‹ can you share the data model and the exact query you want to to send? I think in the case of the issue you linked, the query should use
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 šŸ™‚
y
Hi !! Thansk for the answer 😺 I am confused by this problem. I tested two cases.
1. nexus, nexus-plugin-prisma + prisma 2. raw graphql type, resolver…. + prisma
1 case : The results ​​are different on the server and client 2 case : The results are the same on the server and client We desperately want the result of the second case šŸ”„šŸ”„šŸ”„(applied 1 case specā€¦šŸ˜­ ) I’ll be waiting for your answer šŸ™
a
Hi @YeonHoPark šŸ‘‹šŸ¾ I see that you have commented out the
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?
y
that is just show ā€œdata modelā€ to @nikolasburk, he asked to show the ā€œdata modelā€ Look at the above,
šŸ‘ 1
a
Here's a possible fix to your issue: In your
User
object Type, you can resolve your
posts
field with this:
Copy code
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:
Copy code
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.
šŸ‘Œ 2
y
that’s cool !! I just tested above code, it works as expected. be a little similar here by the way, code that you wrote is in case of all query. what I want to is in case of ā€œrawGraphqlGetUserā€, ā€œnexusGetUserā€ so, I checked resolver method parameter(parent, args, ctx, info) whether resolver name(rawGraphqlGetUser,nexusGetUser) support or not. but I couldn’t find it. how can I find resolver name in resolver method ? I know that issue and appreciate your effort šŸ‘
While solving this probile, I discovered interesting things. even though query user without ā€œinclude posts : trueā€, I still got posts(only client). I think it is mean to there are posts in front, but not in server how is this possible ? it is just nexus feature for rapid development(ā€œhey you don’t need to care of related model, I automatically added relation modelā€)?
n
@YeonHoPark this is a "GraphQL feature" and has nothing to do particularly with Nexus or Prisma. It's because of the type resolver for
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-ac5e2950214e
y
Thanks, I’ll try to understand it If I don’t understand, I’ll ask again šŸ‘šŸ˜ƒ