crystal icon indicating copy to clipboard operation
crystal copied to clipboard

schema.graphql export is not awaited in getGraphQLSchema

Open ezpuzz opened this issue 3 years ago • 1 comments

https://github.com/graphile/postgraphile/blob/4164d437e57a30ff00ecbb4675943a0924c54ec9/src/postgraphile/postgraphile.ts#L159

the above is not awaited which leads to my issue

I'm trying to export schema.graphql in CI and can't use CLI to replicate complex library usage with plugins.

import { OPTIONS } from 'db/graphql/postgraphile';
config();

(async () => {
  const pgPool = new Pool({ connectionString: process.env.DATABASE_URL });
  const { getGraphQLSchema } = getPostgraphileSchemaBuilder(
    pgPool,
    ['schema'],
    { ...OPTIONS }
  );
  await getGraphQLSchema();
  await setTimeout(1000);  // I'd like to remove this!
  exit();
})();

I think the resolution may be awaiting the export?

ezpuzz avatar Jul 26 '22 19:07 ezpuzz

Awaiting that would cause server startup to slow down unnecessarily (since the export could write in parallel with starting the server).

I suggest you use the createPostGraphileSchema method instead and write the file yourself:

import { print } from "graphql";
import * as fs from "fs/promises";
import { createPostGraphileSchema } from "postgraphile";

async main() {
  const schema = await createPostGraphileSchema(
    pgPool,
    ['schema'],
    { ...OPTIONS }
  );
  await fs.writeFile('path/to/schema.graphql', print(schema));
}

main().catch(e => {
  console.error(e);
  process.exit(1);
});

benjie avatar Jul 27 '22 07:07 benjie

[semi-automated message] To keep things manageable I'm going to close this issue as I think it's solved; but if not or you require further help please re-open it.

benjie avatar Jan 03 '23 15:01 benjie