@graphql-mesh/postgraphile 1.0.0-alpha-3fc47d119.0 → 1.0.0-alpha-20230420181317-a95037648
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/{index.js → cjs/index.js} +39 -49
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +19 -10
- package/package.json +29 -22
- package/typings/index.d.cts +12 -0
- package/{index.d.ts → typings/index.d.ts} +2 -2
|
@@ -1,43 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
n['default'] = e;
|
|
20
|
-
return n;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const postgraphile = require('postgraphile');
|
|
25
|
-
const postgraphileCore = require('postgraphile-core');
|
|
26
|
-
const pg = _interopDefault(require('pg'));
|
|
27
|
-
const crossHelpers = require('@graphql-mesh/cross-helpers');
|
|
28
|
-
const os = require('os');
|
|
29
|
-
const stringInterpolation = require('@graphql-mesh/string-interpolation');
|
|
30
|
-
const utils = require('@graphql-mesh/utils');
|
|
31
|
-
const store = require('@graphql-mesh/store');
|
|
32
|
-
const delegate = require('@graphql-tools/delegate');
|
|
33
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5
|
+
// eslint-disable-next-line import/no-nodejs-modules
|
|
6
|
+
const os_1 = require("os");
|
|
7
|
+
const pg_1 = tslib_1.__importDefault(require("pg"));
|
|
8
|
+
const postgraphile_1 = require("postgraphile");
|
|
9
|
+
const postgraphile_core_1 = require("postgraphile-core");
|
|
10
|
+
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
11
|
+
const store_1 = require("@graphql-mesh/store");
|
|
12
|
+
const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
|
|
13
|
+
const utils_1 = require("@graphql-mesh/utils");
|
|
14
|
+
const delegate_1 = require("@graphql-tools/delegate");
|
|
34
15
|
class PostGraphileHandler {
|
|
35
|
-
constructor({ name, config, baseDir, pubsub, store
|
|
16
|
+
constructor({ name, config, baseDir, pubsub, store, logger, importFn, }) {
|
|
36
17
|
this.name = name;
|
|
37
18
|
this.config = config;
|
|
38
19
|
this.baseDir = baseDir;
|
|
39
20
|
this.pubsub = pubsub;
|
|
40
|
-
this.pgCache = store
|
|
21
|
+
this.pgCache = store.proxy('pgCache.json', store_1.PredefinedProxyOptions.JsonWithoutValidation);
|
|
41
22
|
this.logger = logger;
|
|
42
23
|
this.importFn = importFn;
|
|
43
24
|
}
|
|
@@ -45,7 +26,7 @@ class PostGraphileHandler {
|
|
|
45
26
|
var _a, _b;
|
|
46
27
|
let pgPool;
|
|
47
28
|
if (typeof ((_a = this.config) === null || _a === void 0 ? void 0 : _a.pool) === 'string') {
|
|
48
|
-
pgPool = await
|
|
29
|
+
pgPool = await (0, utils_1.loadFromModuleExportExpression)(this.config.pool, {
|
|
49
30
|
cwd: this.baseDir,
|
|
50
31
|
importFn: this.importFn,
|
|
51
32
|
defaultExportName: 'default',
|
|
@@ -53,8 +34,10 @@ class PostGraphileHandler {
|
|
|
53
34
|
}
|
|
54
35
|
if (!pgPool || !('connect' in pgPool)) {
|
|
55
36
|
const pgLogger = this.logger.child('PostgreSQL');
|
|
56
|
-
pgPool = new
|
|
57
|
-
connectionString:
|
|
37
|
+
pgPool = new pg_1.default.Pool({
|
|
38
|
+
connectionString: string_interpolation_1.stringInterpolator.parse(this.config.connectionString, {
|
|
39
|
+
env: cross_helpers_1.process.env,
|
|
40
|
+
}),
|
|
58
41
|
log: messages => pgLogger.debug(messages),
|
|
59
42
|
...(_b = this.config) === null || _b === void 0 ? void 0 : _b.pool,
|
|
60
43
|
});
|
|
@@ -65,25 +48,25 @@ class PostGraphileHandler {
|
|
|
65
48
|
pgPool.end();
|
|
66
49
|
});
|
|
67
50
|
const cacheKey = this.name + '_introspection.json';
|
|
68
|
-
const dummyCacheFilePath =
|
|
51
|
+
const dummyCacheFilePath = cross_helpers_1.path.join((0, os_1.tmpdir)(), cacheKey);
|
|
69
52
|
let cachedIntrospection = await this.pgCache.get();
|
|
70
53
|
let writeCache;
|
|
71
|
-
const appendPlugins = await Promise.all((this.config.appendPlugins || []).map(pluginName =>
|
|
54
|
+
const appendPlugins = await Promise.all((this.config.appendPlugins || []).map(pluginName => (0, utils_1.loadFromModuleExportExpression)(pluginName, {
|
|
72
55
|
cwd: this.baseDir,
|
|
73
56
|
importFn: this.importFn,
|
|
74
57
|
defaultExportName: 'default',
|
|
75
58
|
})));
|
|
76
|
-
const skipPlugins = await Promise.all((this.config.skipPlugins || []).map(pluginName =>
|
|
59
|
+
const skipPlugins = await Promise.all((this.config.skipPlugins || []).map(pluginName => (0, utils_1.loadFromModuleExportExpression)(pluginName, {
|
|
77
60
|
cwd: this.baseDir,
|
|
78
61
|
importFn: this.importFn,
|
|
79
62
|
defaultExportName: 'default',
|
|
80
63
|
})));
|
|
81
|
-
const options = await
|
|
64
|
+
const options = await (0, utils_1.loadFromModuleExportExpression)(this.config.options, {
|
|
82
65
|
cwd: this.baseDir,
|
|
83
66
|
importFn: this.importFn,
|
|
84
67
|
defaultExportName: 'default',
|
|
85
68
|
});
|
|
86
|
-
const builder = await
|
|
69
|
+
const builder = await (0, postgraphile_core_1.getPostGraphileBuilder)(pgPool, this.config.schemaName || 'public', {
|
|
87
70
|
dynamicJson: true,
|
|
88
71
|
subscriptions: 'subscriptions' in this.config ? this.config.subscriptions : true,
|
|
89
72
|
live: 'live' in this.config ? this.config.live : true,
|
|
@@ -98,20 +81,28 @@ class PostGraphileHandler {
|
|
|
98
81
|
...options,
|
|
99
82
|
});
|
|
100
83
|
const schema = builder.buildSchema();
|
|
101
|
-
const defaultExecutor =
|
|
84
|
+
const defaultExecutor = (0, delegate_1.createDefaultExecutor)(schema);
|
|
102
85
|
if (!cachedIntrospection) {
|
|
103
86
|
await writeCache();
|
|
104
|
-
cachedIntrospection = await
|
|
87
|
+
cachedIntrospection = await Promise.resolve(`${dummyCacheFilePath}`).then(s => tslib_1.__importStar(require(s)));
|
|
105
88
|
await this.pgCache.set(cachedIntrospection);
|
|
106
89
|
}
|
|
90
|
+
let contextOptions = await (0, utils_1.loadFromModuleExportExpression)(this.config.contextOptions, {
|
|
91
|
+
cwd: this.baseDir,
|
|
92
|
+
importFn: this.importFn,
|
|
93
|
+
defaultExportName: 'default',
|
|
94
|
+
});
|
|
95
|
+
if (typeof contextOptions !== 'function')
|
|
96
|
+
contextOptions = () => ({});
|
|
107
97
|
return {
|
|
108
98
|
schema,
|
|
109
|
-
executor({ document, variables, context: meshContext, rootValue, operationName, extensions }) {
|
|
110
|
-
return
|
|
99
|
+
executor({ document, variables, context: meshContext, rootValue, operationName, extensions, }) {
|
|
100
|
+
return (0, postgraphile_1.withPostGraphileContext)({
|
|
111
101
|
pgPool,
|
|
112
102
|
queryDocumentAst: document,
|
|
113
103
|
operationName,
|
|
114
104
|
variables,
|
|
105
|
+
...contextOptions(meshContext),
|
|
115
106
|
}, function withPgContextCallback(pgContext) {
|
|
116
107
|
return defaultExecutor({
|
|
117
108
|
document,
|
|
@@ -129,5 +120,4 @@ class PostGraphileHandler {
|
|
|
129
120
|
};
|
|
130
121
|
}
|
|
131
122
|
}
|
|
132
|
-
|
|
133
|
-
module.exports = PostGraphileHandler;
|
|
123
|
+
exports.default = PostGraphileHandler;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
// eslint-disable-next-line import/no-nodejs-modules
|
|
3
|
+
import { tmpdir } from 'os';
|
|
4
|
+
import pg from 'pg';
|
|
1
5
|
import { withPostGraphileContext } from 'postgraphile';
|
|
2
6
|
import { getPostGraphileBuilder } from 'postgraphile-core';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { tmpdir } from 'os';
|
|
7
|
+
import { path, process } from '@graphql-mesh/cross-helpers';
|
|
8
|
+
import { PredefinedProxyOptions } from '@graphql-mesh/store';
|
|
6
9
|
import { stringInterpolator } from '@graphql-mesh/string-interpolation';
|
|
7
10
|
import { loadFromModuleExportExpression } from '@graphql-mesh/utils';
|
|
8
|
-
import { PredefinedProxyOptions } from '@graphql-mesh/store';
|
|
9
11
|
import { createDefaultExecutor } from '@graphql-tools/delegate';
|
|
10
|
-
|
|
11
|
-
class PostGraphileHandler {
|
|
12
|
+
export default class PostGraphileHandler {
|
|
12
13
|
constructor({ name, config, baseDir, pubsub, store, logger, importFn, }) {
|
|
13
14
|
this.name = name;
|
|
14
15
|
this.config = config;
|
|
@@ -31,7 +32,9 @@ class PostGraphileHandler {
|
|
|
31
32
|
if (!pgPool || !('connect' in pgPool)) {
|
|
32
33
|
const pgLogger = this.logger.child('PostgreSQL');
|
|
33
34
|
pgPool = new pg.Pool({
|
|
34
|
-
connectionString: stringInterpolator.parse(this.config.connectionString, {
|
|
35
|
+
connectionString: stringInterpolator.parse(this.config.connectionString, {
|
|
36
|
+
env: process.env,
|
|
37
|
+
}),
|
|
35
38
|
log: messages => pgLogger.debug(messages),
|
|
36
39
|
...(_b = this.config) === null || _b === void 0 ? void 0 : _b.pool,
|
|
37
40
|
});
|
|
@@ -81,14 +84,22 @@ class PostGraphileHandler {
|
|
|
81
84
|
cachedIntrospection = await import(dummyCacheFilePath);
|
|
82
85
|
await this.pgCache.set(cachedIntrospection);
|
|
83
86
|
}
|
|
87
|
+
let contextOptions = await loadFromModuleExportExpression(this.config.contextOptions, {
|
|
88
|
+
cwd: this.baseDir,
|
|
89
|
+
importFn: this.importFn,
|
|
90
|
+
defaultExportName: 'default',
|
|
91
|
+
});
|
|
92
|
+
if (typeof contextOptions !== 'function')
|
|
93
|
+
contextOptions = () => ({});
|
|
84
94
|
return {
|
|
85
95
|
schema,
|
|
86
|
-
executor({ document, variables, context: meshContext, rootValue, operationName, extensions }) {
|
|
96
|
+
executor({ document, variables, context: meshContext, rootValue, operationName, extensions, }) {
|
|
87
97
|
return withPostGraphileContext({
|
|
88
98
|
pgPool,
|
|
89
99
|
queryDocumentAst: document,
|
|
90
100
|
operationName,
|
|
91
101
|
variables,
|
|
102
|
+
...contextOptions(meshContext),
|
|
92
103
|
}, function withPgContextCallback(pgContext) {
|
|
93
104
|
return defaultExecutor({
|
|
94
105
|
document,
|
|
@@ -106,5 +117,3 @@ class PostGraphileHandler {
|
|
|
106
117
|
};
|
|
107
118
|
}
|
|
108
119
|
}
|
|
109
|
-
|
|
110
|
-
export default PostGraphileHandler;
|
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/postgraphile",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230420181317-a95037648",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/
|
|
7
|
-
"@graphql-mesh/
|
|
8
|
-
"graphql": "
|
|
6
|
+
"@graphql-mesh/cross-helpers": "^0.3.4",
|
|
7
|
+
"@graphql-mesh/store": "1.0.0-alpha-20230420181317-a95037648",
|
|
8
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230420181317-a95037648",
|
|
9
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230420181317-a95037648",
|
|
10
|
+
"graphql": "*",
|
|
11
|
+
"tslib": "^2.4.0"
|
|
9
12
|
},
|
|
10
13
|
"dependencies": {
|
|
11
|
-
"@graphql-mesh/
|
|
12
|
-
"@graphql-
|
|
13
|
-
"@graphql-mesh/string-interpolation": "0.3.0",
|
|
14
|
-
"@graphql-tools/delegate": "8.8.0",
|
|
14
|
+
"@graphql-mesh/string-interpolation": "0.4.4",
|
|
15
|
+
"@graphql-tools/delegate": "9.0.32",
|
|
15
16
|
"pg": "^8.6.0",
|
|
16
|
-
"postgraphile": "4.
|
|
17
|
-
"postgraphile-core": "4.
|
|
18
|
-
"tslib": "^2.4.0"
|
|
17
|
+
"postgraphile": "4.13.0",
|
|
18
|
+
"postgraphile-core": "4.13.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
@@ -23,21 +23,28 @@
|
|
|
23
23
|
"directory": "packages/handlers/postgraphile"
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
|
-
"main": "index.js",
|
|
27
|
-
"module": "index.
|
|
28
|
-
"typings": "index.d.ts",
|
|
26
|
+
"main": "cjs/index.js",
|
|
27
|
+
"module": "esm/index.js",
|
|
28
|
+
"typings": "typings/index.d.ts",
|
|
29
29
|
"typescript": {
|
|
30
|
-
"definition": "index.d.ts"
|
|
30
|
+
"definition": "typings/index.d.ts"
|
|
31
31
|
},
|
|
32
|
+
"type": "module",
|
|
32
33
|
"exports": {
|
|
33
34
|
".": {
|
|
34
|
-
"require":
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./typings/index.d.cts",
|
|
37
|
+
"default": "./cjs/index.js"
|
|
38
|
+
},
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./typings/index.d.ts",
|
|
41
|
+
"default": "./esm/index.js"
|
|
42
|
+
},
|
|
43
|
+
"default": {
|
|
44
|
+
"types": "./typings/index.d.ts",
|
|
45
|
+
"default": "./esm/index.js"
|
|
46
|
+
}
|
|
40
47
|
},
|
|
41
48
|
"./package.json": "./package.json"
|
|
42
49
|
}
|
|
43
|
-
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
|
|
2
|
+
export default class PostGraphileHandler implements MeshHandler {
|
|
3
|
+
private name;
|
|
4
|
+
private config;
|
|
5
|
+
private baseDir;
|
|
6
|
+
private pubsub;
|
|
7
|
+
private pgCache;
|
|
8
|
+
private logger;
|
|
9
|
+
private importFn;
|
|
10
|
+
constructor({ name, config, baseDir, pubsub, store, logger, importFn, }: MeshHandlerOptions<YamlConfig.PostGraphileHandler>);
|
|
11
|
+
getMeshSource(): Promise<MeshSource>;
|
|
12
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
|
|
2
2
|
export default class PostGraphileHandler implements MeshHandler {
|
|
3
3
|
private name;
|
|
4
4
|
private config;
|
|
@@ -7,6 +7,6 @@ export default class PostGraphileHandler implements MeshHandler {
|
|
|
7
7
|
private pgCache;
|
|
8
8
|
private logger;
|
|
9
9
|
private importFn;
|
|
10
|
-
constructor({ name, config, baseDir, pubsub, store, logger, importFn, }:
|
|
10
|
+
constructor({ name, config, baseDir, pubsub, store, logger, importFn, }: MeshHandlerOptions<YamlConfig.PostGraphileHandler>);
|
|
11
11
|
getMeshSource(): Promise<MeshSource>;
|
|
12
12
|
}
|