graphile-build-pg 4.4.5 → 4.5.3
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/README.md +2 -1
- package/node8plus/QueryBuilder.d.ts +10 -2
- package/node8plus/QueryBuilder.js +80 -1
- package/node8plus/QueryBuilder.js.flow +75 -2
- package/node8plus/QueryBuilder.js.map +1 -1
- package/node8plus/index.d.ts +8 -0
- package/node8plus/index.js +7 -1
- package/node8plus/index.js.flow +6 -1
- package/node8plus/index.js.map +1 -1
- package/node8plus/plugins/PgBasicsPlugin.js +5 -3
- package/node8plus/plugins/PgBasicsPlugin.js.flow +2 -0
- package/node8plus/plugins/PgBasicsPlugin.js.map +1 -1
- package/node8plus/plugins/PgConnectionTotalCount.js +10 -4
- package/node8plus/plugins/PgConnectionTotalCount.js.flow +13 -9
- package/node8plus/plugins/PgConnectionTotalCount.js.map +1 -1
- package/node8plus/plugins/PgIntrospectionPlugin.d.ts +48 -11
- package/node8plus/plugins/PgIntrospectionPlugin.js +53 -23
- package/node8plus/plugins/PgIntrospectionPlugin.js.flow +81 -25
- package/node8plus/plugins/PgIntrospectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgJWTPlugin.js +6 -1
- package/node8plus/plugins/PgJWTPlugin.js.flow +7 -1
- package/node8plus/plugins/PgJWTPlugin.js.map +1 -1
- package/node8plus/plugins/PgMutationUpdateDeletePlugin.js +2 -1
- package/node8plus/plugins/PgMutationUpdateDeletePlugin.js.flow +3 -1
- package/node8plus/plugins/PgMutationUpdateDeletePlugin.js.map +1 -1
- package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js +1 -0
- package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js.flow +1 -0
- package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js +1 -0
- package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js.flow +1 -0
- package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgTypesPlugin.js +9 -2
- package/node8plus/plugins/PgTypesPlugin.js.flow +19 -0
- package/node8plus/plugins/PgTypesPlugin.js.map +1 -1
- package/node8plus/plugins/introspectionQuery.js +1 -0
- package/node8plus/plugins/introspectionQuery.js.flow +1 -0
- package/node8plus/plugins/introspectionQuery.js.map +1 -1
- package/node8plus/queryFromResolveDataFactory.js +8 -1
- package/node8plus/queryFromResolveDataFactory.js.flow +13 -1
- package/node8plus/queryFromResolveDataFactory.js.map +1 -1
- package/package.json +7 -12
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.PgEntityKind = exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
var _withPgClient = _interopRequireWildcard(require("../withPgClient"));
|
|
9
9
|
|
|
@@ -233,6 +233,21 @@ function smartCommentConstraints(introspectionResults) {
|
|
|
233
233
|
}
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
|
+
/* The argument to this must not contain cyclic references! */
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
const deepClone = value => {
|
|
240
|
+
if (Array.isArray(value)) {
|
|
241
|
+
return value.map(val => deepClone(val));
|
|
242
|
+
} else if (typeof value === "object" && value) {
|
|
243
|
+
return Object.keys(value).reduce((memo, k) => {
|
|
244
|
+
memo[k] = deepClone(value[k]);
|
|
245
|
+
return memo;
|
|
246
|
+
}, {});
|
|
247
|
+
} else {
|
|
248
|
+
return value;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
236
251
|
|
|
237
252
|
var PgIntrospectionPlugin = async function PgIntrospectionPlugin(builder, {
|
|
238
253
|
pgConfig,
|
|
@@ -243,13 +258,12 @@ var PgIntrospectionPlugin = async function PgIntrospectionPlugin(builder, {
|
|
|
243
258
|
pgIncludeExtensionResources = false,
|
|
244
259
|
pgLegacyFunctionsOnly = false,
|
|
245
260
|
pgSkipInstallingWatchFixtures = false,
|
|
246
|
-
pgAugmentIntrospectionResults,
|
|
247
261
|
pgOwnerConnectionString
|
|
248
262
|
}) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
263
|
+
/**
|
|
264
|
+
* @summary introspect database and get the table/view/constraints.
|
|
265
|
+
* @returns {Promise<PgIntrospectionResultsByKind>}
|
|
266
|
+
*/
|
|
253
267
|
async function introspect() {
|
|
254
268
|
// Perform introspection
|
|
255
269
|
if (!Array.isArray(schemas)) {
|
|
@@ -257,17 +271,7 @@ var PgIntrospectionPlugin = async function PgIntrospectionPlugin(builder, {
|
|
|
257
271
|
}
|
|
258
272
|
|
|
259
273
|
const cacheKey = `PgIntrospectionPlugin-introspectionResultsByKind-v${_package.version}`;
|
|
260
|
-
|
|
261
|
-
const cloneResults = obj => {
|
|
262
|
-
const result = Object.keys(obj).reduce((memo, k) => {
|
|
263
|
-
memo[k] = Array.isArray(obj[k]) ? obj[k].map(v => ({ ...v
|
|
264
|
-
})) : obj[k];
|
|
265
|
-
return memo;
|
|
266
|
-
}, {});
|
|
267
|
-
return result;
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
const introspectionResultsByKind = cloneResults((await persistentMemoizeWithKey(cacheKey, () => (0, _withPgClient.default)(pgConfig, async pgClient => {
|
|
274
|
+
const introspectionResultsByKind = deepClone((await persistentMemoizeWithKey(cacheKey, () => (0, _withPgClient.default)(pgConfig, async pgClient => {
|
|
271
275
|
const versionResult = await pgClient.query("show server_version_num;");
|
|
272
276
|
const serverVersionNum = parseInt(versionResult.rows[0].server_version_num, 10);
|
|
273
277
|
const introspectionQuery = (0, _introspectionQuery.makeIntrospectionQuery)(serverVersionNum, {
|
|
@@ -331,6 +335,12 @@ var PgIntrospectionPlugin = async function PgIntrospectionPlugin(builder, {
|
|
|
331
335
|
}
|
|
332
336
|
}
|
|
333
337
|
|
|
338
|
+
return introspectionResultsByKind;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function introspectionResultsFromRaw(rawResults, pgAugmentIntrospectionResults) {
|
|
342
|
+
const introspectionResultsByKind = deepClone(rawResults);
|
|
343
|
+
|
|
334
344
|
const xByY = (arrayOfX, attrKey) => arrayOfX.reduce((memo, x) => {
|
|
335
345
|
memo[x[attrKey]] = x;
|
|
336
346
|
return memo;
|
|
@@ -382,6 +392,10 @@ var PgIntrospectionPlugin = async function PgIntrospectionPlugin(builder, {
|
|
|
382
392
|
});
|
|
383
393
|
};
|
|
384
394
|
|
|
395
|
+
const augment = introspectionResults => {
|
|
396
|
+
[pgAugmentIntrospectionResults, smartCommentConstraints].forEach(fn => fn ? fn(introspectionResults) : null);
|
|
397
|
+
};
|
|
398
|
+
|
|
385
399
|
augment(introspectionResultsByKind);
|
|
386
400
|
relate(introspectionResultsByKind.class, "namespace", "namespaceId", introspectionResultsByKind.namespaceById, true // Because it could be a type defined in a different namespace - which is fine so long as we don't allow querying it directly
|
|
387
401
|
);
|
|
@@ -452,7 +466,7 @@ var PgIntrospectionPlugin = async function PgIntrospectionPlugin(builder, {
|
|
|
452
466
|
return introspectionResultsByKind;
|
|
453
467
|
}
|
|
454
468
|
|
|
455
|
-
let
|
|
469
|
+
let rawIntrospectionResultsByKind = await introspect();
|
|
456
470
|
let listener;
|
|
457
471
|
|
|
458
472
|
class Listener {
|
|
@@ -462,7 +476,7 @@ var PgIntrospectionPlugin = async function PgIntrospectionPlugin(builder, {
|
|
|
462
476
|
debug(`Schema change detected: re-inspecting schema...`);
|
|
463
477
|
|
|
464
478
|
try {
|
|
465
|
-
|
|
479
|
+
rawIntrospectionResultsByKind = await introspect();
|
|
466
480
|
debug(`Schema change detected: re-inspecting schema complete`);
|
|
467
481
|
triggerRebuild();
|
|
468
482
|
} catch (e) {
|
|
@@ -479,7 +493,7 @@ var PgIntrospectionPlugin = async function PgIntrospectionPlugin(builder, {
|
|
|
479
493
|
this._start();
|
|
480
494
|
}
|
|
481
495
|
|
|
482
|
-
async _start() {
|
|
496
|
+
async _start(isReconnect = false) {
|
|
483
497
|
if (this.stopped) {
|
|
484
498
|
return;
|
|
485
499
|
} // Connect to DB
|
|
@@ -527,7 +541,9 @@ var PgIntrospectionPlugin = async function PgIntrospectionPlugin(builder, {
|
|
|
527
541
|
} // Trigger re-introspection on server reconnect
|
|
528
542
|
|
|
529
543
|
|
|
530
|
-
|
|
544
|
+
if (isReconnect) {
|
|
545
|
+
this._handleChange();
|
|
546
|
+
}
|
|
531
547
|
}
|
|
532
548
|
} catch (e) {
|
|
533
549
|
// If something goes wrong, disconnect and try again after a short delay
|
|
@@ -554,7 +570,7 @@ var PgIntrospectionPlugin = async function PgIntrospectionPlugin(builder, {
|
|
|
554
570
|
setTimeout(() => {
|
|
555
571
|
if (!this.stopped) {
|
|
556
572
|
// Listen for further changes
|
|
557
|
-
this._start();
|
|
573
|
+
this._start(true);
|
|
558
574
|
}
|
|
559
575
|
}, 2000);
|
|
560
576
|
} // eslint-disable-next-line flowtype/no-weak-types
|
|
@@ -641,6 +657,8 @@ var PgIntrospectionPlugin = async function PgIntrospectionPlugin(builder, {
|
|
|
641
657
|
}
|
|
642
658
|
});
|
|
643
659
|
builder.hook("build", build => {
|
|
660
|
+
const introspectionResultsByKind = introspectionResultsFromRaw(rawIntrospectionResultsByKind, build.pgAugmentIntrospectionResults);
|
|
661
|
+
|
|
644
662
|
if (introspectionResultsByKind.__pgVersion < 90500) {
|
|
645
663
|
// TODO:v5: remove this workaround
|
|
646
664
|
// This is a bit of a hack, but until we have plugin priorities it's the
|
|
@@ -654,7 +672,19 @@ var PgIntrospectionPlugin = async function PgIntrospectionPlugin(builder, {
|
|
|
654
672
|
pgIntrospectionResultsByKind: introspectionResultsByKind
|
|
655
673
|
});
|
|
656
674
|
}, ["PgIntrospection"], [], ["PgBasics"]);
|
|
657
|
-
};
|
|
675
|
+
}; // TypeScript compatibility
|
|
676
|
+
|
|
658
677
|
|
|
659
678
|
exports.default = PgIntrospectionPlugin;
|
|
679
|
+
const PgEntityKind = {
|
|
680
|
+
NAMESPACE: "namespace",
|
|
681
|
+
PROCEDURE: "procedure",
|
|
682
|
+
CLASS: "class",
|
|
683
|
+
TYPE: "type",
|
|
684
|
+
ATTRIBUTE: "attribute",
|
|
685
|
+
CONSTRAINT: "constraint",
|
|
686
|
+
EXTENSION: "extension",
|
|
687
|
+
INDEX: "index"
|
|
688
|
+
};
|
|
689
|
+
exports.PgEntityKind = PgEntityKind;
|
|
660
690
|
//# sourceMappingURL=PgIntrospectionPlugin.js.map
|
|
@@ -71,9 +71,9 @@ export type PgClass = {
|
|
|
71
71
|
namespace: PgNamespace,
|
|
72
72
|
type: PgType,
|
|
73
73
|
tags: { [string]: string },
|
|
74
|
-
attributes:
|
|
75
|
-
constraints:
|
|
76
|
-
foreignConstraints:
|
|
74
|
+
attributes: Array<PgAttribute>,
|
|
75
|
+
constraints: Array<PgConstraint>,
|
|
76
|
+
foreignConstraints: Array<PgConstraint>,
|
|
77
77
|
primaryKeyConstraint: ?PgConstraint,
|
|
78
78
|
aclSelectable: boolean,
|
|
79
79
|
aclInsertable: boolean,
|
|
@@ -142,9 +142,9 @@ export type PgConstraint = {
|
|
|
142
142
|
comment: ?string,
|
|
143
143
|
description: ?string,
|
|
144
144
|
keyAttributeNums: Array<number>,
|
|
145
|
-
keyAttributes:
|
|
145
|
+
keyAttributes: Array<PgAttribute>,
|
|
146
146
|
foreignKeyAttributeNums: Array<number>,
|
|
147
|
-
foreignKeyAttributes:
|
|
147
|
+
foreignKeyAttributes: Array<PgAttribute>,
|
|
148
148
|
namespace: PgNamespace,
|
|
149
149
|
isIndexed: ?boolean,
|
|
150
150
|
tags: { [string]: string },
|
|
@@ -182,6 +182,7 @@ export type PgIndex = {
|
|
|
182
182
|
isReplicaIdentity: boolean,
|
|
183
183
|
isValid: boolean,
|
|
184
184
|
*/
|
|
185
|
+
isPartial: boolean,
|
|
185
186
|
attributeNums: Array<number>,
|
|
186
187
|
attributePropertiesAsc: ?Array<boolean>,
|
|
187
188
|
attributePropertiesNullsFirst: ?Array<boolean>,
|
|
@@ -199,6 +200,25 @@ export type PgEntity =
|
|
|
199
200
|
| PgExtension
|
|
200
201
|
| PgIndex;
|
|
201
202
|
|
|
203
|
+
export type PgIntrospectionResultsByKind = {
|
|
204
|
+
__pgVersion: number,
|
|
205
|
+
attribute: PgAttribute[],
|
|
206
|
+
attributeByClassIdAndNum: {
|
|
207
|
+
[classId: string]: { [num: string]: PgAttribute },
|
|
208
|
+
},
|
|
209
|
+
class: PgClass[],
|
|
210
|
+
classById: { [classId: string]: PgClass },
|
|
211
|
+
constraint: PgConstraint[],
|
|
212
|
+
extension: PgExtension[],
|
|
213
|
+
extensionById: { [extId: string]: PgExtension },
|
|
214
|
+
index: PgIndex[],
|
|
215
|
+
namespace: PgNamespace[],
|
|
216
|
+
namespaceById: { [namespaceId: string]: PgNamespace },
|
|
217
|
+
procedure: PgProc[],
|
|
218
|
+
type: PgType[],
|
|
219
|
+
typeById: { [typeId: string]: PgType },
|
|
220
|
+
};
|
|
221
|
+
|
|
202
222
|
function readFile(filename, encoding) {
|
|
203
223
|
return new Promise((resolve, reject) => {
|
|
204
224
|
rawReadFile(filename, encoding, (err, res) => {
|
|
@@ -424,6 +444,20 @@ function smartCommentConstraints(introspectionResults) {
|
|
|
424
444
|
});
|
|
425
445
|
}
|
|
426
446
|
|
|
447
|
+
/* The argument to this must not contain cyclic references! */
|
|
448
|
+
const deepClone = value => {
|
|
449
|
+
if (Array.isArray(value)) {
|
|
450
|
+
return value.map(val => deepClone(val));
|
|
451
|
+
} else if (typeof value === "object" && value) {
|
|
452
|
+
return Object.keys(value).reduce((memo, k) => {
|
|
453
|
+
memo[k] = deepClone(value[k]);
|
|
454
|
+
return memo;
|
|
455
|
+
}, {});
|
|
456
|
+
} else {
|
|
457
|
+
return value;
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
|
|
427
461
|
export default (async function PgIntrospectionPlugin(
|
|
428
462
|
builder,
|
|
429
463
|
{
|
|
@@ -435,29 +469,20 @@ export default (async function PgIntrospectionPlugin(
|
|
|
435
469
|
pgIncludeExtensionResources = false,
|
|
436
470
|
pgLegacyFunctionsOnly = false,
|
|
437
471
|
pgSkipInstallingWatchFixtures = false,
|
|
438
|
-
pgAugmentIntrospectionResults,
|
|
439
472
|
pgOwnerConnectionString,
|
|
440
473
|
}
|
|
441
474
|
) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
async function introspect() {
|
|
475
|
+
/**
|
|
476
|
+
* @summary introspect database and get the table/view/constraints.
|
|
477
|
+
* @returns {Promise<PgIntrospectionResultsByKind>}
|
|
478
|
+
*/
|
|
479
|
+
async function introspect(): Promise<PgIntrospectionResultsByKind> {
|
|
448
480
|
// Perform introspection
|
|
449
481
|
if (!Array.isArray(schemas)) {
|
|
450
482
|
throw new Error("Argument 'schemas' (array) is required");
|
|
451
483
|
}
|
|
452
484
|
const cacheKey = `PgIntrospectionPlugin-introspectionResultsByKind-v${version}`;
|
|
453
|
-
const
|
|
454
|
-
const result = Object.keys(obj).reduce((memo, k) => {
|
|
455
|
-
memo[k] = Array.isArray(obj[k]) ? obj[k].map(v => ({ ...v })) : obj[k];
|
|
456
|
-
return memo;
|
|
457
|
-
}, {});
|
|
458
|
-
return result;
|
|
459
|
-
};
|
|
460
|
-
const introspectionResultsByKind = cloneResults(
|
|
485
|
+
const introspectionResultsByKind = deepClone(
|
|
461
486
|
await persistentMemoizeWithKey(cacheKey, () =>
|
|
462
487
|
withPgClient(pgConfig, async pgClient => {
|
|
463
488
|
const versionResult = await pgClient.query(
|
|
@@ -555,6 +580,14 @@ export default (async function PgIntrospectionPlugin(
|
|
|
555
580
|
console.warn("⚠️ WARNING⚠️ " + errorMessage); // eslint-disable-line no-console
|
|
556
581
|
}
|
|
557
582
|
}
|
|
583
|
+
return introspectionResultsByKind;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function introspectionResultsFromRaw(
|
|
587
|
+
rawResults,
|
|
588
|
+
pgAugmentIntrospectionResults
|
|
589
|
+
) {
|
|
590
|
+
const introspectionResultsByKind = deepClone(rawResults);
|
|
558
591
|
|
|
559
592
|
const xByY = (arrayOfX, attrKey) =>
|
|
560
593
|
arrayOfX.reduce((memo, x) => {
|
|
@@ -626,6 +659,11 @@ export default (async function PgIntrospectionPlugin(
|
|
|
626
659
|
});
|
|
627
660
|
};
|
|
628
661
|
|
|
662
|
+
const augment = introspectionResults => {
|
|
663
|
+
[pgAugmentIntrospectionResults, smartCommentConstraints].forEach(fn =>
|
|
664
|
+
fn ? fn(introspectionResults) : null
|
|
665
|
+
);
|
|
666
|
+
};
|
|
629
667
|
augment(introspectionResultsByKind);
|
|
630
668
|
|
|
631
669
|
relate(
|
|
@@ -802,7 +840,7 @@ export default (async function PgIntrospectionPlugin(
|
|
|
802
840
|
return introspectionResultsByKind;
|
|
803
841
|
}
|
|
804
842
|
|
|
805
|
-
let
|
|
843
|
+
let rawIntrospectionResultsByKind = await introspect();
|
|
806
844
|
|
|
807
845
|
let listener;
|
|
808
846
|
|
|
@@ -818,7 +856,7 @@ export default (async function PgIntrospectionPlugin(
|
|
|
818
856
|
async () => {
|
|
819
857
|
debug(`Schema change detected: re-inspecting schema...`);
|
|
820
858
|
try {
|
|
821
|
-
|
|
859
|
+
rawIntrospectionResultsByKind = await introspect();
|
|
822
860
|
debug(`Schema change detected: re-inspecting schema complete`);
|
|
823
861
|
triggerRebuild();
|
|
824
862
|
} catch (e) {
|
|
@@ -837,7 +875,7 @@ export default (async function PgIntrospectionPlugin(
|
|
|
837
875
|
this._start();
|
|
838
876
|
}
|
|
839
877
|
|
|
840
|
-
async _start() {
|
|
878
|
+
async _start(isReconnect = false) {
|
|
841
879
|
if (this.stopped) {
|
|
842
880
|
return;
|
|
843
881
|
}
|
|
@@ -897,7 +935,9 @@ export default (async function PgIntrospectionPlugin(
|
|
|
897
935
|
}
|
|
898
936
|
|
|
899
937
|
// Trigger re-introspection on server reconnect
|
|
900
|
-
|
|
938
|
+
if (isReconnect) {
|
|
939
|
+
this._handleChange();
|
|
940
|
+
}
|
|
901
941
|
}
|
|
902
942
|
} catch (e) {
|
|
903
943
|
// If something goes wrong, disconnect and try again after a short delay
|
|
@@ -925,7 +965,7 @@ export default (async function PgIntrospectionPlugin(
|
|
|
925
965
|
setTimeout(() => {
|
|
926
966
|
if (!this.stopped) {
|
|
927
967
|
// Listen for further changes
|
|
928
|
-
this._start();
|
|
968
|
+
this._start(true);
|
|
929
969
|
}
|
|
930
970
|
}, 2000);
|
|
931
971
|
}
|
|
@@ -1011,6 +1051,10 @@ export default (async function PgIntrospectionPlugin(
|
|
|
1011
1051
|
builder.hook(
|
|
1012
1052
|
"build",
|
|
1013
1053
|
build => {
|
|
1054
|
+
const introspectionResultsByKind = introspectionResultsFromRaw(
|
|
1055
|
+
rawIntrospectionResultsByKind,
|
|
1056
|
+
build.pgAugmentIntrospectionResults
|
|
1057
|
+
);
|
|
1014
1058
|
if (introspectionResultsByKind.__pgVersion < 90500) {
|
|
1015
1059
|
// TODO:v5: remove this workaround
|
|
1016
1060
|
// This is a bit of a hack, but until we have plugin priorities it's the
|
|
@@ -1028,3 +1072,15 @@ export default (async function PgIntrospectionPlugin(
|
|
|
1028
1072
|
["PgBasics"]
|
|
1029
1073
|
);
|
|
1030
1074
|
}: Plugin);
|
|
1075
|
+
|
|
1076
|
+
// TypeScript compatibility
|
|
1077
|
+
export const PgEntityKind = {
|
|
1078
|
+
NAMESPACE: "namespace",
|
|
1079
|
+
PROCEDURE: "procedure",
|
|
1080
|
+
CLASS: "class",
|
|
1081
|
+
TYPE: "type",
|
|
1082
|
+
ATTRIBUTE: "attribute",
|
|
1083
|
+
CONSTRAINT: "constraint",
|
|
1084
|
+
EXTENSION: "extension",
|
|
1085
|
+
INDEX: "index",
|
|
1086
|
+
};
|