GraphQL is awesome! But one of the most annoying parts to implement a GraphQL server is solving N+1 problem.

TL;DR

Use this package  https://github.com/oney/sequelize-proxy

Dive in

In general, there are two methods to solve N+1 problem.

First method:

Parsing  info: GraphQLResolveInfo in query/mutation levels to determine what data the whole operation needs and pre-fetch all data in one single SQL query.

This is how  join-monster,  postgraphile, and  prisma do it.

One inconvenience of this method( join-monster facing) is you have to declare dependencies of fields to make pre-fetching know how to construct the one single query.

Another inconvenience of this method( postgraphile,  prisma facing) is the whole GraphQL type schema are predetermined and bound to your database schema. You can’t change your GraphQL schema.

#graphql #nodejs #database

The Easiest Way to Solve N+1 Problem on GraphQL
5.50 GEEK