Skip to content

Instantly share code, notes, and snippets.

@timble-one
Last active December 18, 2025 10:39
Show Gist options
  • Select an option

  • Save timble-one/c168d173a9bebdf36b246ca29e91ca74 to your computer and use it in GitHub Desktop.

Select an option

Save timble-one/c168d173a9bebdf36b246ca29e91ca74 to your computer and use it in GitHub Desktop.
import {buildClientSchema, getIntrospectionQuery, printSchema} from "graphql";
import * as fs from "fs";
import {loadEnv} from "vite";
const main = (async () => {
const env = loadEnv('dev', process.cwd())
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'
const res = await fetch(`${env.VITE_HTTP_ENDPOINT}/api/graphql`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-AUTH-TOKEN': 'very-secret-token',
},
body: JSON.stringify({
query: getIntrospectionQuery(),
})
})
if (!res.ok) {
console.error(res.statusText)
process.exit(1)
}
const data = await res.json()
if (!('data' in data)) {
console.error(data)
process.exit(1)
}
const schema = printSchema(buildClientSchema(data.data))
schema && fs.writeFileSync('src/schema.graphql', schema)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment