Friday, 17 June 2022

How to import directives in a nestJS graphQLModule?

I need to generate typeScript types for mongoDB using graphql-code-generator and the typescript-mongodb plugin, but I don't understand how to import the directives of that plugin in a nestJS application.

In my backend app (nestJS) the graphql module is defined like this:

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

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

In the docs of the plugin I see I have to use the directives:

import { makeExecutableSchema } from '@graphql-tools/schema'
import { DIRECTIVES } from '@graphql-codegen/typescript-mongodb'

const schema = makeExecutableSchema({
  typeDefs: [
    DIRECTIVES
    // the rest of your GraphQL types
  ],
  resolvers
})

But I don't get it how to implement this in my nestJS app, which is using GraphQLModule.



from How to import directives in a nestJS graphQLModule?

No comments:

Post a Comment