Files
supabase/apps/studio/scripts/download-graphql-schema.mts
Alaister Young 5f533247e1 Update docs url to env var (#38772)
* Update Supabase docs URLs to use env variable

Co-authored-by: a <a@alaisteryoung.com>

* Refactor: Use DOCS_URL constant for documentation links

This change centralizes documentation links using a new DOCS_URL constant, improving maintainability and consistency.

Co-authored-by: a <a@alaisteryoung.com>

* Refactor: Use DOCS_URL constant for all documentation links

This change replaces hardcoded documentation URLs with a centralized constant, improving maintainability and consistency.

Co-authored-by: a <a@alaisteryoung.com>

* replace more instances

* ci: Autofix updates from GitHub workflow

* remaining instances

* fix duplicate useRouter

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: alaister <10985857+alaister@users.noreply.github.com>
2025-09-26 10:16:33 +00:00

46 lines
1.2 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))
// Note: This is a build-time script, so we use the fallback URL directly
const DOCS_URL = process.env.NEXT_PUBLIC_DOCS_URL || 'https://supabase.com/docs'
async function downloadGraphQLSchema() {
const schemaEndpoint = `${DOCS_URL}/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()
}