I found this example of the GraphQL N+1 problem:
Query
# getting the top 100 reviews { top100Reviews { body author { name } } }Schema
const typeDefs = gql` type User { id: ID! name: String } type Review { id: ID! body: String author: User product: Product } type Query { top100Reviews: [Review] } `Resolvers
const resolver = { Query: { top100Reviews: () => get100Reviews(), }, Review: { author: (review) => getUser(review.authorId), }, }When we execute the following query to get the top 100 reviews and the corresponding author names, we first make a single call to retrieve 100 records of review from database and then for each review, we make another call to the database to fetch the user details given the author ID.
Can't you just remove the Review resolver and just do a simple JOIN in the get100Reviews method in the Query resolver?
I don't understand why you would create the Review resolver it causes the GraphQL N+1 problem, when you could just do a simple JOIN in the Query resolver.
Do I understand GraphQL correctly?