📄️ Overview
Are you ready to take your GraphQL development skills to the next level? In this series of four articles, I'll guide you through the process of building a powerful GraphQL API using Nest and MongoDB. You'll learn best practices, and see how to scale your app just as you would in a real-world scenario.
📄️ Prerequisites
To fully benefit from this series, it's important to have a basic knowledge of NodeJS, GraphQL, NestJS, TypeScript, and MongoDB. However, even if you're new to these technologies, don't worry - this series will provide a comprehensive overview of our stack, including the most crucial aspects we'll be using along the way.
📄️ Why NestJS
NestJS(we will use Nest often) is a popular framework for building efficient, scalable Node server-side applications. Some reasons why developers might choose NestJS for API development include its use of modern JavaScript and TypeScript, its modular architecture, you don’t have to care much about the architecture of your project since Nest provides modern patterns, and its ability to easily integrate with other common libraries and frameworks such as Express. Additionally, NestJS provides a powerful CLI that can be used to generate boilerplate code, which can be a time-saver, making it easier to get started with building an API. Overall, NestJS can make it easier for developers to build efficient and maintainable APIs in a relatively short amount of time, read more about the fundamental of Nest here.
📄️ Setup our codebase
What are we going to build
📄️ Understand the Nest Architecture
From the project structure, let’s dive into the nest architecture:
📄️ From Rest to Graph
Currently, we have created a Rest API with one exposed endpoint, the GET defined in the src/app/app.controller.ts file, in this section, we will transition from the Rest API to Graphql API the painless way.
📄️ Setup Database and environment variables
You can get the codebase for the previous part by checking out the commit #4db24a
📄️ Create Modules
At this part, we have done most of the setup, now we will mostly code.
📄️ Security in Nest
You can get the codebase for the previous part by checking out the commit #20d18
📄️ Validation in Nest
As part of security, it’s very important to make sure users enter valid data so that we don’t have to save incorrect or incoherent data in the password. While most of the decorators can manage validating data, sometimes, we may need a deeper check to make sure users don’t challenge our database with incorrect data, for example, we shouldn’t allow a user to enter a weak password, or we should never allow the user to enter an invalid email on the registry, etc.
📄️ Deploy the codebase
We have covered the most core features of Nest, and we have made a long way to get here, let’s celebrate … Oups, before we really celebrate, we need to ship our app to clients, in this last part, we will deploy the app we just built on.
📄️ Conclusion
In the first part of this series provided an introduction to Nest, a powerful NodeJS framework that allows you to build efficient and scalable applications. By diving into the fundamentals of Nest, we have set up the foundation for our final project, while exploring a couple of key concepts of the framework, a powerful GraphQL API using Nest and MongoDB. With this knowledge, we were able to understand the nest architecture and built on top of built-in packages, hope you enjoyed building along. In the next parts of this series, we will continue to build upon this foundation and learn how to implement best practices and scale our app in a real-world scenario, such as TDD, CI/CD, and microservice architecture.