72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
require('dotenv').config();
|
|
const express = require("express");
|
|
const { postgraphile } = require("postgraphile");
|
|
const morgan = require("morgan");
|
|
|
|
console.log('database url: ', process.env.DATABASE_URL);
|
|
|
|
const port = process.env.PORT || 5000;
|
|
console.log('port: ', port);
|
|
|
|
const production = process.env.NODE_ENV === "production";
|
|
console.log('production: ', production);
|
|
|
|
const app = express();
|
|
app.use(morgan("combined"));
|
|
|
|
const postgraphileOptionsDev = {
|
|
subscriptions: true,
|
|
watchPg: true,
|
|
dynamicJson: true,
|
|
setofFunctionsContainNulls: false,
|
|
ignoreRBAC: false,
|
|
showErrorStack: "json",
|
|
extendedErrors: ["hint", "detail", "errcode"],
|
|
appendPlugins: [require("@graphile-contrib/pg-simplify-inflector")],
|
|
exportGqlSchemaPath: "schema.graphql",
|
|
graphiql: true,
|
|
enhanceGraphiql: true,
|
|
allowExplain(req) {
|
|
// TODO: customise condition!
|
|
return true;
|
|
},
|
|
enableQueryBatching: true,
|
|
legacyRelations: "omit",
|
|
pgSettings(req) {
|
|
/* TODO */
|
|
},
|
|
};
|
|
|
|
const postgraphileOptionsProd = {
|
|
subscriptions: true,
|
|
retryOnInitFail: true,
|
|
dynamicJson: true,
|
|
setofFunctionsContainNulls: false,
|
|
ignoreRBAC: false,
|
|
extendedErrors: ["errcode"],
|
|
appendPlugins: [require("@graphile-contrib/pg-simplify-inflector")],
|
|
graphiql: false,
|
|
enableQueryBatching: true,
|
|
disableQueryLog: true,
|
|
legacyRelations: "omit",
|
|
pgSettings(req) {
|
|
/* TODO */
|
|
},
|
|
};
|
|
|
|
app.use(
|
|
postgraphile(
|
|
process.env.DATABASE_URL,
|
|
"zvbn_nvp",
|
|
production ? postgraphileOptionsProd : postgraphileOptionsDev
|
|
)
|
|
);
|
|
|
|
app.listen(port, "0.0.0.0", () => {
|
|
console.log(`${production ? "🚀 PRODUCTION" : "🧑💻 DEV"} server`);
|
|
console.log(`GraphQL endpoint: http://localhost:${port}/graphql`);
|
|
console.log(
|
|
`GraphiQL (GraphQL IDE) endpoint: http://localhost:${port}/graphiql`
|
|
);
|
|
});
|