@axinom/mosaic-graphql-common 0.1.0-rc.0
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 +16 -0
- package/dist/common/checks.d.ts +9 -0
- package/dist/common/checks.d.ts.map +1 -0
- package/dist/common/checks.js +21 -0
- package/dist/common/checks.js.map +1 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +19 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/types.d.ts +13 -0
- package/dist/common/types.d.ts.map +1 -0
- package/dist/common/types.js +15 -0
- package/dist/common/types.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/add-error-codes-enum-plugin.d.ts +27 -0
- package/dist/plugins/add-error-codes-enum-plugin.d.ts.map +1 -0
- package/dist/plugins/add-error-codes-enum-plugin.js +78 -0
- package/dist/plugins/add-error-codes-enum-plugin.js.map +1 -0
- package/dist/plugins/annotate-types-with-permissions-plugin.d.ts +22 -0
- package/dist/plugins/annotate-types-with-permissions-plugin.d.ts.map +1 -0
- package/dist/plugins/annotate-types-with-permissions-plugin.js +145 -0
- package/dist/plugins/annotate-types-with-permissions-plugin.js.map +1 -0
- package/dist/plugins/deprecate-stray-node-id-fields-plugin.d.ts +14 -0
- package/dist/plugins/deprecate-stray-node-id-fields-plugin.d.ts.map +1 -0
- package/dist/plugins/deprecate-stray-node-id-fields-plugin.js +37 -0
- package/dist/plugins/deprecate-stray-node-id-fields-plugin.js.map +1 -0
- package/dist/plugins/generic-bulk-plugin-factory.d.ts +49 -0
- package/dist/plugins/generic-bulk-plugin-factory.d.ts.map +1 -0
- package/dist/plugins/generic-bulk-plugin-factory.js +181 -0
- package/dist/plugins/generic-bulk-plugin-factory.js.map +1 -0
- package/dist/plugins/graphiql-management-mode-plugin-hook.d.ts +13 -0
- package/dist/plugins/graphiql-management-mode-plugin-hook.d.ts.map +1 -0
- package/dist/plugins/graphiql-management-mode-plugin-hook.js +44 -0
- package/dist/plugins/graphiql-management-mode-plugin-hook.js.map +1 -0
- package/dist/plugins/index.d.ts +10 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +26 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/omit-from-query-root-plugin.d.ts +17 -0
- package/dist/plugins/omit-from-query-root-plugin.d.ts.map +1 -0
- package/dist/plugins/omit-from-query-root-plugin.js +43 -0
- package/dist/plugins/omit-from-query-root-plugin.js.map +1 -0
- package/dist/plugins/operations-enum-generator-plugin-factory.d.ts +15 -0
- package/dist/plugins/operations-enum-generator-plugin-factory.d.ts.map +1 -0
- package/dist/plugins/operations-enum-generator-plugin-factory.js +108 -0
- package/dist/plugins/operations-enum-generator-plugin-factory.js.map +1 -0
- package/dist/plugins/subscriptions-plugin-factory.d.ts +9 -0
- package/dist/plugins/subscriptions-plugin-factory.d.ts.map +1 -0
- package/dist/plugins/subscriptions-plugin-factory.js +67 -0
- package/dist/plugins/subscriptions-plugin-factory.js.map +1 -0
- package/dist/plugins/validation-directives-plugin.d.ts +6 -0
- package/dist/plugins/validation-directives-plugin.d.ts.map +1 -0
- package/dist/plugins/validation-directives-plugin.js +117 -0
- package/dist/plugins/validation-directives-plugin.js.map +1 -0
- package/dist/postgraphile/enhance-graphql-errors.d.ts +48 -0
- package/dist/postgraphile/enhance-graphql-errors.d.ts.map +1 -0
- package/dist/postgraphile/enhance-graphql-errors.js +67 -0
- package/dist/postgraphile/enhance-graphql-errors.js.map +1 -0
- package/dist/postgraphile/index.d.ts +4 -0
- package/dist/postgraphile/index.d.ts.map +1 -0
- package/dist/postgraphile/index.js +20 -0
- package/dist/postgraphile/index.js.map +1 -0
- package/dist/postgraphile/postgraphile-options-builder.d.ts +273 -0
- package/dist/postgraphile/postgraphile-options-builder.d.ts.map +1 -0
- package/dist/postgraphile/postgraphile-options-builder.js +419 -0
- package/dist/postgraphile/postgraphile-options-builder.js.map +1 -0
- package/dist/postgraphile/websocket-utils.d.ts +11 -0
- package/dist/postgraphile/websocket-utils.d.ts.map +1 -0
- package/dist/postgraphile/websocket-utils.js +17 -0
- package/dist/postgraphile/websocket-utils.js.map +1 -0
- package/package.json +61 -0
- package/src/common/checks.ts +23 -0
- package/src/common/index.ts +2 -0
- package/src/common/types.ts +15 -0
- package/src/index.ts +3 -0
- package/src/plugins/add-error-codes-enum-plugin.ts +102 -0
- package/src/plugins/annotate-types-with-permissions-plugin.spec.ts +158 -0
- package/src/plugins/annotate-types-with-permissions-plugin.ts +205 -0
- package/src/plugins/deprecate-stray-node-id-fields-plugin.ts +41 -0
- package/src/plugins/generic-bulk-plugin-factory.ts +313 -0
- package/src/plugins/graphiql-management-mode-plugin-hook.ts +46 -0
- package/src/plugins/index.ts +9 -0
- package/src/plugins/omit-from-query-root-plugin.ts +69 -0
- package/src/plugins/operations-enum-generator-plugin-factory.ts +130 -0
- package/src/plugins/subscriptions-plugin-factory.ts +114 -0
- package/src/plugins/validation-directives-plugin.ts +141 -0
- package/src/postgraphile/enhance-graphql-errors.spec.ts +241 -0
- package/src/postgraphile/enhance-graphql-errors.ts +138 -0
- package/src/postgraphile/index.ts +3 -0
- package/src/postgraphile/postgraphile-options-builder.spec.ts +744 -0
- package/src/postgraphile/postgraphile-options-builder.ts +510 -0
- package/src/postgraphile/websocket-utils.ts +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @axinom/mosaic-graphql-common
|
|
2
|
+
|
|
3
|
+
## About the Package
|
|
4
|
+
|
|
5
|
+
This package is part of the Axinom Mosaic development platform. More information
|
|
6
|
+
can be found at https://portal.axinom.com/mosaic.
|
|
7
|
+
|
|
8
|
+
## License
|
|
9
|
+
|
|
10
|
+
This package can be licensed under the
|
|
11
|
+
[Axinom Products Licensing Agreement](https://portal.axinom.com/mosaic/contracts/products-licensing-agreement)
|
|
12
|
+
or evaluated under the
|
|
13
|
+
[Axinom Products Evaluation Agreement](https://portal.axinom.com/mosaic/contracts/products-evaluation-agreement).
|
|
14
|
+
No part of Axinom's software may be copied, modified, propagated, or distributed
|
|
15
|
+
except in accordance with the terms contained in the Axinom Products Licensing
|
|
16
|
+
Agreement and Axinom Products Evaluation Agreement.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a variable is a string index based object
|
|
3
|
+
* @param value variable to check
|
|
4
|
+
*/
|
|
5
|
+
export declare function assertDictionary(value: unknown): asserts value is {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
export declare const isNullOrWhitespace: <T>(value: T | null | undefined) => value is null | undefined;
|
|
9
|
+
//# sourceMappingURL=checks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checks.d.ts","sourceRoot":"","sources":["../../src/common/checks.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,GAEb,OAAO,CAAC,KAAK,IAAI;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAIzC;AAED,eAAO,MAAM,kBAAkB,+DAQ9B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNullOrWhitespace = exports.assertDictionary = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Check if a variable is a string index based object
|
|
6
|
+
* @param value variable to check
|
|
7
|
+
*/
|
|
8
|
+
// must be a real function: https://github.com/microsoft/TypeScript/issues/36931
|
|
9
|
+
function assertDictionary(value) {
|
|
10
|
+
if (typeof value !== 'object' || value === null) {
|
|
11
|
+
throw Error('The value is no string indexed object.');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.assertDictionary = assertDictionary;
|
|
15
|
+
const isNullOrWhitespace = (value) => {
|
|
16
|
+
return (value === null ||
|
|
17
|
+
value === undefined ||
|
|
18
|
+
(typeof value === 'string' && value.trim().length === 0));
|
|
19
|
+
};
|
|
20
|
+
exports.isNullOrWhitespace = isNullOrWhitespace;
|
|
21
|
+
//# sourceMappingURL=checks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checks.js","sourceRoot":"","sources":["../../src/common/checks.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,gFAAgF;AAChF,SAAgB,gBAAgB,CAC9B,KAAc;IAGd,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE;QAC/C,MAAM,KAAK,CAAC,wCAAwC,CAAC,CAAC;KACvD;AACH,CAAC;AAPD,4CAOC;AAEM,MAAM,kBAAkB,GAAG,CAChC,KAA2B,EACA,EAAE;IAC7B,OAAO,CACL,KAAK,KAAK,IAAI;QACd,KAAK,KAAK,SAAS;QACnB,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CACzD,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,kBAAkB,sBAQ7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./checks"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** TYpe definition of an object with field accessor. */
|
|
2
|
+
export interface Dict<T> {
|
|
3
|
+
[key: string]: T;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Error to be thrown in a default block of an exhaustive switch-case block, if checked value has a finite amount of possible values (e.g enum).
|
|
7
|
+
* This error has a very low chance to actually be thrown.
|
|
8
|
+
* Instead, it is used by IDE to give an indication of which possible value is not covered by switch-case and will result in a failed build.
|
|
9
|
+
*/
|
|
10
|
+
export declare class UnreachableCaseError extends Error {
|
|
11
|
+
constructor(val: never);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;CAClB;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,GAAG,EAAE,KAAK;CAGvB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnreachableCaseError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Error to be thrown in a default block of an exhaustive switch-case block, if checked value has a finite amount of possible values (e.g enum).
|
|
6
|
+
* This error has a very low chance to actually be thrown.
|
|
7
|
+
* Instead, it is used by IDE to give an indication of which possible value is not covered by switch-case and will result in a failed build.
|
|
8
|
+
*/
|
|
9
|
+
class UnreachableCaseError extends Error {
|
|
10
|
+
constructor(val) {
|
|
11
|
+
super(`Unreachable case: ${val}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.UnreachableCaseError = UnreachableCaseError;
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":";;;AAKA;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,GAAU;QACpB,KAAK,CAAC,qBAAqB,GAAG,EAAE,CAAC,CAAC;IACpC,CAAC;CACF;AAJD,oDAIC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./plugins"), exports);
|
|
19
|
+
__exportStar(require("./postgraphile"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,4CAA0B;AAC1B,iDAA+B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Plugin } from 'postgraphile';
|
|
2
|
+
import { Dict } from '../common';
|
|
3
|
+
export interface MosaicErrorDefinition {
|
|
4
|
+
message: string;
|
|
5
|
+
code: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Adds a detached enum type to the GraphQL schema, listing all possible
|
|
9
|
+
* ErrorCode values and adding messages as a descriptions.
|
|
10
|
+
*
|
|
11
|
+
* Make sure to add it after `EnforceStrictPermissionsPlugin` or any other
|
|
12
|
+
* plugin that might filter queries out of the resulting schema.
|
|
13
|
+
*
|
|
14
|
+
* If there is a need to adjust this enum - use `GraphQLEnumType` postgraphile
|
|
15
|
+
* hook and `isErrorCodesEnum` scope to find the generated enum. E.g.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
builder.hook('GraphQLEnumType', (enumField, _build, context) => {
|
|
19
|
+
if (context.scope.isErrorCodesEnum === true) {
|
|
20
|
+
// Modification logic
|
|
21
|
+
}
|
|
22
|
+
return enumField;
|
|
23
|
+
});
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const AddErrorCodesEnumPluginFactory: (errorCodeEnums: Dict<MosaicErrorDefinition>[]) => Plugin;
|
|
27
|
+
//# sourceMappingURL=add-error-codes-enum-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-error-codes-enum-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/add-error-codes-enum-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AA+BD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,8BAA8B,EAAE,CAC3C,cAAc,EAAE,IAAI,CAAC,qBAAqB,CAAC,EAAE,KAC1C,MAwCJ,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AddErrorCodesEnumPluginFactory = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
/**
|
|
6
|
+
* Maps an array of error code enum objects to a single object, forming a
|
|
7
|
+
* unified ErrorCodes GraphQL Enum.
|
|
8
|
+
*/
|
|
9
|
+
const mapEnumValues = (errorCodeEnums) => {
|
|
10
|
+
const values = {};
|
|
11
|
+
for (const errorCodeEnum of errorCodeEnums) {
|
|
12
|
+
for (const key in errorCodeEnum) {
|
|
13
|
+
if (Object.prototype.hasOwnProperty.call(errorCodeEnum, key)) {
|
|
14
|
+
const element = errorCodeEnum[key];
|
|
15
|
+
if (values[element.code]) {
|
|
16
|
+
throw new Error(`Error code '${element.code}' is used in multiple enum objects. Error codes must be unique.`);
|
|
17
|
+
}
|
|
18
|
+
values[element.code] = {
|
|
19
|
+
value: element.code,
|
|
20
|
+
description: element.message,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return values;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Adds a detached enum type to the GraphQL schema, listing all possible
|
|
29
|
+
* ErrorCode values and adding messages as a descriptions.
|
|
30
|
+
*
|
|
31
|
+
* Make sure to add it after `EnforceStrictPermissionsPlugin` or any other
|
|
32
|
+
* plugin that might filter queries out of the resulting schema.
|
|
33
|
+
*
|
|
34
|
+
* If there is a need to adjust this enum - use `GraphQLEnumType` postgraphile
|
|
35
|
+
* hook and `isErrorCodesEnum` scope to find the generated enum. E.g.
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
builder.hook('GraphQLEnumType', (enumField, _build, context) => {
|
|
39
|
+
if (context.scope.isErrorCodesEnum === true) {
|
|
40
|
+
// Modification logic
|
|
41
|
+
}
|
|
42
|
+
return enumField;
|
|
43
|
+
});
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
const AddErrorCodesEnumPluginFactory = (errorCodeEnums) => (builder) => {
|
|
47
|
+
const dummyQueryName = '_dummyErrorCodesEnum';
|
|
48
|
+
// Attaches the enum type and a dummy query endpoint to the schema.
|
|
49
|
+
// Postgraphile removes all unused types, so we are first adding a dummy
|
|
50
|
+
// query endpoint (to emulate enum usage), and during the `finalize` phase -
|
|
51
|
+
// we delete it, so that the cleanup would not remove the enum type itself.
|
|
52
|
+
builder.hook('GraphQLObjectType:fields', (fields, { extend, newWithHooks }, { scope: { isRootQuery } }) => {
|
|
53
|
+
if (!isRootQuery) {
|
|
54
|
+
return fields;
|
|
55
|
+
}
|
|
56
|
+
const values = mapEnumValues(errorCodeEnums);
|
|
57
|
+
const enumType = newWithHooks(graphql_1.GraphQLEnumType, {
|
|
58
|
+
name: 'ErrorCodesEnum',
|
|
59
|
+
description: `Exposes all error codes and messages for errors that a service requests can throw. In some cases, messages that are actually thrown can be different, since they can include more details or a single code can used for different errors of the same type.`,
|
|
60
|
+
values,
|
|
61
|
+
}, { isErrorCodesEnum: true });
|
|
62
|
+
return extend(fields, {
|
|
63
|
+
[dummyQueryName]: {
|
|
64
|
+
type: enumType,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
// Removing the dummy type from schema, leaving only the enum type.
|
|
69
|
+
builder.hook('finalize', (schema) => {
|
|
70
|
+
const query = schema.getQueryType();
|
|
71
|
+
if (query) {
|
|
72
|
+
delete query.getFields()[dummyQueryName];
|
|
73
|
+
}
|
|
74
|
+
return schema;
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
exports.AddErrorCodesEnumPluginFactory = AddErrorCodesEnumPluginFactory;
|
|
78
|
+
//# sourceMappingURL=add-error-codes-enum-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-error-codes-enum-plugin.js","sourceRoot":"","sources":["../../src/plugins/add-error-codes-enum-plugin.ts"],"names":[],"mappings":";;;AAAA,qCAA0C;AAW1C;;;GAGG;AACH,MAAM,aAAa,GAAG,CACpB,cAA6C,EAC1B,EAAE;IACrB,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE;QAC1C,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE;YAC/B,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE;gBAC5D,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;gBACnC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;oBACxB,MAAM,IAAI,KAAK,CACb,eAAe,OAAO,CAAC,IAAI,iEAAiE,CAC7F,CAAC;iBACH;gBAED,MAA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,CAAC,CAAC;AACL,CAAC,CAAC;AA1CW,QAAA,8BAA8B,kCA0CzC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Plugin } from 'postgraphile';
|
|
2
|
+
interface PolicyRow {
|
|
3
|
+
schemaname: string;
|
|
4
|
+
tablename: string;
|
|
5
|
+
permissive: 'PERMISSIVE' | 'RESTRICTIVE';
|
|
6
|
+
command: string;
|
|
7
|
+
using: string | null;
|
|
8
|
+
withcheck: string | null;
|
|
9
|
+
}
|
|
10
|
+
type SqlOperation = 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE';
|
|
11
|
+
declare function setPermissionsCommentText(currentDescription: string | null | undefined, policies: PolicyRow[], type: SqlOperation): string;
|
|
12
|
+
/**
|
|
13
|
+
* Plugin that adds permissions annotation to graphql schema descriptions.
|
|
14
|
+
*
|
|
15
|
+
* @param graphileBuildOptions should be of type `Partial<Options> & { ownerPool: Pool }`
|
|
16
|
+
*/
|
|
17
|
+
export declare const AnnotateTypesWithPermissionsPlugin: Plugin;
|
|
18
|
+
export declare const exportedForTestingAnnotatePlugin: {
|
|
19
|
+
setPermissionsCommentText: typeof setPermissionsCommentText;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=annotate-types-with-permissions-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotate-types-with-permissions-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/annotate-types-with-permissions-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,UAAU,SAAS;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,YAAY,GAAG,aAAa,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,KAAK,YAAY,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAsD9D,iBAAS,yBAAyB,CAChC,kBAAkB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC7C,QAAQ,EAAE,SAAS,EAAE,EACrB,IAAI,EAAE,YAAY,GACjB,MAAM,CAeR;AAID;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,EAAE,MA2GhD,CAAC;AAEF,eAAO,MAAM,gCAAgC;;CAAgC,CAAC"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exportedForTestingAnnotatePlugin = exports.AnnotateTypesWithPermissionsPlugin = void 0;
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
async function loadPolicies(ownerPool) {
|
|
6
|
+
const client = await ownerPool.connect();
|
|
7
|
+
try {
|
|
8
|
+
// get all policies, sort so "ALL" is last and custom ones come earlier
|
|
9
|
+
const queryResult = await client.query(`
|
|
10
|
+
select
|
|
11
|
+
schemaname,
|
|
12
|
+
tablename,
|
|
13
|
+
permissive,
|
|
14
|
+
cmd as command,
|
|
15
|
+
qual as using,
|
|
16
|
+
with_check as withcheck
|
|
17
|
+
from pg_policies
|
|
18
|
+
order by command desc`);
|
|
19
|
+
return queryResult.rows;
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
client.release();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function parsePermissions(sqlPolicy) {
|
|
26
|
+
const matches = /(ax_utils\.)?user_has_permission\('([^']+)/.exec(sqlPolicy);
|
|
27
|
+
return matches && matches.length > 2 ? matches[2] : '';
|
|
28
|
+
}
|
|
29
|
+
function getPermissions(policies, commands, field) {
|
|
30
|
+
let matchingPolicies = policies.filter((p) => commands.find((cmd) => p.command === cmd) && p[field]);
|
|
31
|
+
// If RESTRICTIVE policies found, list only them and remove PERMISSIVE ones
|
|
32
|
+
if (matchingPolicies.some((policy) => policy.permissive === 'RESTRICTIVE')) {
|
|
33
|
+
matchingPolicies = matchingPolicies.filter((policy) => policy.permissive === 'RESTRICTIVE');
|
|
34
|
+
}
|
|
35
|
+
return [
|
|
36
|
+
...new Set(// removes duplicates
|
|
37
|
+
matchingPolicies
|
|
38
|
+
.map((p) => parsePermissions(p[field]))
|
|
39
|
+
.filter((p) => !(0, common_1.isNullOrWhitespace)(p))
|
|
40
|
+
.sort()),
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
function setPermissionsCommentText(currentDescription, policies, type) {
|
|
44
|
+
const field = type === 'SELECT' || type === 'DELETE' ? 'using' : 'withcheck';
|
|
45
|
+
const permissions = getPermissions(policies, ['ALL', type], field);
|
|
46
|
+
const description = (0, common_1.isNullOrWhitespace)(currentDescription)
|
|
47
|
+
? ''
|
|
48
|
+
: currentDescription;
|
|
49
|
+
return permissions.length > 0
|
|
50
|
+
? [
|
|
51
|
+
(0, common_1.isNullOrWhitespace)(description) ? description : `${description}\n`,
|
|
52
|
+
...permissions
|
|
53
|
+
.map((permission) => `@permissions: ${permission}`)
|
|
54
|
+
.join('\n'),
|
|
55
|
+
].join('')
|
|
56
|
+
: description;
|
|
57
|
+
}
|
|
58
|
+
// all available hooks are defined here:
|
|
59
|
+
// https://www.graphile.org/graphile-build/all-hooks/
|
|
60
|
+
/**
|
|
61
|
+
* Plugin that adds permissions annotation to graphql schema descriptions.
|
|
62
|
+
*
|
|
63
|
+
* @param graphileBuildOptions should be of type `Partial<Options> & { ownerPool: Pool }`
|
|
64
|
+
*/
|
|
65
|
+
const AnnotateTypesWithPermissionsPlugin = async (builder, { ownerPool }) => {
|
|
66
|
+
const allPolicies = await loadPolicies(ownerPool);
|
|
67
|
+
builder.hook('GraphQLInputObjectType', (obj, _build, context) => {
|
|
68
|
+
const scope = context.scope;
|
|
69
|
+
// PostGraphile input Types that do not correspond to a database table
|
|
70
|
+
if (scope.isPointInputType ||
|
|
71
|
+
scope.isIntervalInputType ||
|
|
72
|
+
scope.isPgConnectionFilterOperators ||
|
|
73
|
+
scope.isPgConnectionFilterMany ||
|
|
74
|
+
scope.isPgCondition ||
|
|
75
|
+
scope.isPgConnectionFilter) {
|
|
76
|
+
return obj;
|
|
77
|
+
}
|
|
78
|
+
// PostGraphile generated input types for DB mutations
|
|
79
|
+
if (scope.pgIntrospection) {
|
|
80
|
+
const policies = allPolicies.filter((value) => value.schemaname === scope.pgIntrospection.namespaceName &&
|
|
81
|
+
value.tablename === scope.pgIntrospection.name);
|
|
82
|
+
let operation;
|
|
83
|
+
switch (true) {
|
|
84
|
+
case scope.isPgCreateInputType:
|
|
85
|
+
operation = 'INSERT';
|
|
86
|
+
break;
|
|
87
|
+
case scope.isPgUpdateInputType:
|
|
88
|
+
operation = 'UPDATE';
|
|
89
|
+
break;
|
|
90
|
+
case scope.isPgDeleteInputType:
|
|
91
|
+
operation = 'DELETE';
|
|
92
|
+
break;
|
|
93
|
+
default:
|
|
94
|
+
return obj;
|
|
95
|
+
}
|
|
96
|
+
obj.description = setPermissionsCommentText(obj.description, policies, operation);
|
|
97
|
+
return obj;
|
|
98
|
+
}
|
|
99
|
+
// The input objects that come to this code-path are custom input types
|
|
100
|
+
// and require custom logic to protect them!
|
|
101
|
+
// Only works if they have input >types< - if they have no input or scalar
|
|
102
|
+
// input values they cannot be found by this method.
|
|
103
|
+
// Example: PopulateInput from the populate endpoint
|
|
104
|
+
return obj;
|
|
105
|
+
});
|
|
106
|
+
builder.hook('GraphQLObjectType', (obj, _build, context) => {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
const scope = context.scope;
|
|
109
|
+
if (
|
|
110
|
+
// PostGraphile Types that do not correspond to a database table
|
|
111
|
+
scope.isPointType ||
|
|
112
|
+
scope.isIntervalType ||
|
|
113
|
+
scope.isPgConnectionFilterOperators ||
|
|
114
|
+
scope.isPgConnectionFilterMany ||
|
|
115
|
+
scope.isPgCondition ||
|
|
116
|
+
scope.isPgConnectionFilter ||
|
|
117
|
+
scope.isPageInfo ||
|
|
118
|
+
scope.isEdgeType ||
|
|
119
|
+
scope.isRootQuery ||
|
|
120
|
+
scope.isRootMutation ||
|
|
121
|
+
scope.isRootSubscription ||
|
|
122
|
+
scope.isMutationPayload ||
|
|
123
|
+
scope.isPgDeletePayloadType ||
|
|
124
|
+
scope.isPgUpdatePayloadType ||
|
|
125
|
+
// TODO: Procedures have no row level security: secure them in another way
|
|
126
|
+
((_b = (_a = context === null || context === void 0 ? void 0 : context.scope) === null || _a === void 0 ? void 0 : _a.pgIntrospection) === null || _b === void 0 ? void 0 : _b.kind) === 'procedure') {
|
|
127
|
+
return obj;
|
|
128
|
+
}
|
|
129
|
+
// PostGraphile generated types for DB queries
|
|
130
|
+
if (scope.pgIntrospection) {
|
|
131
|
+
const policies = allPolicies.filter((value) => value.schemaname === scope.pgIntrospection.namespaceName &&
|
|
132
|
+
value.tablename === scope.pgIntrospection.name);
|
|
133
|
+
obj.description = setPermissionsCommentText(obj.description, policies, 'SELECT');
|
|
134
|
+
return obj;
|
|
135
|
+
}
|
|
136
|
+
// The objects that come to this code-path are custom types
|
|
137
|
+
// and require custom logic to protect them!
|
|
138
|
+
// Only works if they have >types< - if they have no input or scalar
|
|
139
|
+
// input values they cannot be found by this method.
|
|
140
|
+
return obj;
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
exports.AnnotateTypesWithPermissionsPlugin = AnnotateTypesWithPermissionsPlugin;
|
|
144
|
+
exports.exportedForTestingAnnotatePlugin = { setPermissionsCommentText };
|
|
145
|
+
//# sourceMappingURL=annotate-types-with-permissions-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotate-types-with-permissions-plugin.js","sourceRoot":"","sources":["../../src/plugins/annotate-types-with-permissions-plugin.ts"],"names":[],"mappings":";;;AAEA,sCAA+C;AAc/C,KAAK,UAAU,YAAY,CAAC,SAAe;IACzC,MAAM,MAAM,GAAG,MAAM,SA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,KAAK,CAAC,aAAa;YACnB,KAAK,CAAC,oBAAoB;YAC1B,KAAK,CAAC,UAAU;YAChB,KAAK,CAAC,UAAU;YAChB,KAAK,CAAC,WAAW;YACjB,KAAK,CAAC,cAAc;YACpB,KAAK,CAAC,kBAAkB;YACxB,KAAK,CAAC,iBAAiB;YACvB,KAAK,CAAC,qBAAqB;YAC3B,KAAK,CAAC,qBAAqB;YAC3B,0EAA0E;YAC1E,CAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,eAAe,0CAAE,IAAI,MAAK,WAAW,EACrD;YACA,OAAO,GAAG,CAAC;SACZ;QAED,8CAA8C;QAC9C,IAAI,KAAK,CAAC,eAAe,EAAE;YACzB,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CACjC,CAAC,KAAK,EAAE,EAAE,CACR,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,eAAe,CAAC,aAAa;gBACxD,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,eAAe,CAAC,IAAI,CACjD,CAAC;YAEF,GAAG,CAAC,WAAW,GAAG,yBAAyB,CACzC,GAAG,CAAC,WAAW,EACf,QAAQ,EACR,QAAQ,CACT,CAAC;YACF,OAAO,GAAG,CAAC;SACZ;QAED,2DAA2D;QAC3D,4CAA4C;QAC5C,oEAAoE;QACpE,oDAAoD;QACpD,OAAO,GAAG,CAAC;IACb,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA3GW,QAAA,kCAAkC,sCA2G7C;AAEW,QAAA,gCAAgC,GAAG,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from 'postgraphile';
|
|
2
|
+
type DeprecateMode = 'DEPRECATE' | 'DROP';
|
|
3
|
+
/**
|
|
4
|
+
* NodePlugin is excluded by default to remove all references of NodeId fields
|
|
5
|
+
* and byNodeId operations. A few such instances are not removed and handled
|
|
6
|
+
* explicitly by this plugin, e.g. deletedEntityNodeId in the
|
|
7
|
+
* DeleteEntityPayload types.
|
|
8
|
+
*
|
|
9
|
+
* By default, the plugin marks each field as deprecated. Pass an explicit
|
|
10
|
+
* `DROP` value to drop the fields instead.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DeprecateStrayNodeIdFieldsPlugin: (mode?: DeprecateMode) => Plugin;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=deprecate-stray-node-id-fields-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecate-stray-node-id-fields-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/deprecate-stray-node-id-fields-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,KAAK,aAAa,GAAG,WAAW,GAAG,MAAM,CAAC;AAE1C;;;;;;;;GAQG;AACH,eAAO,MAAM,gCAAgC,UACpC,aAAa,KAAiB,MAyBpC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeprecateStrayNodeIdFieldsPlugin = void 0;
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
/**
|
|
6
|
+
* NodePlugin is excluded by default to remove all references of NodeId fields
|
|
7
|
+
* and byNodeId operations. A few such instances are not removed and handled
|
|
8
|
+
* explicitly by this plugin, e.g. deletedEntityNodeId in the
|
|
9
|
+
* DeleteEntityPayload types.
|
|
10
|
+
*
|
|
11
|
+
* By default, the plugin marks each field as deprecated. Pass an explicit
|
|
12
|
+
* `DROP` value to drop the fields instead.
|
|
13
|
+
*/
|
|
14
|
+
const DeprecateStrayNodeIdFieldsPlugin = (mode = 'DEPRECATE') => (builder) => {
|
|
15
|
+
builder.hook('GraphQLObjectType:fields', (fields, _build, context) => {
|
|
16
|
+
const typeName = context.Self.name;
|
|
17
|
+
if (typeName.startsWith('Delete') && typeName.endsWith('Payload')) {
|
|
18
|
+
Object.keys(fields)
|
|
19
|
+
.filter((name) => name.startsWith('deleted') && name.endsWith('NodeId'))
|
|
20
|
+
.map((name) => {
|
|
21
|
+
switch (mode) {
|
|
22
|
+
case 'DEPRECATE':
|
|
23
|
+
fields[name].deprecationReason = 'The field is obsolete.';
|
|
24
|
+
break;
|
|
25
|
+
case 'DROP':
|
|
26
|
+
delete fields[name];
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
throw new common_1.UnreachableCaseError(mode);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return fields;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
exports.DeprecateStrayNodeIdFieldsPlugin = DeprecateStrayNodeIdFieldsPlugin;
|
|
37
|
+
//# sourceMappingURL=deprecate-stray-node-id-fields-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecate-stray-node-id-fields-plugin.js","sourceRoot":"","sources":["../../src/plugins/deprecate-stray-node-id-fields-plugin.ts"],"names":[],"mappings":";;;AACA,sCAAiD;AAIjD;;;;;;;;GAQG;AACI,MAAM,gCAAgC,GAC3C,CAAC,OAAsB,WAAW,EAAU,EAAE,CAC9C,CAAC,OAAO,EAAE,EAAE;IACV,OAAO,CAAC,IAAI,CAAC,0BAA0B,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;QACnE,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,IAAc,CAAC;QAC7C,IAAI,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YACjE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;iBAChB,MAAM,CACL,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAChE;iBACA,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;gBACZ,QAAQ,IAAI,EAAE;oBACZ,KAAK,WAAW;wBACd,MAAM,CAAC,IAAI,CAAC,CAAC,iBAAiB,GAAG,wBAAwB,CAAC;wBAC1D,MAAM;oBACR,KAAK,MAAM;wBACT,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;wBACpB,MAAM;oBAER;wBACE,MAAM,IAAI,6BAAoB,CAAC,IAAI,CAAC,CAAC;iBACxC;YACH,CAAC,CAAC,CAAC;SACN;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA1BS,QAAA,gCAAgC,oCA0BzC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import GraphQL from 'graphql';
|
|
2
|
+
import { Plugin } from 'postgraphile';
|
|
3
|
+
/**
|
|
4
|
+
* A collection of parameters to decide on which entities and by which criteria bulk operation should be performed.
|
|
5
|
+
*/
|
|
6
|
+
export interface BulkFilter {
|
|
7
|
+
tableName: string;
|
|
8
|
+
primaryKeyName: string;
|
|
9
|
+
primaryKeyType: string;
|
|
10
|
+
filterType: GraphQL.GraphQLInputType;
|
|
11
|
+
filterName: string;
|
|
12
|
+
queryName: string;
|
|
13
|
+
typeName: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Interface for specifying bulk action endpoint name
|
|
17
|
+
*/
|
|
18
|
+
export interface CustomBulkSettings {
|
|
19
|
+
graphQLEndpointName: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Callback that decides for which filters a bulk action is defined
|
|
23
|
+
*/
|
|
24
|
+
export interface DefinePlugin {
|
|
25
|
+
(filter: BulkFilter): CustomBulkSettings | undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parameters that GenericBulkPluginFactory will provide to the callback, so that the actual bulk operation can be performed.
|
|
29
|
+
*/
|
|
30
|
+
export interface BulkIdParameters {
|
|
31
|
+
entityIds: number[] | string[];
|
|
32
|
+
entityType: string;
|
|
33
|
+
primaryKeyName: string;
|
|
34
|
+
tableName: string;
|
|
35
|
+
graphQLAdditionalInput: unknown;
|
|
36
|
+
graphQLContext: {
|
|
37
|
+
[str: string]: unknown;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Plugin factory to create bulk mutations based on query filters
|
|
42
|
+
* @param callback The callback that shall perform the actual bulk operation. It
|
|
43
|
+
* receives different parameters from the base plugin to assist with the
|
|
44
|
+
* operation, e.g. a list of ids for which the bulk operation shall be performed.
|
|
45
|
+
* @param definePlugin The callback that decides for which filters a bulk action is defined.
|
|
46
|
+
* @param inputType Defines additional input parameters for the bulk action. The values are forwarded as part of the message payload.
|
|
47
|
+
*/
|
|
48
|
+
export declare const GenericBulkPluginFactory: (callback: (parameters: BulkIdParameters) => Promise<void>, definePlugin: DefinePlugin, inputType?: GraphQL.GraphQLInputObjectType) => Plugin;
|
|
49
|
+
//# sourceMappingURL=generic-bulk-plugin-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic-bulk-plugin-factory.d.ts","sourceRoot":"","sources":["../../src/plugins/generic-bulk-plugin-factory.ts"],"names":[],"mappings":"AAEA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAS,MAAM,EAAE,MAAM,cAAc,CAAC;AAG7C;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC,gBAAgB,CAAC;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,CAAC,MAAM,EAAE,UAAU,GAAG,kBAAkB,GAAG,SAAS,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB,EAAE,OAAO,CAAC;IAChC,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CAC5C;AAgHD;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,0BACV,gBAAgB,KAAG,QAAQ,IAAI,CAAC,gBAC3C,YAAY,cACd,QAAQ,sBAAsB,KACzC,MAiJF,CAAC"}
|