Generate DocumentNode for the schema when building servers #4067
-
I'm building a GraphQL server using So similar to what |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
It should be pretty simple, you can create something like that as a custom plugin: // my-plugin.js
const { printSchema, parse } = require('graphql');
module.exports = {
plugin: (schema) => {
const schemaStr = printSchema(schema);
const schemaNode = parse(schemaStr);
return `export const schema = ${JSON.stringify(schemaNode)}`;
}
} Then use it in codegen: schema: "src/**/*.graphql" # point here to all your schema pieces, codegen will merge it for you
generates:
./schema.ts:
plugins:
- ./my-plugin.js For more info about custom plugins: https://graphql-code-generator.com/docs/custom-codegen/index |
Beta Was this translation helpful? Give feedback.
-
Hi, I created a plugin for exactly this purpose so you can use: https://github.com/acomagu/graphql-codegen-typescript-schema |
Beta Was this translation helpful? Give feedback.
It should be pretty simple, you can create something like that as a custom plugin:
Then use it in codegen:
@affanshahid
For more info about custom plugins: https://graphql-code-generator.com/docs/custom-codegen/index