Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
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.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  1. Install these packages to the current nestjs repo
npm i @graphql-codegen/cli @graphql-codegen/typescript-mongodb
  1. add codegen config file codegen.yml
overwrite: true
schema: "http://localhost:3000/graphql"
documents: null
generates:
  src/generated/graphql.ts:
    plugins:
      - "typescript"
      - "typescript-mongodb"

The above code schema should point to the local GraphQl endpoint. The above code will generate types in src/generated/graphql.ts file

  1. add generate script in your package.json scripts
    "generate": "graphql-codegen --config codegen.yml"
  1. run generate script
npm run generate

Note: graphQL server (start:dev) should be running while using generate command

Working repo link - https://github.com/vinodsai-a/nestjs-graphql-codegen-example

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda