Skip to content

Commit 7251b0c

Browse files
jamesallainbenjie
authored andcommitted
Fix yarn server schema:export command via makeSchema (#357)
Co-authored-by: Benjie Gillam <benjie@jemjie.com>
1 parent 697c045 commit 7251b0c

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

@app/server/scripts/schema-export.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
import { writeFileSync } from "fs";
22
import { lexicographicSortSchema, printSchema } from "graphql";
33
import { Pool } from "pg";
4-
import { createPostGraphileSchema } from "postgraphile";
4+
import { makeSchema } from "postgraphile";
55

6-
import { getPostGraphileOptions } from "../src/graphile.config";
6+
import { getPreset } from "../src/graphile.config";
77

88
async function main() {
9-
const rootPgPool = new Pool({
10-
connectionString: process.env.DATABASE_URL!,
9+
const authPgPool = new Pool({
10+
connectionString: process.env.AUTH_DATABASE_URL!,
1111
});
12+
const preset = {
13+
extends: [getPreset({ authPgPool })],
14+
schema: {
15+
// Turn off built-in schema exporting
16+
exportSchemaSDLPath: undefined,
17+
exportSchemaIntrospectionResultPath: undefined,
18+
},
19+
};
20+
1221
try {
13-
const schema = await createPostGraphileSchema(
14-
process.env.AUTH_DATABASE_URL!,
15-
"app_public",
16-
getPostGraphileOptions({ rootPgPool })
17-
);
22+
const { schema } = await makeSchema(preset);
1823
const sorted = lexicographicSortSchema(schema);
1924
writeFileSync(
2025
`${__dirname}/../../../data/schema.graphql`,
21-
printSchema(sorted)
26+
printSchema(sorted) + "\n"
2227
);
2328
console.log("GraphQL schema exported");
2429
} finally {
25-
rootPgPool.end();
30+
authPgPool.end();
2631
}
2732
}
2833

@app/server/src/graphile.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function uuidOrNull(input: string | number | null | undefined): UUID | null {
6060

6161
interface IPostGraphileOptionsOptions {
6262
authPgPool: Pool;
63-
rootPgPool: Pool;
63+
rootPgPool?: Pool;
6464
}
6565

6666
const isTest = process.env.NODE_ENV === "test";
@@ -222,7 +222,7 @@ export function getPreset({
222222
const sessionId = uuidOrNull(req.user?.session_id);
223223
if (sessionId) {
224224
// Update the last_active timestamp (but only do it at most once every 15 seconds to avoid too much churn).
225-
await rootPgPool.query(
225+
await rootPgPool?.query(
226226
"UPDATE app_private.sessions SET last_active = NOW() WHERE uuid = $1 AND last_active < NOW() - INTERVAL '15 seconds'",
227227
[sessionId]
228228
);

0 commit comments

Comments
 (0)