Nest JS With Graphql World
Tags: nestjs, graphql, node
Published: 2022-03-16 15:49:43


### 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

![](https://cdn-images-1.medium.com/max/2560/1*SxqjYjhXg0lHdiKYQpBOnw.jpeg)

Nest JS — [https://github.com/nestjs/nest](https://github.com/nestjs/nest)

Nest is a framework for building efficient, scalable [Node.js](http://nodejs.org/) server-side applications. It uses modern JavaScript, is built with [TypeScript](http://www.typescriptlang.org/) (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](https://expressjs.com/), but also, provides compatibility with a wide range of other libraries, like e.g. [Fastify](https://github.com/fastify/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](https://graphql.org/) 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](https://dev-blog.apollodata.com/graphql-vs-rest-5d425123e34b) between GraphQL and REST. GraphQL combined with [TypeScript](https://www.typescriptlang.org/) 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](https://www.apollographql.com/) server (with the @nestjs/apollo driver) and [Mercurius](https://github.com/mercurius-js/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/other-features#creating-a-custom-driver)).

[https://docs.nestjs.com/graphql/quick-start](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](https://github.com/tkssharma/nodejs-graphql-world/tree/master/Graphql%20using%20Apollo)

References

* [https://nestjs.com/](https://nestjs.com/)
* [https://graphql.org/](https://graphql.org/)