Move packages/apps back
This commit is contained in:
parent
6eaaf8e9be
commit
5535d6b575
348 changed files with 0 additions and 0 deletions
37
packages/metamigo-cli/postgraphile.ts
Normal file
37
packages/metamigo-cli/postgraphile.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { writeFileSync } from "fs";
|
||||
import {
|
||||
getIntrospectionQuery,
|
||||
graphqlSync,
|
||||
lexicographicSortSchema,
|
||||
printSchema,
|
||||
} from "graphql";
|
||||
import { createPostGraphileSchema } from "postgraphile";
|
||||
import { Pool } from "pg";
|
||||
import { loadConfig } from "config";
|
||||
import { getPostGraphileOptions } from "db";
|
||||
|
||||
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 {
|
||||
const schema = await createPostGraphileSchema(
|
||||
config.postgraphile.authConnection,
|
||||
"app_public",
|
||||
getPostGraphileOptions()
|
||||
);
|
||||
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();
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue