I'm looking at this prisma2 example: <https://gith...
# orm-help
l
I'm looking at this prisma2 example: https://github.com/prisma/prisma-examples/tree/master/typescript/graphql-apollo-server It has a model like this:
Copy code
model User {
  id    Int     @default(autoincrement()) @id
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int     @default(autoincrement()) @id
  authorId  Int?
  content   String?
  published Boolean @default(false)
  title     String
  author    User?   @relation(fields: [authorId], references: [id])
}
If i run this query:
Copy code
query {
   filterPosts{
    id
    title
    author {
      name
    }
  }
}
Why does prisma run 3 SQL queries?
Copy code
SELECT "public"."Post"."id", "public"."Post"."authorId", "public"."Post"."content", "public"."Post"."published", "public"."Post"."title" FROM "public"."Post" WHERE 1=1 OFFSET 0;

SELECT "public"."Post"."id", "public"."Post"."authorId" FROM "public"."Post" WHERE "public"."Post"."id" IN (1,2,3,4,5,6) OFFSET 0;

SELECT "public"."User"."id", "public"."User"."email", "public"."User"."name" FROM "public"."User" WHERE "public"."User"."id" IN (1, 2) OFFSET 0
The second query seems unnecessary?
a
@Lars-Jørgen Kristiansen Using my example https://github.com/AhmedElywa/prisma-tools/tree/master/examples/apollo-nexus-schema Have this query
Copy code
{
  findManyUser {
    id
    posts {
      id
      comments{
        id
      }
    }
  }
}
this is query log
Copy code
prisma:query SELECT `dev`.`User`.`id` FROM `dev`.`User` WHERE 1=1 LIMIT ? OFFSET ?
prisma:query SELECT `dev`.`Post`.`id`, `dev`.`Post`.`authorId` FROM `dev`.`Post` WHERE `dev`.`Post`.`authorId` IN (?,?) LIMIT ? OFFSET ?
prisma:query SELECT `dev`.`Comment`.`id`, `dev`.`Comment`.`postId` FROM `dev`.`Comment` WHERE `dev`.`Comment`.`postId` IN (?,?,?,?,?,?) LIMIT ? OFFSET ?
The problem not in Prisma client the issue in prisma-nexus plugin
And if you looked to my query log will see db select is same what i request in my graphql query not select all model fields
l
Thanks! Is this a known issue, or a limitation of the prisma nexus plugin?
r
Hey @Lars-Jørgen Kristiansen 👋 Nexus does request all the fields by default This issue is somewhat related to that.
l
Thanks, but why the extra query?
r
Could you share your Prisma Client method you're calling? Would it be something like this:
Copy code
await prisma.post.findMany({
    include: {
      author: true,
    },
  })
I had the same result with exposing
t.crud.posts
too
r
Yes that's being caused by Nexus. If you run the
prisma
client call directly, it will produce only two queries.
👍 1
Let me get back to you on the reason why this occurs in Nexus.
l
Thanks 🙏
a
@Ryan it’s not from Nexus it’s from nexus-prisma plugin i use prisma with my tools and have it very good
👍 2