mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 21:59:16 +03:00
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.
43 lines
1.0 KiB
TypeScript
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()
|
|
}
|