Skip to content

Prisma not combining queries for GraphQL server, leading to N+1 issues #5274

@dickfickling

Description

@dickfickling

Bug description

I've created a small server running Prisma, Apollo, and type-graphql with a few entities. A simple fetch that traverses multiple edges on the graph causes N+1 db queries when I'd have expected Prisma to combine them.

How to reproduce

Check out https://github.com/dickfickling/prisma-n1 for a repro. I'm not sure whether the culprit is within prisma, type-graphql, typegraphql-prisma, or somewhere in the way i'm structuring my code. Regardless if you install deps and run npm run test in this example, you'll see the test creates 10 users with 10 posts each, and then fetches the feed, which should return all 100 posts and their attached users. The test passes, but you see a massive number of queries logged.

There's a github action workflow that demonstrates this as well.

Expected behavior

I'd expect a constant number of db queries to run

Prisma information

prisma 2

Environment & setup

  • OS: debian/ubuntu
  • Database: mysql
  • Node.js version: reproduced on 14 and 15
  • Prisma version: 2.15.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions