Nest JS With Graphql World

tkssharma

tkssharma

Posted on March 16, 2022

Nest JS With Graphql World

Nest JS With Graphql World

My Blog originally published at Medium https://medium.com/tkssharma/nest-js-with-graphql-world-486059767768

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 {}
Enter fullscreen mode Exit fullscreen mode

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 {}
Enter fullscreen mode Exit fullscreen mode

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

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

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

πŸ’– πŸ’ͺ πŸ™… 🚩
tkssharma
tkssharma

Posted on March 16, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Nest JS With Graphql World
nestjs Nest JS With Graphql World

March 16, 2022