2023-05-25 09:27:26 +00:00
|
|
|
// @ts-nocheck
|
2023-03-13 12:11:25 +00:00
|
|
|
import { writeFileSync } from "node:fs";
|
2023-02-13 12:41:30 +00:00
|
|
|
import {
|
|
|
|
|
getIntrospectionQuery,
|
2023-03-13 12:11:25 +00:00
|
|
|
GraphQLSchema,
|
2023-02-13 12:41:30 +00:00
|
|
|
graphqlSync,
|
|
|
|
|
lexicographicSortSchema,
|
|
|
|
|
printSchema,
|
|
|
|
|
} from "graphql";
|
|
|
|
|
import { createPostGraphileSchema } from "postgraphile";
|
|
|
|
|
import { Pool } from "pg";
|
2023-03-13 12:11:25 +00:00
|
|
|
import { loadConfig } from "@digiresilience/metamigo-config";
|
2023-03-13 11:01:28 +00:00
|
|
|
import { getPostGraphileOptions } from "@digiresilience/metamigo-db";
|
2023-02-13 12:41:30 +00:00
|
|
|
|
|
|
|
|
export const exportGraphqlSchema = async (): Promise<void> => {
|
|
|
|
|
const config = await loadConfig();
|
|
|
|
|
|
|
|
|
|
const rootPgPool = new Pool({
|
|
|
|
|
connectionString: config.db.connection,
|
|
|
|
|
});
|
|
|
|
|
const exportSchema = `../../data/schema.graphql`;
|
|
|
|
|
const exportJson = `../../frontend/lib/graphql-schema.json`;
|
|
|
|
|
try {
|
2023-03-13 12:11:25 +00:00
|
|
|
const schema = (await createPostGraphileSchema(
|
2023-02-13 12:41:30 +00:00
|
|
|
config.postgraphile.authConnection,
|
|
|
|
|
"app_public",
|
|
|
|
|
getPostGraphileOptions()
|
2023-03-13 12:11:25 +00:00
|
|
|
)) as unknown as GraphQLSchema;
|
2023-02-13 12:41:30 +00:00
|
|
|
const sorted = lexicographicSortSchema(schema);
|
|
|
|
|
const json = graphqlSync(schema, getIntrospectionQuery());
|
|
|
|
|
writeFileSync(exportSchema, printSchema(sorted));
|
|
|
|
|
writeFileSync(exportJson, JSON.stringify(json));
|
|
|
|
|
|
|
|
|
|
console.log(`GraphQL schema exported to ${exportSchema}`);
|
|
|
|
|
console.log(`GraphQL schema json exported to ${exportJson}`);
|
|
|
|
|
} finally {
|
|
|
|
|
rootPgPool.end();
|
|
|
|
|
}
|
|
|
|
|
};
|