To enable graphQL in your nestjs api, you can first read the offical document here.

Step 1, install npm package need

yarn add @nestjs/graphql graphql-tools graphql graphql-type-json apollo-server-express

declare a simple factory class for graphQL

In app.module.ts, add GraphQL module

and also define .gql under schema

Next, create order.resolver.ts which make graphQL support same request as restful, which define in order.controller.

Use postman to make a request for getOrders, we copy the sample request query and variable below

Here is the result which same as using restful API

The sample code is here, hope this help.

--

--