other
schema-ast

Schema AST

Package nameWeekly DownloadsVersionLicenseUpdated
@graphql-codegen/schema-ast (opens in a new tab)DownloadsVersionLicenseFeb 5th, 2023

Installation

Terminal
yarn add -D @graphql-codegen/schema-ast

Examples

codegen.ts
import type { CodegenConfig } from '@graphql-codegen/cli'
 
const config: CodegenConfig = {
  // ...
  schema: ['http://localhost:3000/graphql', './src/**/*.graphql', 'scalar MyCustomScalar'],
  generates: {
    'path/to/file.graphql': {
      plugins: ['schema-ast']
    }
  }
}
export default config

This plugin prints the merged schema as string. If multiple schemas are provided, they will be merged and printed as one schema.

Config API Reference

includeDirectives

type: boolean default: false

Include directives to Schema output.

Usage Examples

codegen.ts
 import type { CodegenConfig } from '@graphql-codegen/cli';
 
 const config: CodegenConfig = {
   schema: './src/schema.graphql',
   generates: {
     'path/to/file.graphql': {
       plugins: ['schema-ast'],
       config: {
         includeDirectives: true
       },
     },
   },
 };
 export default config;

includeIntrospectionTypes

type: boolean default: false

Include introspection types to Schema output.

Usage Examples

codegen.ts
 import type { CodegenConfig } from '@graphql-codegen/cli';
 
 const config: CodegenConfig = {
   schema: './src/schema.graphql',
   generates: {
     'path/to/file.graphql': {
       plugins: ['schema-ast'],
       config: {
         includeIntrospectionTypes: true
       },
     },
   },
 };
 export default config;

commentDescriptions

type: boolean default: false

Set to true in order to print description as comments (using # instead of """)

Usage Examples

codegen.ts
 import type { CodegenConfig } from '@graphql-codegen/cli';
 
 const config: CodegenConfig = {
   schema: './src/schema.graphql',
   generates: {
     'path/to/file.graphql': {
       plugins: ['schema-ast'],
       config: {
         commentDescriptions: true
       },
     },
   },
 };
 export default config;

sort

type: boolean default: true

Set to false to disable sorting

federation

type: boolean