graphile-settings 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +59 -0
- package/esm/index.js +108 -0
- package/esm/plugins/types.js +31 -0
- package/esm/resolvers/upload.js +54 -0
- package/index.d.ts +3 -0
- package/index.js +113 -0
- package/package.json +66 -0
- package/plugins/types.d.ts +3 -0
- package/plugins/types.js +33 -0
- package/resolvers/upload.d.ts +14 -0
- package/resolvers/upload.js +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
|
|
4
|
+
Copyright (c) 2025 Hyperweb <developers@hyperweb.io>
|
|
5
|
+
Copyright (c) 2020-present, Interweb, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# graphile-settings
|
|
2
|
+
|
|
3
|
+
<p align="center" width="100%">
|
|
4
|
+
<img height="250" src="https://raw.githubusercontent.com/launchql/launchql/refs/heads/main/assets/outline-logo.svg" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center" width="100%">
|
|
8
|
+
<a href="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml">
|
|
9
|
+
<img height="20" src="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml/badge.svg" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/launchql/launchql/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/graphile-settings"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/launchql?filename=packages%2Fgraphile-settings%2Fpackage.json"/></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
## Related LaunchQL Tooling
|
|
16
|
+
|
|
17
|
+
### 🧪 Testing
|
|
18
|
+
|
|
19
|
+
* [launchql/pgsql-test](https://github.com/launchql/launchql/tree/main/packages/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
|
|
20
|
+
* [launchql/graphile-test](https://github.com/launchql/launchql/tree/main/packages/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
|
|
21
|
+
* [launchql/pg-query-context](https://github.com/launchql/launchql/tree/main/packages/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
|
|
22
|
+
|
|
23
|
+
### 🧠 Parsing & AST
|
|
24
|
+
|
|
25
|
+
* [launchql/pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
26
|
+
* [launchql/libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
27
|
+
* [launchql/pg-proto-parser](https://github.com/launchql/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
|
|
28
|
+
* [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
|
|
29
|
+
* [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
|
|
30
|
+
* [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
|
|
31
|
+
* [launchql/pg-ast](https://github.com/launchql/launchql/tree/main/packages/pg-ast): **🔍 Low-level AST tools** and transformations for Postgres query structures.
|
|
32
|
+
|
|
33
|
+
### 🚀 API & Dev Tools
|
|
34
|
+
|
|
35
|
+
* [launchql/server](https://github.com/launchql/launchql/tree/main/packages/server): **⚡ Express-based API server** powered by PostGraphile to expose a secure, scalable GraphQL API over your Postgres database.
|
|
36
|
+
* [launchql/explorer](https://github.com/launchql/launchql/tree/main/packages/explorer): **🔎 Visual API explorer** with GraphiQL for browsing across all databases and schemas—useful for debugging, documentation, and API prototyping.
|
|
37
|
+
|
|
38
|
+
### 🔁 Streaming & Uploads
|
|
39
|
+
|
|
40
|
+
* [launchql/s3-streamer](https://github.com/launchql/launchql/tree/main/packages/s3-streamer): **📤 Direct S3 streaming** for large files with support for metadata injection and content validation.
|
|
41
|
+
* [launchql/etag-hash](https://github.com/launchql/launchql/tree/main/packages/etag-hash): **🏷️ S3-compatible ETags** created by streaming and hashing file uploads in chunks.
|
|
42
|
+
* [launchql/etag-stream](https://github.com/launchql/launchql/tree/main/packages/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
|
|
43
|
+
* [launchql/uuid-hash](https://github.com/launchql/launchql/tree/main/packages/uuid-hash): **🆔 Deterministic UUIDs** generated from hashed content, great for deduplication and asset referencing.
|
|
44
|
+
* [launchql/uuid-stream](https://github.com/launchql/launchql/tree/main/packages/uuid-stream): **🌊 Streaming UUID generation** based on piped file content—ideal for upload pipelines.
|
|
45
|
+
* [launchql/upload-names](https://github.com/launchql/launchql/tree/main/packages/upload-names): **📂 Collision-resistant filenames** utility for structured and unique file names for uploads.
|
|
46
|
+
|
|
47
|
+
### 🧰 CLI & Codegen
|
|
48
|
+
|
|
49
|
+
* [@launchql/cli](https://github.com/launchql/launchql/tree/main/packages/cli): **🖥️ Command-line toolkit** for managing LaunchQL projects—supports database scaffolding, migrations, seeding, code generation, and automation.
|
|
50
|
+
* [launchql/launchql-gen](https://github.com/launchql/launchql/tree/main/packages/launchql-gen): **✨ Auto-generated GraphQL** mutations and queries dynamically built from introspected schema data.
|
|
51
|
+
* [@launchql/query-builder](https://github.com/launchql/launchql/tree/main/packages/query-builder): **🏗️ SQL constructor** providing a robust TypeScript-based query builder for dynamic generation of `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and stored procedure calls—supports advanced SQL features like `JOIN`, `GROUP BY`, and schema-qualified queries.
|
|
52
|
+
* [@launchql/query](https://github.com/launchql/launchql/tree/main/packages/query): **🧩 Fluent GraphQL builder** for PostGraphile schemas. ⚡ Schema-aware via introspection, 🧩 composable and ergonomic for building deeply nested queries.
|
|
53
|
+
|
|
54
|
+
## Disclaimer
|
|
55
|
+
|
|
56
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
57
|
+
|
|
58
|
+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
|
59
|
+
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { NodePlugin } from 'graphile-build';
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import PgSimpleInflector from 'graphile-simple-inflector';
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import PgMetaschema from 'graphile-meta-schema';
|
|
6
|
+
import ConnectionFilterPlugin from 'postgraphile-plugin-connection-filter';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import FulltextFilterPlugin from '@pyramation/postgraphile-plugin-fulltext-filter';
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
import PostGraphileUploadFieldPlugin from 'postgraphile-derived-upload-field';
|
|
11
|
+
import { LangPlugin, additionalGraphQLContextFromRequest as langAdditional
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
} from 'graphile-i18n';
|
|
14
|
+
import PgPostgis from '@pyramation/postgis';
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
import PgPostgisFilter from 'postgraphile-plugin-connection-filter-postgis';
|
|
17
|
+
import PgManyToMany from '@graphile-contrib/pg-many-to-many';
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
import PgSearch from 'graphile-search-plugin';
|
|
20
|
+
import LqlTypesPlugin from './plugins/types';
|
|
21
|
+
import { Uploader } from './resolvers/upload';
|
|
22
|
+
import { getEnvOptions } from '@launchql/types';
|
|
23
|
+
export const getGraphileSettings = (rawOpts) => {
|
|
24
|
+
const opts = getEnvOptions(rawOpts);
|
|
25
|
+
const { server, graphile, features, cdn } = opts;
|
|
26
|
+
// Instantiate uploader with merged cdn opts
|
|
27
|
+
const uploader = new Uploader({
|
|
28
|
+
bucketName: cdn.bucketName,
|
|
29
|
+
awsRegion: cdn.awsRegion,
|
|
30
|
+
awsAccessKey: cdn.awsAccessKey,
|
|
31
|
+
awsSecretKey: cdn.awsSecretKey,
|
|
32
|
+
minioEndpoint: cdn.minioEndpoint
|
|
33
|
+
});
|
|
34
|
+
const resolveUpload = uploader.resolveUpload.bind(uploader);
|
|
35
|
+
const plugins = [
|
|
36
|
+
ConnectionFilterPlugin,
|
|
37
|
+
FulltextFilterPlugin,
|
|
38
|
+
LqlTypesPlugin,
|
|
39
|
+
PostGraphileUploadFieldPlugin,
|
|
40
|
+
PgMetaschema,
|
|
41
|
+
PgManyToMany,
|
|
42
|
+
PgSearch
|
|
43
|
+
];
|
|
44
|
+
if (features?.postgis) {
|
|
45
|
+
plugins.push(PgPostgis, PgPostgisFilter);
|
|
46
|
+
}
|
|
47
|
+
if (features?.simpleInflection) {
|
|
48
|
+
plugins.push(PgSimpleInflector);
|
|
49
|
+
}
|
|
50
|
+
plugins.push(LangPlugin);
|
|
51
|
+
return {
|
|
52
|
+
graphileBuildOptions: {
|
|
53
|
+
uploadFieldDefinitions: [
|
|
54
|
+
{
|
|
55
|
+
name: 'upload',
|
|
56
|
+
namespaceName: 'public',
|
|
57
|
+
type: 'JSON',
|
|
58
|
+
resolve: resolveUpload
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'attachment',
|
|
62
|
+
namespaceName: 'public',
|
|
63
|
+
type: 'String',
|
|
64
|
+
resolve: resolveUpload
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'image',
|
|
68
|
+
namespaceName: 'public',
|
|
69
|
+
type: 'JSON',
|
|
70
|
+
resolve: resolveUpload
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
tag: 'upload',
|
|
74
|
+
resolve: resolveUpload
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
pgSimplifyOppositeBaseNames: features?.oppositeBaseNames,
|
|
78
|
+
connectionFilterComputedColumns: false
|
|
79
|
+
},
|
|
80
|
+
appendPlugins: plugins,
|
|
81
|
+
skipPlugins: [NodePlugin],
|
|
82
|
+
dynamicJson: true,
|
|
83
|
+
disableGraphiql: false,
|
|
84
|
+
enhanceGraphiql: true,
|
|
85
|
+
enableQueryBatching: true,
|
|
86
|
+
graphiql: true,
|
|
87
|
+
watch: false,
|
|
88
|
+
port: server?.port,
|
|
89
|
+
host: server?.host,
|
|
90
|
+
schema: graphile?.schema,
|
|
91
|
+
ignoreRBAC: false,
|
|
92
|
+
legacyRelations: 'omit',
|
|
93
|
+
showErrorStack: false,
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
extendedErrors: false,
|
|
96
|
+
disableQueryLog: false,
|
|
97
|
+
includeExtensionResources: true,
|
|
98
|
+
setofFunctionsContainNulls: false,
|
|
99
|
+
retryOnInitFail: async (_error) => {
|
|
100
|
+
return false;
|
|
101
|
+
},
|
|
102
|
+
additionalGraphQLContextFromRequest: (req, res) => ({
|
|
103
|
+
...langAdditional(req, res),
|
|
104
|
+
req,
|
|
105
|
+
res
|
|
106
|
+
})
|
|
107
|
+
};
|
|
108
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// formerly lql-types.js
|
|
2
|
+
const CustomPgTypeMappingsPlugin = builder => {
|
|
3
|
+
builder.hook('build', (build, _context) => {
|
|
4
|
+
const customMappings = [
|
|
5
|
+
{ name: 'geolocation', namespaceName: 'public', type: 'GeoJSON' },
|
|
6
|
+
{ name: 'geopolygon', namespaceName: 'public', type: 'GeoJSON' },
|
|
7
|
+
{ name: 'email', namespaceName: 'public', type: 'String' },
|
|
8
|
+
{ name: 'hostname', namespaceName: 'public', type: 'String' },
|
|
9
|
+
{ name: 'multiple_select', namespaceName: 'public', type: 'JSON' },
|
|
10
|
+
{ name: 'single_select', namespaceName: 'public', type: 'JSON' },
|
|
11
|
+
{ name: 'origin', namespaceName: 'public', type: 'String' },
|
|
12
|
+
{ name: 'url', namespaceName: 'public', type: 'String' },
|
|
13
|
+
];
|
|
14
|
+
for (const { name, namespaceName, type } of customMappings) {
|
|
15
|
+
const pgType = build.pgIntrospectionResultsByKind.type.find(
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
t => t.name === name && t.namespaceName === namespaceName);
|
|
18
|
+
if (pgType) {
|
|
19
|
+
build.pgRegisterGqlTypeByTypeId(pgType.id, () => {
|
|
20
|
+
const gqlType = build.getTypeByName(type);
|
|
21
|
+
if (!gqlType) {
|
|
22
|
+
throw new Error(`Unknown GraphQL type: ${type}`);
|
|
23
|
+
}
|
|
24
|
+
return gqlType;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return build;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
export default CustomPgTypeMappingsPlugin;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import streamer from '@launchql/s3-streamer';
|
|
2
|
+
import uploadNames from '@launchql/upload-names';
|
|
3
|
+
export class Uploader {
|
|
4
|
+
opts;
|
|
5
|
+
streamerInstance;
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
this.opts = opts;
|
|
8
|
+
const { bucketName, awsRegion, awsSecretKey, awsAccessKey, minioEndpoint } = this.opts;
|
|
9
|
+
this.streamerInstance = new streamer({
|
|
10
|
+
defaultBucket: bucketName,
|
|
11
|
+
awsRegion,
|
|
12
|
+
awsSecretKey,
|
|
13
|
+
awsAccessKey,
|
|
14
|
+
minioEndpoint,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
async resolveUpload(upload, _args, _context, info) {
|
|
18
|
+
const { uploadPlugin: { tags, type } } = info;
|
|
19
|
+
const readStream = upload.createReadStream();
|
|
20
|
+
const { filename } = upload;
|
|
21
|
+
const rand = Math.random().toString(36).substring(2, 7) +
|
|
22
|
+
Math.random().toString(36).substring(2, 7);
|
|
23
|
+
const key = `${rand}-${uploadNames(filename)}`;
|
|
24
|
+
const result = await this.streamerInstance.upload({
|
|
25
|
+
readStream,
|
|
26
|
+
filename,
|
|
27
|
+
key,
|
|
28
|
+
bucket: this.opts.bucketName
|
|
29
|
+
});
|
|
30
|
+
const url = result.upload.Location;
|
|
31
|
+
const { contentType, magic: { charset } } = result;
|
|
32
|
+
const typ = type || tags.type;
|
|
33
|
+
const allowedMimes = tags.mime
|
|
34
|
+
? tags.mime.trim().split(',').map((a) => a.trim())
|
|
35
|
+
: typ === 'image'
|
|
36
|
+
? ['image/jpg', 'image/jpeg', 'image/png', 'image/svg+xml']
|
|
37
|
+
: [];
|
|
38
|
+
if (allowedMimes.length && !allowedMimes.includes(contentType)) {
|
|
39
|
+
throw new Error(`UPLOAD_MIMETYPE ${allowedMimes.join(',')}`);
|
|
40
|
+
}
|
|
41
|
+
switch (typ) {
|
|
42
|
+
case 'image':
|
|
43
|
+
case 'upload':
|
|
44
|
+
return {
|
|
45
|
+
filename,
|
|
46
|
+
mime: contentType,
|
|
47
|
+
url
|
|
48
|
+
};
|
|
49
|
+
case 'attachment':
|
|
50
|
+
default:
|
|
51
|
+
return url;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getGraphileSettings = void 0;
|
|
7
|
+
const graphile_build_1 = require("graphile-build");
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const graphile_simple_inflector_1 = __importDefault(require("graphile-simple-inflector"));
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
const graphile_meta_schema_1 = __importDefault(require("graphile-meta-schema"));
|
|
12
|
+
const postgraphile_plugin_connection_filter_1 = __importDefault(require("postgraphile-plugin-connection-filter"));
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
const postgraphile_plugin_fulltext_filter_1 = __importDefault(require("@pyramation/postgraphile-plugin-fulltext-filter"));
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
const postgraphile_derived_upload_field_1 = __importDefault(require("postgraphile-derived-upload-field"));
|
|
17
|
+
const graphile_i18n_1 = require("graphile-i18n");
|
|
18
|
+
const postgis_1 = __importDefault(require("@pyramation/postgis"));
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const postgraphile_plugin_connection_filter_postgis_1 = __importDefault(require("postgraphile-plugin-connection-filter-postgis"));
|
|
21
|
+
const pg_many_to_many_1 = __importDefault(require("@graphile-contrib/pg-many-to-many"));
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
const graphile_search_plugin_1 = __importDefault(require("graphile-search-plugin"));
|
|
24
|
+
const types_1 = __importDefault(require("./plugins/types"));
|
|
25
|
+
const upload_1 = require("./resolvers/upload");
|
|
26
|
+
const types_2 = require("@launchql/types");
|
|
27
|
+
const getGraphileSettings = (rawOpts) => {
|
|
28
|
+
const opts = (0, types_2.getEnvOptions)(rawOpts);
|
|
29
|
+
const { server, graphile, features, cdn } = opts;
|
|
30
|
+
// Instantiate uploader with merged cdn opts
|
|
31
|
+
const uploader = new upload_1.Uploader({
|
|
32
|
+
bucketName: cdn.bucketName,
|
|
33
|
+
awsRegion: cdn.awsRegion,
|
|
34
|
+
awsAccessKey: cdn.awsAccessKey,
|
|
35
|
+
awsSecretKey: cdn.awsSecretKey,
|
|
36
|
+
minioEndpoint: cdn.minioEndpoint
|
|
37
|
+
});
|
|
38
|
+
const resolveUpload = uploader.resolveUpload.bind(uploader);
|
|
39
|
+
const plugins = [
|
|
40
|
+
postgraphile_plugin_connection_filter_1.default,
|
|
41
|
+
postgraphile_plugin_fulltext_filter_1.default,
|
|
42
|
+
types_1.default,
|
|
43
|
+
postgraphile_derived_upload_field_1.default,
|
|
44
|
+
graphile_meta_schema_1.default,
|
|
45
|
+
pg_many_to_many_1.default,
|
|
46
|
+
graphile_search_plugin_1.default
|
|
47
|
+
];
|
|
48
|
+
if (features?.postgis) {
|
|
49
|
+
plugins.push(postgis_1.default, postgraphile_plugin_connection_filter_postgis_1.default);
|
|
50
|
+
}
|
|
51
|
+
if (features?.simpleInflection) {
|
|
52
|
+
plugins.push(graphile_simple_inflector_1.default);
|
|
53
|
+
}
|
|
54
|
+
plugins.push(graphile_i18n_1.LangPlugin);
|
|
55
|
+
return {
|
|
56
|
+
graphileBuildOptions: {
|
|
57
|
+
uploadFieldDefinitions: [
|
|
58
|
+
{
|
|
59
|
+
name: 'upload',
|
|
60
|
+
namespaceName: 'public',
|
|
61
|
+
type: 'JSON',
|
|
62
|
+
resolve: resolveUpload
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'attachment',
|
|
66
|
+
namespaceName: 'public',
|
|
67
|
+
type: 'String',
|
|
68
|
+
resolve: resolveUpload
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'image',
|
|
72
|
+
namespaceName: 'public',
|
|
73
|
+
type: 'JSON',
|
|
74
|
+
resolve: resolveUpload
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
tag: 'upload',
|
|
78
|
+
resolve: resolveUpload
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
pgSimplifyOppositeBaseNames: features?.oppositeBaseNames,
|
|
82
|
+
connectionFilterComputedColumns: false
|
|
83
|
+
},
|
|
84
|
+
appendPlugins: plugins,
|
|
85
|
+
skipPlugins: [graphile_build_1.NodePlugin],
|
|
86
|
+
dynamicJson: true,
|
|
87
|
+
disableGraphiql: false,
|
|
88
|
+
enhanceGraphiql: true,
|
|
89
|
+
enableQueryBatching: true,
|
|
90
|
+
graphiql: true,
|
|
91
|
+
watch: false,
|
|
92
|
+
port: server?.port,
|
|
93
|
+
host: server?.host,
|
|
94
|
+
schema: graphile?.schema,
|
|
95
|
+
ignoreRBAC: false,
|
|
96
|
+
legacyRelations: 'omit',
|
|
97
|
+
showErrorStack: false,
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
extendedErrors: false,
|
|
100
|
+
disableQueryLog: false,
|
|
101
|
+
includeExtensionResources: true,
|
|
102
|
+
setofFunctionsContainNulls: false,
|
|
103
|
+
retryOnInitFail: async (_error) => {
|
|
104
|
+
return false;
|
|
105
|
+
},
|
|
106
|
+
additionalGraphQLContextFromRequest: (req, res) => ({
|
|
107
|
+
...(0, graphile_i18n_1.additionalGraphQLContextFromRequest)(req, res),
|
|
108
|
+
req,
|
|
109
|
+
res
|
|
110
|
+
})
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
exports.getGraphileSettings = getGraphileSettings;
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "graphile-settings",
|
|
3
|
+
"version": "2.1.7",
|
|
4
|
+
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
|
+
"description": "graphile settings",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"homepage": "https://github.com/launchql/launchql",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"directory": "dist"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/launchql/launchql"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/launchql/launchql/issues"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
|
|
24
|
+
"clean": "rimraf dist/**",
|
|
25
|
+
"prepare": "npm run build",
|
|
26
|
+
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
|
|
27
|
+
"build:dev": "npm run clean; tsc --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
|
|
28
|
+
"lint": "eslint . --fix",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"test:watch": "jest --watch"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@graphile-contrib/pg-many-to-many": "^1.0.2",
|
|
34
|
+
"@launchql/types": "^2.1.5",
|
|
35
|
+
"@launchql/upload-names": "^2.1.3",
|
|
36
|
+
"@pyramation/postgis": "^0.1.1",
|
|
37
|
+
"@pyramation/postgraphile-plugin-fulltext-filter": "^2.0.0",
|
|
38
|
+
"cors": "^2.8.5",
|
|
39
|
+
"express": "^5.1.0",
|
|
40
|
+
"graphile-build": "^4.14.1",
|
|
41
|
+
"graphile-i18n": "^0.0.3",
|
|
42
|
+
"graphile-meta-schema": "^0.2.5",
|
|
43
|
+
"graphile-query": "^2.1.5",
|
|
44
|
+
"graphile-search-plugin": "^0.1.2",
|
|
45
|
+
"graphile-settings": "^2.1.7",
|
|
46
|
+
"graphile-simple-inflector": "^0.1.1",
|
|
47
|
+
"graphql-tag": "2.12.6",
|
|
48
|
+
"lru-cache": "^11.1.0",
|
|
49
|
+
"pg": "^8.16.0",
|
|
50
|
+
"postgraphile": "^4.14.1",
|
|
51
|
+
"postgraphile-derived-upload-field": "^0.0.6",
|
|
52
|
+
"postgraphile-plugin-connection-filter": "^2.3.0",
|
|
53
|
+
"postgraphile-plugin-connection-filter-postgis": "^1.0.0-alpha.6",
|
|
54
|
+
"request-ip": "^3.3.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/cors": "^2.8.17",
|
|
58
|
+
"@types/express": "^5.0.1",
|
|
59
|
+
"@types/pg": "^8.15.2",
|
|
60
|
+
"@types/request-ip": "^0.0.41",
|
|
61
|
+
"@types/rimraf": "^4.0.5",
|
|
62
|
+
"nodemon": "^3.1.10",
|
|
63
|
+
"ts-node": "^10.9.2"
|
|
64
|
+
},
|
|
65
|
+
"gitHead": "8a638ef47a175c964a63431017d83587e62efbb8"
|
|
66
|
+
}
|
package/plugins/types.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// formerly lql-types.js
|
|
4
|
+
const CustomPgTypeMappingsPlugin = builder => {
|
|
5
|
+
builder.hook('build', (build, _context) => {
|
|
6
|
+
const customMappings = [
|
|
7
|
+
{ name: 'geolocation', namespaceName: 'public', type: 'GeoJSON' },
|
|
8
|
+
{ name: 'geopolygon', namespaceName: 'public', type: 'GeoJSON' },
|
|
9
|
+
{ name: 'email', namespaceName: 'public', type: 'String' },
|
|
10
|
+
{ name: 'hostname', namespaceName: 'public', type: 'String' },
|
|
11
|
+
{ name: 'multiple_select', namespaceName: 'public', type: 'JSON' },
|
|
12
|
+
{ name: 'single_select', namespaceName: 'public', type: 'JSON' },
|
|
13
|
+
{ name: 'origin', namespaceName: 'public', type: 'String' },
|
|
14
|
+
{ name: 'url', namespaceName: 'public', type: 'String' },
|
|
15
|
+
];
|
|
16
|
+
for (const { name, namespaceName, type } of customMappings) {
|
|
17
|
+
const pgType = build.pgIntrospectionResultsByKind.type.find(
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
t => t.name === name && t.namespaceName === namespaceName);
|
|
20
|
+
if (pgType) {
|
|
21
|
+
build.pgRegisterGqlTypeByTypeId(pgType.id, () => {
|
|
22
|
+
const gqlType = build.getTypeByName(type);
|
|
23
|
+
if (!gqlType) {
|
|
24
|
+
throw new Error(`Unknown GraphQL type: ${type}`);
|
|
25
|
+
}
|
|
26
|
+
return gqlType;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return build;
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.default = CustomPgTypeMappingsPlugin;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface UploaderOptions {
|
|
2
|
+
bucketName: string;
|
|
3
|
+
awsRegion: string;
|
|
4
|
+
awsSecretKey: string;
|
|
5
|
+
awsAccessKey: string;
|
|
6
|
+
minioEndpoint?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class Uploader {
|
|
9
|
+
private opts;
|
|
10
|
+
private streamerInstance;
|
|
11
|
+
constructor(opts: UploaderOptions);
|
|
12
|
+
resolveUpload(upload: any, _args: any, _context: any, info: any): Promise<any>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Uploader = void 0;
|
|
7
|
+
const s3_streamer_1 = __importDefault(require("@launchql/s3-streamer"));
|
|
8
|
+
const upload_names_1 = __importDefault(require("@launchql/upload-names"));
|
|
9
|
+
class Uploader {
|
|
10
|
+
opts;
|
|
11
|
+
streamerInstance;
|
|
12
|
+
constructor(opts) {
|
|
13
|
+
this.opts = opts;
|
|
14
|
+
const { bucketName, awsRegion, awsSecretKey, awsAccessKey, minioEndpoint } = this.opts;
|
|
15
|
+
this.streamerInstance = new s3_streamer_1.default({
|
|
16
|
+
defaultBucket: bucketName,
|
|
17
|
+
awsRegion,
|
|
18
|
+
awsSecretKey,
|
|
19
|
+
awsAccessKey,
|
|
20
|
+
minioEndpoint,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async resolveUpload(upload, _args, _context, info) {
|
|
24
|
+
const { uploadPlugin: { tags, type } } = info;
|
|
25
|
+
const readStream = upload.createReadStream();
|
|
26
|
+
const { filename } = upload;
|
|
27
|
+
const rand = Math.random().toString(36).substring(2, 7) +
|
|
28
|
+
Math.random().toString(36).substring(2, 7);
|
|
29
|
+
const key = `${rand}-${(0, upload_names_1.default)(filename)}`;
|
|
30
|
+
const result = await this.streamerInstance.upload({
|
|
31
|
+
readStream,
|
|
32
|
+
filename,
|
|
33
|
+
key,
|
|
34
|
+
bucket: this.opts.bucketName
|
|
35
|
+
});
|
|
36
|
+
const url = result.upload.Location;
|
|
37
|
+
const { contentType, magic: { charset } } = result;
|
|
38
|
+
const typ = type || tags.type;
|
|
39
|
+
const allowedMimes = tags.mime
|
|
40
|
+
? tags.mime.trim().split(',').map((a) => a.trim())
|
|
41
|
+
: typ === 'image'
|
|
42
|
+
? ['image/jpg', 'image/jpeg', 'image/png', 'image/svg+xml']
|
|
43
|
+
: [];
|
|
44
|
+
if (allowedMimes.length && !allowedMimes.includes(contentType)) {
|
|
45
|
+
throw new Error(`UPLOAD_MIMETYPE ${allowedMimes.join(',')}`);
|
|
46
|
+
}
|
|
47
|
+
switch (typ) {
|
|
48
|
+
case 'image':
|
|
49
|
+
case 'upload':
|
|
50
|
+
return {
|
|
51
|
+
filename,
|
|
52
|
+
mime: contentType,
|
|
53
|
+
url
|
|
54
|
+
};
|
|
55
|
+
case 'attachment':
|
|
56
|
+
default:
|
|
57
|
+
return url;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.Uploader = Uploader;
|