UNPKG

graphile-settings

Version:
24 lines (23 loc) 892 B
import { getCachedTablesMeta, setCachedTablesMeta } from './cache'; import { extendQueryWithMetaField } from './graphql-meta-field'; import { collectTablesMeta } from './table-meta-builder'; export const MetaSchemaPlugin = { name: 'MetaSchemaPlugin', version: '1.0.0', description: 'Exposes _meta query for database schema introspection', schema: { hooks: { init(input, rawBuild) { const build = rawBuild; setCachedTablesMeta(collectTablesMeta(build)); return input; }, GraphQLObjectType_fields(rawFields, _rawBuild, rawContext) { const context = rawContext; if (context.Self?.name !== 'Query') return rawFields; return extendQueryWithMetaField(rawFields, getCachedTablesMeta()); }, }, }, };