2021-02-27 02:52:27 +00:00
|
|
|
'use strict';
|
|
|
|
|
2023-05-30 22:29:54 +00:00
|
|
|
/* eslint-disable arrow-body-style */
|
2023-06-18 23:45:45 +00:00
|
|
|
const config = require('config');
|
2021-02-27 02:52:27 +00:00
|
|
|
const { postgraphile } = require('postgraphile');
|
|
|
|
|
|
|
|
const PgConnectionFilterPlugin = require('postgraphile-plugin-connection-filter');
|
|
|
|
const PgSimplifyInflectorPlugin = require('@graphile-contrib/pg-simplify-inflector');
|
|
|
|
const PgOrderByRelatedPlugin = require('@graphile-contrib/pg-order-by-related');
|
|
|
|
|
2021-03-18 03:36:04 +00:00
|
|
|
const { ActorPlugins, SitePlugins, ReleasePlugins, MediaPlugins } = require('./plugins/plugins');
|
2021-02-27 02:52:27 +00:00
|
|
|
|
2021-03-14 03:54:43 +00:00
|
|
|
async function pgSettings(req) {
|
|
|
|
return {
|
2021-03-19 23:12:12 +00:00
|
|
|
'user.id': req.session.user?.id || null, // undefined is passed as an empty string, avoid
|
2023-06-18 23:45:45 +00:00
|
|
|
statement_timeout: config.database.timeout,
|
2021-03-14 03:54:43 +00:00
|
|
|
};
|
|
|
|
}
|
2021-02-27 02:52:27 +00:00
|
|
|
|
2023-06-03 00:51:42 +00:00
|
|
|
function initPostgraphile(credentials) {
|
|
|
|
const connectionString = `postgres://${credentials.user}:${credentials.password}@${credentials.host}:5432/${credentials.database}`;
|
|
|
|
|
|
|
|
return postgraphile(
|
|
|
|
connectionString,
|
|
|
|
'public',
|
|
|
|
{
|
|
|
|
// watchPg: true,
|
|
|
|
disableDefaultMutations: true,
|
|
|
|
dynamicJson: true,
|
2023-06-19 01:28:55 +00:00
|
|
|
graphiql: config.database.graphiql,
|
2023-06-03 00:51:42 +00:00
|
|
|
enhanceGraphiql: true,
|
|
|
|
allowExplain: () => true,
|
|
|
|
// simpleCollections: 'only',
|
|
|
|
simpleCollections: 'both',
|
|
|
|
graphileBuildOptions: {
|
|
|
|
pgOmitListSuffix: true,
|
2023-11-30 02:12:47 +00:00
|
|
|
// connectionFilterUseListInflectors: true,
|
2023-06-03 00:51:42 +00:00
|
|
|
connectionFilterRelations: true,
|
|
|
|
connectionFilterAllowNullInput: true,
|
|
|
|
},
|
|
|
|
appendPlugins: [
|
|
|
|
PgSimplifyInflectorPlugin,
|
|
|
|
PgConnectionFilterPlugin,
|
|
|
|
PgOrderByRelatedPlugin,
|
|
|
|
...ActorPlugins,
|
|
|
|
...SitePlugins,
|
|
|
|
...ReleasePlugins,
|
|
|
|
...MediaPlugins,
|
|
|
|
],
|
|
|
|
pgSettings,
|
2021-02-27 02:52:27 +00:00
|
|
|
},
|
2021-03-14 03:54:43 +00:00
|
|
|
pgSettings,
|
2023-06-03 00:51:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = initPostgraphile;
|