import { GraphQLSchema , introspectionFromSchema } from 'graphql' ; import { PluginFunction , PluginValidateFn , Types , removeFederation } from '@graphql-codegen/plugin-helpers' ; import { extname } from 'path' ; import { getConfigValue } from '../../visitor-plugin-common/src/utils' ; description export interface IntrospectionPluginConfig { description default exampleMarkdown minify ? : boolean ; description default descriptions ? : boolean ; description default specifiedByUrl ? : boolean ; description default directiveIsRepeatable ? : boolean ; description default schemaDescription ? : boolean ; federation ? : boolean ; } export const plugin = async ( schema , _documents , pluginConfig ) : Promise < string > => { const cleanSchema = pluginConfig . federation ? removeFederation ( schema ) : schema ; const descriptions = getConfigValue ( pluginConfig . descriptions , true ) ; const directiveIsRepeatable = getConfigValue ( pluginConfig . directiveIsRepeatable , true ) ; const schemaDescription = getConfigValue ( pluginConfig . schemaDescription , undefined ) ; const specifiedByUrl = getConfigValue ( pluginConfig . specifiedByUrl , undefined ) ; const introspection = introspectionFromSchema ( cleanSchema , { descriptions , directiveIsRepeatable , schemaDescription , specifiedByUrl , } ) ; return pluginConfig . minify ? JSON . stringify ( introspection ) : JSON . stringify ( introspection , null , 2 ) ; } ; export const validate = async ( schema , documents , config , outputFile ) => { if ( extname ( outputFile ) !== '.json' ) { throw new Error ( `Plugin "introspection" requires extension to be ".json"!` ) ; } } ;