Files
supabase/apps/studio/scripts/download-graphql-schema.mts
Charis d122f289df feat(api gateway logs): add error code explanation (#36315)
Add the ability to look up error code explanation in API Gateway logs.
Also a bunch of GraphQL-related utilities and generated types for
calling the Content API.
2025-06-24 13:18:12 -04:00

43 lines
1.0 KiB
TypeScript

import { stripIndent } from 'common-tags'
import { writeFileSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
async function downloadGraphQLSchema() {
const schemaEndpoint = 'https://supabase.com/docs/api/graphql'
const outputPath = path.join(__dirname, './schema.graphql')
const schemaQuery = stripIndent`
query SchemaQuery {
schema
}
`
try {
const response = await fetch(schemaEndpoint, {
method: 'POST',
body: JSON.stringify({
query: schemaQuery.trim(),
}),
})
const { data, errors } = await response.json()
if (errors) {
throw errors
}
writeFileSync(outputPath, data.schema, 'utf8')
console.log(`✅ Successfully downloaded GraphQL schema to ${outputPath}`)
} catch (error) {
console.error('🚨 Error generating GraphQL schema:', error)
process.exit(1)
}
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
downloadGraphQLSchema()
}