-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.ts
More file actions
119 lines (109 loc) · 3.23 KB
/
index.ts
File metadata and controls
119 lines (109 loc) · 3.23 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import PgManyToMany from '@graphile-contrib/pg-many-to-many';
import { getEnvOptions } from '@pgpmjs/env';
import { PgpmOptions } from '@pgpmjs/types';
import PgPostgis from 'graphile-postgis';
import FulltextFilterPlugin from 'graphile-plugin-fulltext-filter';
import { NodePlugin, Plugin } from 'graphile-build';
import {
additionalGraphQLContextFromRequest as langAdditional,
LangPlugin
} from 'graphile-i18n';
import PgMetaschema from 'graphile-meta-schema';
import PgSearch from 'graphile-search-plugin';
import PgSimpleInflector from 'graphile-simple-inflector';
import { PostGraphileOptions } from 'postgraphile';
import ConnectionFilterPlugin from 'graphile-plugin-connection-filter';
import PgPostgisFilter from 'graphile-plugin-connection-filter-postgis';
import CustomPgTypeMappingsPlugin from 'graphile-pg-type-mappings';
import UploadPostGraphilePlugin, { Uploader } from 'graphile-upload-plugin';
export const getGraphileSettings = (
rawOpts: PgpmOptions
): PostGraphileOptions => {
const opts = getEnvOptions(rawOpts);
const { server, graphile, features, cdn } = opts;
// Instantiate uploader with merged cdn opts
const uploader = new Uploader({
bucketName: cdn.bucketName!,
awsRegion: cdn.awsRegion!,
awsAccessKey: cdn.awsAccessKey!,
awsSecretKey: cdn.awsSecretKey!,
minioEndpoint: cdn.minioEndpoint,
});
const resolveUpload = uploader.resolveUpload.bind(uploader);
const plugins: Plugin[] = [
ConnectionFilterPlugin,
FulltextFilterPlugin,
CustomPgTypeMappingsPlugin,
UploadPostGraphilePlugin,
PgMetaschema,
PgManyToMany,
PgSearch,
];
if (features?.postgis) {
plugins.push(PgPostgis, PgPostgisFilter);
}
if (features?.simpleInflection) {
plugins.push(PgSimpleInflector);
}
plugins.push(LangPlugin);
return {
graphileBuildOptions: {
uploadFieldDefinitions: [
{
name: 'upload',
namespaceName: 'public',
type: 'JSON',
resolve: resolveUpload,
},
{
name: 'attachment',
namespaceName: 'public',
type: 'String',
resolve: resolveUpload,
},
{
name: 'image',
namespaceName: 'public',
type: 'JSON',
resolve: resolveUpload,
},
{
tag: 'upload',
resolve: resolveUpload,
},
],
pgSimplifyOppositeBaseNames: features?.oppositeBaseNames,
connectionFilterComputedColumns: false,
},
appendPlugins: plugins,
skipPlugins: [NodePlugin],
dynamicJson: true,
disableGraphiql: false,
enhanceGraphiql: true,
enableQueryBatching: true,
graphiql: true,
watch: false,
port: server?.port,
host: server?.host,
schema: graphile?.schema,
ignoreRBAC: false,
legacyRelations: 'omit',
showErrorStack: false,
// @ts-ignore
extendedErrors: false,
disableQueryLog: false,
includeExtensionResources: true,
setofFunctionsContainNulls: false,
retryOnInitFail: async (_error: Error) => {
return false;
},
additionalGraphQLContextFromRequest: async (req, res) => {
const langContext = await langAdditional(req, res);
return {
...langContext,
req,
res,
};
},
};
};