Backend – importing and configuring the GraphQL NestJS module

Before we continue and start using GraphQL, you should take a look at AppModule.

Open backend/src/app.module.ts. It should look as follows:

@Module({ 
  imports: [ 
    GraphQLModule.forRoot({ 
      debug: true, 
      playground: true, 
      autoSchemaFile: 'schema.gql', 
    }), 
    // ... 
  ], 
  // ... 
} 
export class AppModule {} 

If you've followed the Angular chapter (that is, Chapter 8, Discovering Angular, Angular Material, and RxJS), then this whole file should make you feel right at home. NestJS uses the same decorators/properties that we are now used to. In this case, we load GraphQLModule and configure it as required.

We have enabled the debug mode and playground to be able to debug and play with our GraphQL API through the web browser. The playground is a web application that we can use to easily interact with the GraphQL API and write/validate/test queries.

For this exercise, we have decided to follow the Code First approach, as proposed by the NestJS GraphQL plugin authors. This is the reason why we have defined the autoSchemaFile: 'schema.gql' option.

The GraphQL schema file will be generated automatically for us by the NestJS GraphQL plugin, thanks to the decorators that we have defined in the DTO as well as in the resolver.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.162.247