Files
speckle-server/packages/server/modules/cli/commands/graphql/introspect.ts
T
Kristaps Fabians Geikins 4b06f42db7 chore(server): run TS files directly (no compilation) (#5134)
* sort of works

* type fixes

* added option to run old way too
2025-07-23 11:20:40 +02:00

34 lines
1013 B
TypeScript

import type { CommandModule } from 'yargs'
import { cliLogger as logger } from '@/observability/logging'
import * as ModulesSetup from '@/modules/index'
import { printSchema } from 'graphql/utilities'
import fs from 'node:fs/promises'
import path from 'node:path'
const command: CommandModule<unknown, { file: string }> = {
command: 'introspect [file]',
describe: 'Introspect server schema and save it to file',
builder: {
file: {
describe:
'Path to .graphql file that the introspection result should be dumped to',
type: 'string',
default: './introspected-schema.graphql'
}
},
handler: async ({ file }) => {
logger.info('Loading GQL schema...')
const schema = await ModulesSetup.graphSchema()
const schemaString = printSchema(schema)
logger.info(`Saving to "${file}"...`)
const absolutePath = path.isAbsolute(file)
? file
: path.resolve(process.cwd(), file)
await fs.writeFile(absolutePath, schemaString)
}
}
export = command