mirror of
https://github.com/supabase/supabase.git
synced 2026-05-06 17:00:27 -04:00
33b9e1ed29
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.
31 lines
918 B
TypeScript
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()
|
|
}
|