sikanhe / gqtx

Code-first Typescript GraphQL Server without codegen or metaprogramming
458 stars 13 forks source link

Dump schema in IDL format #78

Open acro5piano opened 3 months ago

acro5piano commented 3 months ago

Hi, thank you for the great library. It helps my life a lot.

Do you have a plan to dump IDL schema?

I'm using gqtx along with the awesome graphql-code-generator. To generate GraphQL query, I need schema.graphql file (Network request also works but I prefer to omit dependent services for code generation). Also, a static schema file will help other developers to understand overall API.

I've written the below script to dump schema in my current project. It would be great if dumping a schema is officially supported:

import { buildGraphQLSchema } from 'gqtx'

import { printSchemaWithDirectives } from '@graphql-tools/utils'
import { writeFileSync } from 'node:fs'
import { QueryType } from './types/Query'

export const schema = buildGraphQLSchema({
  query: QueryType,
})

writeFileSync(
  './path/to/schema.graphql',
  printSchemaWithDirectives(schema),
  'utf8',
)

If it's okay I'll try to send a PR. Thanks!