- Set up the project
yarn install
- Start the server
yarn start:dev
- Go to the playground - http://localhost:3000/graphql
- Run the
productsquery:
query Products {
products {
id
direct
resolved
combined
parent
}
}10 000 products will be returned. You can adjust the number in src/products/products.mock.ts file.
Notes about fields:
idanddirectare passed directly from the REST response, no resolver involvedresolvedfield is being resolved through a resolver, but a very simple one. Just pointing to the REST field (1:1)combinedfield has a resolver that concatenates two fields (think about it as "full name" that's created from first and last name fields)parentsame asresolvedbut uses@Parent()decorator
- Run the
productsquery with just a single field case to understand its impact
In each case, I run a simple query with id and "a field". Here's the k6 command I used:
k6 run --vus 1 --duration 30s --http-debug ./performance/--CASE--.js
This is the baseline. 1353 requests in 30s:
resolved field is a 1:1 map to a field (from another service response or database). 582 requests in 30s. That's a 57% degradation in performance! Or in other words, not using a resolver is 2.3x faster.
Same as resolved but also uses @Parent decorator. 346 requests in 30s. That's a ~75% drop in performance! Or in other words, the base is 3.9x faster than a resolver that happens to use the @Parent decorator.
I used two cases here, and this time run as many requests as I could in 10 seconds to see if there were any discrepancies in functions being run.
# First terminal
clinic flame -- node ./dist/main.js
# Second terminal
k6 run --vus 1 --duration 10s --http-debug ./performance/direct.js
The hottest function is willResolveField from @apollo.
This time, the hottest function is in NodeJS - processTicksAndRejections. That indicates a huge amount of asynchronous operations:
Async queue seems to be even busier when using @Parent() decorator:
I think that @ResolveField is automatically turning functions into async functions even if the developer didn't state that and is making very simple synchronous operations.
In the experiments here, I took it to extreme and just returned the same field to show the difference but a case for simple synchronous operations has to exist.
Think about fullName that concatenates firstName and lastName or renaming some field or any other way of transforming the data.
A progressive Node.js framework for building efficient and scalable server-side applications.
Nest framework TypeScript starter repository.
$ yarn install# development
$ yarn run start
# watch mode
$ yarn run start:dev
# production mode
$ yarn run start:prod# unit tests
$ yarn run test
# e2e tests
$ yarn run test:e2e
# test coverage
$ yarn run test:covWhen you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the deployment documentation for more information.
If you are looking for a cloud-based platform to deploy your NestJS application, check out Mau, our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
$ yarn install -g mau
$ mau deployWith Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
Check out a few resources that may come in handy when working with NestJS:
- Visit the NestJS Documentation to learn more about the framework.
- For questions and support, please visit our Discord channel.
- To dive deeper and get more hands-on experience, check out our official video courses.
- Deploy your application to AWS with the help of NestJS Mau in just a few clicks.
- Visualize your application graph and interact with the NestJS application in real-time using NestJS Devtools.
- Need help with your project (part-time to full-time)? Check out our official enterprise support.
- To stay in the loop and get updates, follow us on X and LinkedIn.
- Looking for a job, or have a job to offer? Check out our official Jobs board.
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
- Author - Kamil Myśliwiec
- Website - https://nestjs.com
- Twitter - @nestframework
Nest is MIT licensed.





