Derek
04/17/2022, 5:20 PMbarry
04/17/2022, 7:57 PMbarry
04/17/2022, 7:58 PMbarry
04/17/2022, 7:58 PMfernandolguevara
04/18/2022, 1:27 PMjs
import { writeFileSync } from 'fs';
import openapiTS from 'openapi-typescript';
import dotenv from 'dotenv';
dotenv.config();
const url = 'your-supabase-url';
const key = 'your-supabase-anonkey';
// example 3: load [string] as remote URL (YAML or JSON; released in v4.0)
const output = await openapiTS(`${url}?apikey=${key}`, {
version: 'v3'
});
writeFileSync('./src/lib/supabase.types.ts', output);
fernandolguevara
04/18/2022, 1:28 PMfernandolguevara
04/18/2022, 1:32 PMjs
require("dotenv").config();
const fs = require("fs");
const gradient = require("gradient-string");
const path = require("path");
const ProgressBar = require("progress");
const { fetch } = require("cross-undici-fetch");
const {
buildClientSchema,
getIntrospectionQuery,
printSchema,
} = require("graphql");
const supagradient = gradient(["#00CB8A", "#78E0B8"]);
function fetchGraphQLSchema(url, options) {
options = options || {}; // eslint-disable-line no-param-reassign
const bar = new ProgressBar("🔦 Introspecting schema [:bar]", 24);
const id = setInterval(function () {
bar.tick();
if (bar.complete) {
clearInterval(id);
}
}, 250);
return fetch(url, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
apiKey: process.env.SUPABASE_ANON_KEY,
},
body: JSON.stringify({
query: getIntrospectionQuery(),
}),
})
.then((res) => {
debugger;
return res.json();
})
.then((schemaJSON) => {
if (options.readable) {
return printSchema(buildClientSchema(schemaJSON.data));
}
bar.complete();
return JSON.stringify(schemaJSON, null, 2);
});
}
const filePath = path.join(__dirname, "../graphql/schema/", "schema.graphql");
console.log();
console.log(
supagradient(
`🗞 Fetching GraphQL Schema from ${process.env.SUPABASE_URL} ...`
)
);
fetchGraphQLSchema(`${process.env.SUPABASE_URL}/graphql/v1`, {
readable: true,
}).then((schema) => {
fs.writeFileSync(filePath, schema, "utf-8");
console.log(supagradient(`✨ Saved to ${filePath}`));
console.log(
'💡 Be sure to run "yarn run codegen" to generate latest types.'
);
});
fernandolguevara
04/18/2022, 1:33 PMDerek
04/19/2022, 9:40 PMfernandolguevara
04/19/2022, 11:32 PM