-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
43 lines (35 loc) · 1.07 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const pg = require("pg");
const { ApolloServer } = require("apollo-server");
const { makeSchemaAndPlugin } = require("postgraphile-apollo-server");
const postGraphileOptions = {
jwtSecret: process.env.JWT_SECRET || String(Math.random()),
subscriptions: true,
appendPlugins: [require("@graphile-contrib/pg-simplify-inflector")]
// dynamicJson: true,
// etc
};
const dbSchema = process.env.SCHEMA_NAMES
? process.env.SCHEMA_NAMES.split(",")
: "public";
const pgPool = new pg.Pool({
connectionString: process.env.DATABASE_URL
});
async function main() {
// See https://www.graphile.org/postgraphile/usage-schema/ for schema-only usage guidance
const { schema, plugin } = await makeSchemaAndPlugin(
pgPool,
dbSchema,
postGraphileOptions
);
// See https://www.apollographql.com/docs/apollo-server/api/apollo-server.html#ApolloServer
const server = new ApolloServer({
schema,
plugins: [plugin]
});
const { url } = await server.listen();
console.log(`🚀 Server ready at ${url}`);
}
main().catch(e => {
console.error(e);
process.exit(1);
});