Generating SDL and automatic resolvers (for graphql-codegen use) #277
-
Hi, I'm facing a small issue. I just installed the library on an existing project which already had quite a few resolvers. In this project, I need to generate the schema manually as explained here in the documentation: https://docs.nestjs.com/graphql/generating-sdl : async function generateSchema() {
const app = await NestFactory.create(GraphQLSchemaBuilderModule);
await app.init();
const gqlSchemaFactory = app.get(GraphQLSchemaFactory);
const schema = await gqlSchemaFactory.create([RecipesResolver]);
console.log(printSchema(schema));
} However, when I run the command, the generated schema does not take into account dynamic resolvers, i.e., those automatically generated by the syntax: NestjsQueryGraphQLModule.forFeature({
imports: [NestjsQueryTypeOrmModule.forFeature([TodoItemEntity])],
resolvers: [{ DTOClass: TodoItemDTO, EntityClass: TodoItemEntity }],
}), Has anyone managed to do this? FYI, apart from this issue, everything works well in the app. I can access my resolvers, but the schema generated with generate-schema is incomplete, which is problematic because I need it to generate my TypeScript types file for the frontend (via graphql-codegen). |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Could you give a bit more info? For example, I also modify the schema file that is generated (copy a subset over to a other one) with no issues, I use: GraphQLModule.forRootAsync({
useFactory: (configService: ConfigService): MercuriusDriverConfig => ({
autoSchemaFile: 'schema.main.gql',
schemaTransforms: generateClientApiSchema
})
}) export const generateClientApiSchema = (schema: GraphQLSchema): GraphQLSchema => {
// Do stuff
return schema
} |
Beta Was this translation helpful? Give feedback.
-
Thank you for your quick response, I pushed a repo to reproduce the issue https://github.com/lenybernard/nestjs-query-generate-sdl My context is pretty basic :
If you want to test, you can run : npm run generate-schema Then, the generated schema file in type Author {
id: ID!
name: String!
}
type Query {
author(id: Int!): Author!
} Thank you for your help. |
Beta Was this translation helpful? Give feedback.
By doing this:
A file name
filename.gql
will be generated that contains everything, this is also what I use to then generate my interfaces from (just like you).