Files
supabase/apps/docs/scripts/graphqlSchema.ts
Charis 33b9e1ed29 chore(docs): convert all scripts to esm (#35996)
Scripts currently use CJS, which is causing a bit of a mess when trying
to use shared utilities from the app. Converting everything to ESM so
there are fewer conflicts when adding new scripts going forward.
2025-05-29 15:44:55 -04:00

31 lines
918 B
TypeScript

import { printSchema } from 'graphql'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { rootGraphQLSchema } from '../resources/rootSchema.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
async function generateGraphQLSchema() {
try {
const schemaString = printSchema(rootGraphQLSchema)
const outputDir = path.resolve(__dirname, '../__generated__')
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true })
}
const outputPath = path.resolve(outputDir, 'schema.graphql')
fs.writeFileSync(outputPath, schemaString)
console.log(`✅ Successfully generated GraphQL schema at ${outputPath}`)
} catch (error) {
console.error('🚨 Error generating GraphQL schema:', error)
process.exit(1)
}
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
generateGraphQLSchema()
}