Hi all, I'm curious about what expectation I shou...
# orm-help
j
Hi all, I'm curious about what expectation I should have using nested reads. Should I have the expectation that a nested read would generate 1 SQL query? Or would it generate multiple queries, and I really shouldn't worry about it? For example:
Copy code
ctx.prisma.user.findUnique({
  where: {
    id: user.id,
  },
  include: {
    permissions: true
  }
})
Thanks!
r
@Jack Reed 👋 Nested reads would indeed generate an extra query to fetch the relation. Prisma currently doesn’t use joins to fetch the relations so there will be two queries in this case. You can also check the queries made by adding a log value like this:
Copy code
const prisma = new PrismaClient({
  log: ['query'],
})
j
Thanks @Ryan that is the behavior I was seeing, and wasn't sure if I should expect a join, so that helps. 👍 Do you (or anyone) know of any tooling that rolls up and aggregates query counts / time spent in DB for a GraphQL request? I've made great use of the
log: ['query']
but I now am wanting that in aggregate.
l
@Jack Reed That is a good question that I would be interested in too, although I have an inkling of some solution 🙂 Presumably some form of dedicated middleware exists for such logging, but at least using the Apollo server, you can do stuff (like logging) in lifecycle handlers to find how much time is spent (won't tell you about anything about specifics like number of actual queries at the prisma level though).