|
| 1 | +import type { TableMeta } from 'graphile-settings' |
| 2 | +import { _cachedTablesMeta } from 'graphile-settings' |
| 3 | +import { buildSchemaSDL } from './build-schema' |
| 4 | +import type { BuildSchemaOptions } from './build-schema' |
| 5 | + |
| 6 | +export type { BuildSchemaOptions as BuildIntrospectionOptions } |
| 7 | + |
| 8 | +/** |
| 9 | + * Build introspection metadata for all tables visible in the given schemas. |
| 10 | + * |
| 11 | + * Internally calls `buildSchemaSDL()` which triggers the MetaSchemaPlugin |
| 12 | + * gather hook, populating `_cachedTablesMeta` as a side-effect. The cached |
| 13 | + * metadata is then returned as a plain array of `TableMeta` objects. |
| 14 | + * |
| 15 | + * The result includes every table's fields, types, constraints, indexes, |
| 16 | + * relations, inflection names, and query entry-points — the same data |
| 17 | + * exposed by the `_meta` GraphQL query at runtime. |
| 18 | + * |
| 19 | + * @example |
| 20 | + * ```ts |
| 21 | + * import { buildIntrospectionJSON } from 'graphile-schema'; |
| 22 | + * import fs from 'fs'; |
| 23 | + * |
| 24 | + * const tables = await buildIntrospectionJSON({ |
| 25 | + * database: 'my_db', |
| 26 | + * schemas: ['public', 'app_public'], |
| 27 | + * }); |
| 28 | + * fs.writeFileSync('introspection.json', JSON.stringify(tables, null, 2)); |
| 29 | + * ``` |
| 30 | + */ |
| 31 | +export async function buildIntrospectionJSON( |
| 32 | + opts: BuildSchemaOptions |
| 33 | +): Promise<TableMeta[]> { |
| 34 | + await buildSchemaSDL(opts) |
| 35 | + return [..._cachedTablesMeta] |
| 36 | +} |
0 commit comments