Skip to content

Commit

Permalink
Use the authPgPool when exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Mar 17, 2023
1 parent f7ab73b commit 502ee7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 14 additions & 8 deletions @app/server/scripts/schema-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@ import { makeSchema } from "postgraphile";
import { getPreset } from "../src/graphile.config";

async function main() {
const rootPgPool = new Pool({
connectionString: process.env.DATABASE_URL!,
const authPgPool = new Pool({
connectionString: process.env.AUTH_DATABASE_URL!,
});
try {
const { schema } = await makeSchema(
getPreset({ rootPgPool, authPgPool: rootPgPool })
);
const preset = {
extends: [getPreset({ authPgPool })],
schema: {
// Turn off built-in schema exporting
exportSchemaSDLPath: undefined,
exportSchemaIntrospectionResultPath: undefined,
},
};

try {
const { schema } = await makeSchema(preset);
const sorted = lexicographicSortSchema(schema);
writeFileSync(
`${__dirname}/../../../data/schema.graphql`,
printSchema(sorted)
printSchema(sorted) + "\n"
);
console.log("GraphQL schema exported");
} finally {
rootPgPool.end();
authPgPool.end();
}
}

Expand Down
4 changes: 2 additions & 2 deletions @app/server/src/graphile.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const isDev = process.env.NODE_ENV === "development";

interface IPostGraphileOptionsOptions {
authPgPool: Pool;
rootPgPool: Pool;
rootPgPool?: Pool;
}

export function getPreset({
Expand Down Expand Up @@ -224,7 +224,7 @@ export function getPreset({
const sessionId = uuidOrNull(req.user?.session_id);
if (sessionId) {
// Update the last_active timestamp (but only do it at most once every 15 seconds to avoid too much churn).
await rootPgPool.query(
await rootPgPool?.query(
"UPDATE app_private.sessions SET last_active = NOW() WHERE uuid = $1 AND last_active < NOW() - INTERVAL '15 seconds'",
[sessionId]
);
Expand Down

0 comments on commit 502ee7a

Please sign in to comment.