How to improve resolver performance?
If we log every SQL query hitting our database when we run the GQL request in Figure 14.4, we will count an impressive amount of 18 queries! To do so, you can update the SQLite plugin configuration to the following:
const app = Fastify({ logger: { level: 'trace' } }) await app.register(require('fastify-sqlite'), { verbose: true, promiseApi: true })
With the new configuration, you will be able to see all the SQL executions that have been run during the resolution of the GQL request, and you will see a lot of duplicated queries too:
Figure 14.5 – All SQL queries run by the family resolver
This issue is called the N+1 problem, which ruins the service performance and wastes many server resources. For sure, a GraphQL server aims to provide simplicity over complexity. It deprecates the writing of big SQL queries...