82 lines
2.1 KiB
JavaScript
Executable File
82 lines
2.1 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
const config = require('config');
|
|
|
|
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');
|
|
const PgAggregatesPlugin = require('@graphile/pg-aggregates').default;
|
|
|
|
const { ActorPlugins, SitePlugins, ReleasePlugins, MediaPlugins } = require('./plugins/plugins');
|
|
|
|
const connectionString = `postgres://${config.database.query.user}:${config.database.query.password}@${config.database.query.host}:5432/${config.database.query.database}`;
|
|
|
|
async function pgSettings(req) {
|
|
return {
|
|
'user.id': req.session.user?.id || null, // undefined is passed as an empty string, avoid
|
|
};
|
|
}
|
|
|
|
// console.log(PgAggregatesPlugin);
|
|
|
|
/*
|
|
const TagsAggregatePlugin = (builder) => {
|
|
builder.hook('build', (build) => {
|
|
const pgAggregateSpecs = [
|
|
{
|
|
id: 'tags',
|
|
humanLabel: 'tags',
|
|
HumanLabel: 'Tags',
|
|
sqlAggregateWrap: (sqlFrag) => {
|
|
// console.log('sql frag', sqlFrag);
|
|
return build.pgSql.fragment`select tag_id from tags where release_id = ${sqlFrag}`;
|
|
},
|
|
isSuitableType: (pgType) => {
|
|
// console.log('pg type', pgType);
|
|
return pgType.category === 'N';
|
|
},
|
|
},
|
|
];
|
|
|
|
build.pgAggregateGroupBySpecs = pgAggregateSpecs; // eslint-disable-line no-param-reassign
|
|
|
|
return build;
|
|
});
|
|
};
|
|
*/
|
|
|
|
module.exports = postgraphile(
|
|
connectionString,
|
|
'public',
|
|
{
|
|
// watchPg: true,
|
|
disableDefaultMutations: true,
|
|
dynamicJson: true,
|
|
graphiql: true,
|
|
enhanceGraphiql: true,
|
|
allowExplain: () => true,
|
|
// simpleCollections: 'only',
|
|
simpleCollections: 'both',
|
|
graphileBuildOptions: {
|
|
pgOmitListSuffix: true,
|
|
connectionFilterRelations: true,
|
|
connectionFilterAllowNullInput: true,
|
|
},
|
|
appendPlugins: [
|
|
PgSimplifyInflectorPlugin,
|
|
PgConnectionFilterPlugin,
|
|
PgAggregatesPlugin,
|
|
PgOrderByRelatedPlugin,
|
|
...ActorPlugins,
|
|
...SitePlugins,
|
|
...ReleasePlugins,
|
|
...MediaPlugins,
|
|
// TagsAggregatePlugin,
|
|
],
|
|
pgSettings,
|
|
},
|
|
pgSettings,
|
|
);
|