graphile-test 0.1.1 → 2.0.1
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 +1 -1
- package/README.md +66 -39
- package/clean.d.ts +9 -0
- package/clean.js +67 -0
- package/esm/clean.js +57 -0
- package/esm/graphile-test.js +172 -0
- package/esm/index.js +2 -0
- package/graphile-test.d.ts +12 -0
- package/graphile-test.js +179 -0
- package/index.d.ts +2 -0
- package/index.js +18 -0
- package/package.json +30 -58
- package/main/clean.js +0 -104
- package/main/env.js +0 -28
- package/main/gql.js +0 -15
- package/main/graphql.js +0 -346
- package/main/index.js +0 -53
- package/module/clean.js +0 -46
- package/module/env.js +0 -19
- package/module/gql.js +0 -2
- package/module/graphql.js +0 -152
- package/module/index.js +0 -4
package/package.json
CHANGED
|
@@ -1,73 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-test",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "PostGraphile Testing",
|
|
3
|
+
"version": "2.0.1",
|
|
5
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
|
-
"
|
|
5
|
+
"description": "PostGraphile Testing",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"homepage": "https://github.com/launchql/launchql",
|
|
7
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
8
|
-
"main": "main/index.js",
|
|
9
|
-
"module": "module/index.js",
|
|
10
|
-
"directories": {
|
|
11
|
-
"lib": "src",
|
|
12
|
-
"test": "__tests__"
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"main",
|
|
16
|
-
"module"
|
|
17
|
-
],
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build:main": "BABEL_ENV=production babel src --out-dir main --delete-dir-on-start",
|
|
20
|
-
"build:module": "MODULE=true babel src --out-dir module --delete-dir-on-start",
|
|
21
|
-
"build": "npm run build:module && npm run build:main",
|
|
22
|
-
"prepublish": "npm run build",
|
|
23
|
-
"lint": "eslint src --fix",
|
|
24
|
-
"test": "jest",
|
|
25
|
-
"test:watch": "jest --watch",
|
|
26
|
-
"test:debug": "node --inspect node_modules/.bin/jest --runInBand"
|
|
27
|
-
},
|
|
28
11
|
"publishConfig": {
|
|
29
|
-
"access": "public"
|
|
12
|
+
"access": "public",
|
|
13
|
+
"directory": "dist"
|
|
30
14
|
},
|
|
31
15
|
"repository": {
|
|
32
16
|
"type": "git",
|
|
33
|
-
"url": "https://github.com/
|
|
17
|
+
"url": "https://github.com/launchql/launchql"
|
|
34
18
|
},
|
|
35
|
-
"keywords": [
|
|
36
|
-
"postgraphile",
|
|
37
|
-
"graphile",
|
|
38
|
-
"postgres",
|
|
39
|
-
"graphql",
|
|
40
|
-
"testing"
|
|
41
|
-
],
|
|
42
19
|
"bugs": {
|
|
43
|
-
"url": "https://github.com/
|
|
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"
|
|
44
31
|
},
|
|
45
32
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
48
|
-
"@babel/plugin-proposal-class-properties": "7.8.3",
|
|
49
|
-
"@babel/plugin-proposal-export-default-from": "7.8.3",
|
|
50
|
-
"@babel/plugin-proposal-object-rest-spread": "7.9.6",
|
|
51
|
-
"@babel/plugin-transform-runtime": "7.9.6",
|
|
52
|
-
"@babel/preset-env": "7.9.6",
|
|
53
|
-
"babel-core": "7.0.0-bridge.0",
|
|
54
|
-
"babel-eslint": "10.0.3",
|
|
55
|
-
"babel-jest": "25.1.0",
|
|
56
|
-
"eslint": "6.8.0",
|
|
57
|
-
"eslint-config-prettier": "^6.10.0",
|
|
58
|
-
"eslint-plugin-prettier": "^3.1.2",
|
|
59
|
-
"jest": "^24.5.0",
|
|
60
|
-
"jest-in-case": "^1.0.2",
|
|
61
|
-
"prettier": "^1.19.1",
|
|
62
|
-
"regenerator-runtime": "^0.13.2"
|
|
33
|
+
"@types/pg": "^8.11.10",
|
|
34
|
+
"graphql-tag": "2.12.6"
|
|
63
35
|
},
|
|
64
36
|
"dependencies": {
|
|
65
|
-
"@
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
37
|
+
"@launchql/graphile-settings": "^2.0.5",
|
|
38
|
+
"@launchql/types": "^2.0.5",
|
|
39
|
+
"graphql": "^15.5.2",
|
|
40
|
+
"mock-req": "^0.2.0",
|
|
41
|
+
"pg": "^8.15.6",
|
|
42
|
+
"postgraphile": "^4.14.1"
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "77a8acdaa9513791b3bb47b11dcfc3b141d856ab"
|
|
73
45
|
}
|
package/main/clean.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.snapshot = exports.prune = exports.pruneHashes = exports.pruneUUIDs = exports.pruneIdArrays = exports.pruneIds = exports.pruneDates = void 0;
|
|
9
|
-
|
|
10
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
-
|
|
12
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
-
|
|
14
|
-
// Thanks Graphile again!
|
|
15
|
-
// https://github.com/graphile/starter/blob/ce3c683ee19d4c92444431324b76941347fd85db/%40app/db/__tests__/helpers.ts#L46-L76
|
|
16
|
-
var uuidRegexp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
17
|
-
|
|
18
|
-
var idReplacement = function idReplacement(v) {
|
|
19
|
-
return !v ? v : '[ID]';
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
var pruneDates = function pruneDates(row) {
|
|
23
|
-
return mapValues(row, function (v, k) {
|
|
24
|
-
if (!v) {
|
|
25
|
-
return v;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (v instanceof Date) {
|
|
29
|
-
return '[DATE]';
|
|
30
|
-
} else if (typeof v === 'string' && k.match(/(_at|At)$/) && v.match(/^20[0-9]{2}-[0-9]{2}-[0-9]{2}/)) {
|
|
31
|
-
return '[DATE]';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return v;
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
exports.pruneDates = pruneDates;
|
|
39
|
-
|
|
40
|
-
var mapValues = function mapValues(objs, fn) {
|
|
41
|
-
return Object.entries(objs).reduce(function (a, _ref) {
|
|
42
|
-
var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
|
|
43
|
-
key = _ref2[0],
|
|
44
|
-
value = _ref2[1];
|
|
45
|
-
|
|
46
|
-
a[key] = fn(value, key);
|
|
47
|
-
return a;
|
|
48
|
-
}, {});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
var pruneIds = function pruneIds(row) {
|
|
52
|
-
return mapValues(row, function (v, k) {
|
|
53
|
-
return (k === 'id' || k.endsWith('_id')) && (typeof v === 'string' || typeof v === 'number') ? idReplacement(v) : v;
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
exports.pruneIds = pruneIds;
|
|
58
|
-
|
|
59
|
-
var pruneIdArrays = function pruneIdArrays(row) {
|
|
60
|
-
return mapValues(row, function (v, k) {
|
|
61
|
-
return k.endsWith('_ids') && Array.isArray(v) ? "[UUIDs-".concat(v.length, "]") : v;
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
exports.pruneIdArrays = pruneIdArrays;
|
|
66
|
-
|
|
67
|
-
var pruneUUIDs = function pruneUUIDs(row) {
|
|
68
|
-
return mapValues(row, function (v, k) {
|
|
69
|
-
if (typeof v !== 'string') {
|
|
70
|
-
return v;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
var val = v;
|
|
74
|
-
return ['uuid', 'queue_name'].includes(k) && v.match(uuidRegexp) ? '[UUID]' : k === 'gravatar' && val.match(/^[0-9a-f]{32}$/i) ? '[gUUID]' : v;
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
exports.pruneUUIDs = pruneUUIDs;
|
|
79
|
-
|
|
80
|
-
var pruneHashes = function pruneHashes(row) {
|
|
81
|
-
return mapValues(row, function (v, k) {
|
|
82
|
-
return k.endsWith('_hash') && typeof v === 'string' && v[0] === '$' ? '[hash]' : v;
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
exports.pruneHashes = pruneHashes;
|
|
87
|
-
|
|
88
|
-
var prune = function prune(obj) {
|
|
89
|
-
return pruneHashes(pruneUUIDs(pruneIds(pruneIdArrays(pruneDates(obj)))));
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
exports.prune = prune;
|
|
93
|
-
|
|
94
|
-
var snapshot = function snapshot(obj) {
|
|
95
|
-
if (Array.isArray(obj)) {
|
|
96
|
-
return obj.map(snapshot);
|
|
97
|
-
} else if (obj && (0, _typeof2["default"])(obj) === 'object') {
|
|
98
|
-
return mapValues(prune(obj), snapshot);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return obj;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
exports.snapshot = snapshot;
|
package/main/env.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.env = void 0;
|
|
7
|
-
|
|
8
|
-
var _envalid = require("envalid");
|
|
9
|
-
|
|
10
|
-
var env = (0, _envalid.cleanEnv)(process.env, {
|
|
11
|
-
PGUSER: (0, _envalid.str)({
|
|
12
|
-
"default": 'postgres'
|
|
13
|
-
}),
|
|
14
|
-
PGHOST: (0, _envalid.str)({
|
|
15
|
-
"default": 'localhost'
|
|
16
|
-
}),
|
|
17
|
-
PGPASSWORD: (0, _envalid.str)({
|
|
18
|
-
"default": 'password'
|
|
19
|
-
}),
|
|
20
|
-
PGPORT: (0, _envalid.port)({
|
|
21
|
-
"default": 5432
|
|
22
|
-
}),
|
|
23
|
-
PGDATABASE: (0, _envalid.str)(),
|
|
24
|
-
SCHEMA: (0, _envalid.str)()
|
|
25
|
-
}, {
|
|
26
|
-
dotEnvPath: null
|
|
27
|
-
});
|
|
28
|
-
exports.env = env;
|
package/main/gql.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
Object.defineProperty(exports, "gql", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function get() {
|
|
11
|
-
return _graphqlTag["default"];
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
package/main/graphql.js
DELETED
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.GraphQLTest = void 0;
|
|
9
|
-
|
|
10
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
-
|
|
12
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
13
|
-
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
17
|
-
|
|
18
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
19
|
-
|
|
20
|
-
var _pg = _interopRequireDefault(require("pg"));
|
|
21
|
-
|
|
22
|
-
var _postgraphile = require("postgraphile");
|
|
23
|
-
|
|
24
|
-
var _graphql = require("graphql");
|
|
25
|
-
|
|
26
|
-
var _mockReq = _interopRequireDefault(require("mock-req"));
|
|
27
|
-
|
|
28
|
-
var _printer = require("graphql/language/printer");
|
|
29
|
-
|
|
30
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
31
|
-
|
|
32
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
33
|
-
|
|
34
|
-
var GraphQLTest = function GraphQLTest(options, connectionString) {
|
|
35
|
-
_pg["default"].defaults.poolSize = 1; // This is the role that your normal PostGraphile connection string would use,
|
|
36
|
-
// e.g. `postgres://POSTGRAPHILE_AUTHENTICATOR_ROLE:password@host/db`
|
|
37
|
-
|
|
38
|
-
var POSTGRAPHILE_AUTHENTICATOR_ROLE = 'authenticated'; // Contains the PostGraphile schema and rootPgPool
|
|
39
|
-
|
|
40
|
-
var ctx;
|
|
41
|
-
|
|
42
|
-
var setup = /*#__PURE__*/function () {
|
|
43
|
-
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
44
|
-
var rootPgPool, schema;
|
|
45
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
46
|
-
while (1) {
|
|
47
|
-
switch (_context.prev = _context.next) {
|
|
48
|
-
case 0:
|
|
49
|
-
rootPgPool = new _pg["default"].Pool({
|
|
50
|
-
connectionString: connectionString
|
|
51
|
-
});
|
|
52
|
-
_context.next = 3;
|
|
53
|
-
return (0, _postgraphile.createPostGraphileSchema)(rootPgPool, options.schema, options);
|
|
54
|
-
|
|
55
|
-
case 3:
|
|
56
|
-
schema = _context.sent;
|
|
57
|
-
// Store the context
|
|
58
|
-
ctx = {
|
|
59
|
-
rootPgPool: rootPgPool,
|
|
60
|
-
options: options,
|
|
61
|
-
schema: schema
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
case 5:
|
|
65
|
-
case "end":
|
|
66
|
-
return _context.stop();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}, _callee);
|
|
70
|
-
}));
|
|
71
|
-
|
|
72
|
-
return function setup() {
|
|
73
|
-
return _ref.apply(this, arguments);
|
|
74
|
-
};
|
|
75
|
-
}();
|
|
76
|
-
|
|
77
|
-
var teardown = /*#__PURE__*/function () {
|
|
78
|
-
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
79
|
-
var _ctx, rootPgPool;
|
|
80
|
-
|
|
81
|
-
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
82
|
-
while (1) {
|
|
83
|
-
switch (_context2.prev = _context2.next) {
|
|
84
|
-
case 0:
|
|
85
|
-
_context2.prev = 0;
|
|
86
|
-
|
|
87
|
-
if (ctx) {
|
|
88
|
-
_context2.next = 3;
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return _context2.abrupt("return", null);
|
|
93
|
-
|
|
94
|
-
case 3:
|
|
95
|
-
_ctx = ctx, rootPgPool = _ctx.rootPgPool;
|
|
96
|
-
ctx = null;
|
|
97
|
-
_context2.next = 7;
|
|
98
|
-
return rootPgPool.end();
|
|
99
|
-
|
|
100
|
-
case 7:
|
|
101
|
-
return _context2.abrupt("return", null);
|
|
102
|
-
|
|
103
|
-
case 10:
|
|
104
|
-
_context2.prev = 10;
|
|
105
|
-
_context2.t0 = _context2["catch"](0);
|
|
106
|
-
console.error(_context2.t0); // eslint-disable-line
|
|
107
|
-
|
|
108
|
-
return _context2.abrupt("return", null);
|
|
109
|
-
|
|
110
|
-
case 14:
|
|
111
|
-
case "end":
|
|
112
|
-
return _context2.stop();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}, _callee2, null, [[0, 10]]);
|
|
116
|
-
}));
|
|
117
|
-
|
|
118
|
-
return function teardown() {
|
|
119
|
-
return _ref2.apply(this, arguments);
|
|
120
|
-
};
|
|
121
|
-
}();
|
|
122
|
-
|
|
123
|
-
var graphQL = /*#__PURE__*/function () {
|
|
124
|
-
var _graphQL = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
|
|
125
|
-
var reqOptions,
|
|
126
|
-
checker,
|
|
127
|
-
_ctx2,
|
|
128
|
-
schema,
|
|
129
|
-
rootPgPool,
|
|
130
|
-
options,
|
|
131
|
-
req,
|
|
132
|
-
pgSettingsGenerator,
|
|
133
|
-
pgSettings,
|
|
134
|
-
_args5 = arguments;
|
|
135
|
-
|
|
136
|
-
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
137
|
-
while (1) {
|
|
138
|
-
switch (_context5.prev = _context5.next) {
|
|
139
|
-
case 0:
|
|
140
|
-
// Any additional items to set on `req` (e.g. `{user: {id: 17}}`)
|
|
141
|
-
reqOptions = {}; // Place test assertions in this function
|
|
142
|
-
|
|
143
|
-
checker = function checker() {};
|
|
144
|
-
|
|
145
|
-
if (!(_args5.length === 1)) {
|
|
146
|
-
_context5.next = 6;
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
checker = _args5[0];
|
|
151
|
-
_context5.next = 12;
|
|
152
|
-
break;
|
|
153
|
-
|
|
154
|
-
case 6:
|
|
155
|
-
if (!(_args5.length == 2)) {
|
|
156
|
-
_context5.next = 11;
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
reqOptions = _args5[0];
|
|
161
|
-
checker = _args5[1];
|
|
162
|
-
_context5.next = 12;
|
|
163
|
-
break;
|
|
164
|
-
|
|
165
|
-
case 11:
|
|
166
|
-
throw new Error('no args supplied to graphQL');
|
|
167
|
-
|
|
168
|
-
case 12:
|
|
169
|
-
_ctx2 = ctx, schema = _ctx2.schema, rootPgPool = _ctx2.rootPgPool, options = _ctx2.options;
|
|
170
|
-
req = new _mockReq["default"](_objectSpread({
|
|
171
|
-
url: options.graphqlRoute || '/graphql',
|
|
172
|
-
method: 'POST',
|
|
173
|
-
headers: {
|
|
174
|
-
Accept: 'application/json',
|
|
175
|
-
'Content-Type': 'application/json'
|
|
176
|
-
}
|
|
177
|
-
}, reqOptions));
|
|
178
|
-
pgSettingsGenerator = options.pgSettings;
|
|
179
|
-
|
|
180
|
-
if (!(typeof pgSettingsGenerator === 'function')) {
|
|
181
|
-
_context5.next = 21;
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
_context5.next = 18;
|
|
186
|
-
return pgSettingsGenerator(req);
|
|
187
|
-
|
|
188
|
-
case 18:
|
|
189
|
-
_context5.t0 = _context5.sent;
|
|
190
|
-
_context5.next = 22;
|
|
191
|
-
break;
|
|
192
|
-
|
|
193
|
-
case 21:
|
|
194
|
-
_context5.t0 = pgSettingsGenerator;
|
|
195
|
-
|
|
196
|
-
case 22:
|
|
197
|
-
pgSettings = _context5.t0;
|
|
198
|
-
_context5.next = 25;
|
|
199
|
-
return (0, _postgraphile.withPostGraphileContext)(_objectSpread(_objectSpread({}, options), {}, {
|
|
200
|
-
pgPool: rootPgPool,
|
|
201
|
-
pgSettings: pgSettings
|
|
202
|
-
}), /*#__PURE__*/function () {
|
|
203
|
-
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(context) {
|
|
204
|
-
var replacementPgClient, localSettings, _i, _Object$keys, key, values, sqlQuery, checkResult, query;
|
|
205
|
-
|
|
206
|
-
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
207
|
-
while (1) {
|
|
208
|
-
switch (_context4.prev = _context4.next) {
|
|
209
|
-
case 0:
|
|
210
|
-
_context4.next = 2;
|
|
211
|
-
return rootPgPool.connect();
|
|
212
|
-
|
|
213
|
-
case 2:
|
|
214
|
-
replacementPgClient = _context4.sent;
|
|
215
|
-
_context4.next = 5;
|
|
216
|
-
return replacementPgClient.query('begin');
|
|
217
|
-
|
|
218
|
-
case 5:
|
|
219
|
-
_context4.next = 7;
|
|
220
|
-
return replacementPgClient.query("select set_config('role', $1, true)", [POSTGRAPHILE_AUTHENTICATOR_ROLE]);
|
|
221
|
-
|
|
222
|
-
case 7:
|
|
223
|
-
localSettings = new Map(); // Set the custom provided settings before jwt claims and role are set
|
|
224
|
-
// this prevents an accidentional overwriting
|
|
225
|
-
|
|
226
|
-
if ((0, _typeof2["default"])(pgSettings) === 'object') {
|
|
227
|
-
for (_i = 0, _Object$keys = Object.keys(pgSettings); _i < _Object$keys.length; _i++) {
|
|
228
|
-
key = _Object$keys[_i];
|
|
229
|
-
localSettings.set(key, String(pgSettings[key]));
|
|
230
|
-
}
|
|
231
|
-
} // If there is at least one local setting.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (!(localSettings.size !== 0)) {
|
|
235
|
-
_context4.next = 14;
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Actually create our query.
|
|
240
|
-
values = [];
|
|
241
|
-
sqlQuery = "select ".concat(Array.from(localSettings).map(function (_ref4) {
|
|
242
|
-
var _ref5 = (0, _slicedToArray2["default"])(_ref4, 2),
|
|
243
|
-
key = _ref5[0],
|
|
244
|
-
value = _ref5[1];
|
|
245
|
-
|
|
246
|
-
values.push(key);
|
|
247
|
-
values.push(value);
|
|
248
|
-
return "set_config($".concat(values.length - 1, ", $").concat(values.length, ", true)");
|
|
249
|
-
}).join(', ')); // Execute the query.
|
|
250
|
-
|
|
251
|
-
_context4.next = 14;
|
|
252
|
-
return replacementPgClient.query(sqlQuery, values);
|
|
253
|
-
|
|
254
|
-
case 14:
|
|
255
|
-
_context4.prev = 14;
|
|
256
|
-
|
|
257
|
-
// This runs our GraphQL query, passing the replacement client
|
|
258
|
-
query = /*#__PURE__*/function () {
|
|
259
|
-
var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(q, variables) {
|
|
260
|
-
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
261
|
-
while (1) {
|
|
262
|
-
switch (_context3.prev = _context3.next) {
|
|
263
|
-
case 0:
|
|
264
|
-
if (typeof q !== 'string') q = (0, _printer.print)(q);
|
|
265
|
-
_context3.next = 3;
|
|
266
|
-
return (0, _graphql.graphql)(schema, q, null, _objectSpread(_objectSpread({}, context), {}, {
|
|
267
|
-
pgClient: replacementPgClient
|
|
268
|
-
}), variables);
|
|
269
|
-
|
|
270
|
-
case 3:
|
|
271
|
-
return _context3.abrupt("return", _context3.sent);
|
|
272
|
-
|
|
273
|
-
case 4:
|
|
274
|
-
case "end":
|
|
275
|
-
return _context3.stop();
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}, _callee3);
|
|
279
|
-
}));
|
|
280
|
-
|
|
281
|
-
return function query(_x2, _x3) {
|
|
282
|
-
return _ref6.apply(this, arguments);
|
|
283
|
-
};
|
|
284
|
-
}(); // This is were we call the `checker` so you can do your assertions.
|
|
285
|
-
// Also note that we pass the `replacementPgClient` so that you can
|
|
286
|
-
// query the data in the database from within the transaction before it
|
|
287
|
-
// gets rolled back.
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
_context4.next = 18;
|
|
291
|
-
return checker(query, replacementPgClient);
|
|
292
|
-
|
|
293
|
-
case 18:
|
|
294
|
-
checkResult = _context4.sent;
|
|
295
|
-
|
|
296
|
-
case 19:
|
|
297
|
-
_context4.prev = 19;
|
|
298
|
-
_context4.next = 22;
|
|
299
|
-
return replacementPgClient.query('rollback');
|
|
300
|
-
|
|
301
|
-
case 22:
|
|
302
|
-
replacementPgClient.release();
|
|
303
|
-
return _context4.finish(19);
|
|
304
|
-
|
|
305
|
-
case 24:
|
|
306
|
-
return _context4.abrupt("return", checkResult);
|
|
307
|
-
|
|
308
|
-
case 25:
|
|
309
|
-
case "end":
|
|
310
|
-
return _context4.stop();
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}, _callee4, null, [[14,, 19, 24]]);
|
|
314
|
-
}));
|
|
315
|
-
|
|
316
|
-
return function (_x) {
|
|
317
|
-
return _ref3.apply(this, arguments);
|
|
318
|
-
};
|
|
319
|
-
}());
|
|
320
|
-
|
|
321
|
-
case 25:
|
|
322
|
-
case "end":
|
|
323
|
-
return _context5.stop();
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}, _callee5);
|
|
327
|
-
}));
|
|
328
|
-
|
|
329
|
-
function graphQL() {
|
|
330
|
-
return _graphQL.apply(this, arguments);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
return graphQL;
|
|
334
|
-
}();
|
|
335
|
-
|
|
336
|
-
return {
|
|
337
|
-
setup: setup,
|
|
338
|
-
teardown: teardown,
|
|
339
|
-
graphQL: graphQL,
|
|
340
|
-
withContext: function withContext(cb) {
|
|
341
|
-
return cb(ctx);
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
exports.GraphQLTest = GraphQLTest;
|
package/main/index.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _graphql = require("./graphql");
|
|
8
|
-
|
|
9
|
-
Object.keys(_graphql).forEach(function (key) {
|
|
10
|
-
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
Object.defineProperty(exports, key, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function get() {
|
|
14
|
-
return _graphql[key];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
var _gql = require("./gql");
|
|
20
|
-
|
|
21
|
-
Object.keys(_gql).forEach(function (key) {
|
|
22
|
-
if (key === "default" || key === "__esModule") return;
|
|
23
|
-
Object.defineProperty(exports, key, {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: function get() {
|
|
26
|
-
return _gql[key];
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
var _env = require("./env");
|
|
32
|
-
|
|
33
|
-
Object.keys(_env).forEach(function (key) {
|
|
34
|
-
if (key === "default" || key === "__esModule") return;
|
|
35
|
-
Object.defineProperty(exports, key, {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
get: function get() {
|
|
38
|
-
return _env[key];
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
var _clean = require("./clean");
|
|
44
|
-
|
|
45
|
-
Object.keys(_clean).forEach(function (key) {
|
|
46
|
-
if (key === "default" || key === "__esModule") return;
|
|
47
|
-
Object.defineProperty(exports, key, {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
get: function get() {
|
|
50
|
-
return _clean[key];
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|