Lets Explore Nest JS graphql world

Lets Explore Nest JS graphql world

Let's talk about the hottest topic in the API world is Graphql and how we can build services using graphql in nestjs

Nest JS — https://github.com/nestjs/nest

Nest is a framework for building efficient, scalable Node.js server-side applications. It uses modern JavaScript, is built with TypeScript (preserves compatibility with pure JavaScript), and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).

Under the hood, Nest makes use of Express, but also, provides compatibility with a wide range of other libraries, like e.g. Fastify, allowing for easy use of the myriad third-party plugins which are available.

Now we can use the same nestjs framework with Graphql

Let's see how it works with Graphql as node js provided many libraries to write graphql implementation like yoga-graphql, apollo-graphql-server and many more

GraphQL is a powerful query language for APIs and a runtime for fulfilling those queries with your existing data. It’s an elegant approach that solves many problems typically found with REST APIs. For background, we suggest reading this comparison between GraphQL and REST. GraphQL combined with TypeScript helps you develop better type safety with your GraphQL queries, giving you end-to-end typing.

In this chapter, we assume a basic understanding of GraphQL and focus on how to work with the built-in @nestjs/graphql module. The GraphQLModule can be configured to use Apollo server (with the @nestjs/apollo driver) and Mercurius (with the @nestjs/mercurius). We provide official integrations for these proven GraphQL packages to provide a simple way to use GraphQL with Nest. You can also build your own dedicated driver (read more on that here).

https://docs.nestjs.com/graphql/quick-start

# For Express and Apollo (default)
$ npm i @nestjs/graphql @nestjs/apollo graphql apollo-server-express

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';

@Module({
  imports: [
    GraphQLModule.forRoot<ApolloDriverConfig>({
      driver: ApolloDriver,
    }),
  ],
})
export class AppModule {}

we can pass different options while bootstrapping GraphqlModule

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { ApolloDriver } from '@nestjs/apollo';

@Module({
  imports: [
    GraphQLModule.forRoot<ApolloDriverConfig>({
      driver: ApolloDriver,
      debug: false,
      playground: false,
    }),
  ],
})
export class AppModule {}

Now i am launching a full playlist on nestjs with graphql, you can learn graphql basic first and then can explore other parts of it

  • Learn basic graphql
  • Learn query mutations with simple express app
  • Explore apollo graphql server
  • Explore yoga-graphql library for building graphql service

This is a master course having all about graphql

{% youtube 6p6yggS4yPw %}

Now I am publishing another playlist that will talk about graphql with nestjs

  • nestjs graphql with mongoose
  • nestjs graphql with postgres
  • nestjs graphql with typeorm
  • nestjs graphql with different ORM and ODM
  • nestjs graphql blog App
  • nestjs graphql auth and authz

{% youtube ZcEWdx2exME %}

https://www.youtube.com/watch?list=PLIGDNOJWiL1-uGdiUKnhLvql_KrDNlvDy&v=6p6yggS4yPw&feature=emb_title

https://github.com/tkssharma/nodejs-graphql-world/tree/master/Graphql%20using%20Apollo

References

Comments