@coderich/autograph 0.13.57 → 0.13.59
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coderich/autograph",
|
|
3
3
|
"main": "index.js",
|
|
4
|
-
"version": "0.13.
|
|
4
|
+
"version": "0.13.59",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"!__mocks__"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
-
"
|
|
13
|
+
"publish": "APP_ROOT_PATH=$(pwd) npm run dev npmPublish",
|
|
14
|
+
"test": "NODE_OPTIONS=\"--stack-trace-limit=1000\" jest --config=test/jest.config.js",
|
|
14
15
|
"lint": "eslint --config=.eslintrc ./",
|
|
15
16
|
"dev": "coderich-dev"
|
|
16
17
|
},
|
|
@@ -32,13 +33,12 @@
|
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@apollo/server": "4.9.5",
|
|
36
|
+
"@coderich/autograph-db-tests": "*",
|
|
35
37
|
"@coderich/autograph-mongodb": "0.0.4",
|
|
36
|
-
"@coderich/dev": "0.2.1",
|
|
37
38
|
"@graphql-tools/schema": "10.0.0",
|
|
38
39
|
"graphql": "16.8.1",
|
|
39
40
|
"mongodb": "5.9.2",
|
|
40
|
-
"mongodb-memory-server": "8.13.0"
|
|
41
|
-
"validator": "13.9.0"
|
|
41
|
+
"mongodb-memory-server": "8.13.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"graphql": "*"
|
package/src/data/Pipeline.js
CHANGED
|
@@ -74,10 +74,11 @@ module.exports = class Pipeline {
|
|
|
74
74
|
}, { ignoreNull: false });
|
|
75
75
|
|
|
76
76
|
Pipeline.define('$fk', (params) => {
|
|
77
|
-
const { fkField, isPrimaryKey } = params.field;
|
|
77
|
+
const { fkField, linkTo, isPrimaryKey, generator } = params.field;
|
|
78
78
|
const lookupField = isPrimaryKey ? params.field : fkField;
|
|
79
79
|
const v = params.value?.[lookupField] || params.value;
|
|
80
|
-
|
|
80
|
+
const $generator = isPrimaryKey ? generator : linkTo.fields[fkField].generator;
|
|
81
|
+
return Util.map(v, value => $generator({ ...params, value }));
|
|
81
82
|
});
|
|
82
83
|
|
|
83
84
|
//
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const API = jest.requireActual('../Emitter');
|
|
2
|
+
const { mergeDeep } = require('../../service/AppService');
|
|
3
|
+
|
|
4
|
+
const { emit } = API;
|
|
5
|
+
|
|
6
|
+
API.emit = (eventName, data) => {
|
|
7
|
+
if (API.cloneData) data = { ...data, query: mergeDeep({}, data.query) };
|
|
8
|
+
return emit.call(API, eventName, data);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
module.exports = API;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We need to export Pipeline as a POJO so jest can spy on it
|
|
3
|
+
* This is because all the methods are defined using Object.defineProperty
|
|
4
|
+
*/
|
|
5
|
+
const Pipeline = jest.requireActual('../Pipeline');
|
|
6
|
+
const Util = require('@coderich/util');
|
|
7
|
+
|
|
8
|
+
const API = {};
|
|
9
|
+
|
|
10
|
+
Pipeline.resolve = (params, pipeline) => {
|
|
11
|
+
const transformers = params.field.pipelines[pipeline] || [];
|
|
12
|
+
|
|
13
|
+
return transformers.reduce((value, t) => {
|
|
14
|
+
return Util.uvl(API[t]({ ...params, value }), value);
|
|
15
|
+
}, params.value);
|
|
16
|
+
|
|
17
|
+
// return Util.pipeline(transformers.map(t => (value) => {
|
|
18
|
+
// return API[t]({ ...params, value });
|
|
19
|
+
// }), params.value);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
Object.getOwnPropertyNames(Pipeline).reduce((prev, key) => {
|
|
23
|
+
return Object.assign(prev, { [key]: Pipeline[key] });
|
|
24
|
+
}, API);
|
|
25
|
+
|
|
26
|
+
// For those defined outside of Pipeline.js itself
|
|
27
|
+
API.define = (key, ...args) => {
|
|
28
|
+
Pipeline.define(key, ...args);
|
|
29
|
+
API[key] = Pipeline[key];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = API;
|
package/src/schema/Schema.js
CHANGED
|
@@ -19,7 +19,7 @@ const allowedKinds = modelKinds.concat(fieldKinds).concat(Kind.DOCUMENT, Kind.NO
|
|
|
19
19
|
const pipelines = ['validate', 'construct', 'restruct', 'instruct', 'normalize', 'serialize', 'deserialize'];
|
|
20
20
|
const createPipelines = ['validate', 'construct', 'instruct', 'normalize', 'serialize'];
|
|
21
21
|
const updatePipelines = ['validate', 'restruct', 'instruct', 'normalize', 'serialize'];
|
|
22
|
-
const validatePipelines = ['validate', 'instruct', 'normalize', 'serialize'];
|
|
22
|
+
// const validatePipelines = ['validate', 'instruct', 'normalize', 'serialize'];
|
|
23
23
|
const scalars = ['ID', 'String', 'Float', 'Int', 'Boolean'];
|
|
24
24
|
|
|
25
25
|
module.exports = class Schema {
|
|
@@ -506,7 +506,8 @@ module.exports = class Schema {
|
|
|
506
506
|
$field.linkTo = $schema.models[$field.linkTo];
|
|
507
507
|
$field.crud = Util.uvl($field.crud, $field.model?.scope, 'crud');
|
|
508
508
|
$field.linkBy ??= $field.linkTo?.pkField; // This defines join logic (below) for both straight+virtual references
|
|
509
|
-
$field.fkField ??= $field.
|
|
509
|
+
$field.fkField ??= $field.linkTo?.pkField; // This is the fkReference field for straight references
|
|
510
|
+
// $field.fkField ??= $field.model?.pkField; // This is the fkReference field for straight references
|
|
510
511
|
$field.linkField = $field.isVirtual ? $model.fields[$model.pkField] : $field;
|
|
511
512
|
$field.isFKReference = $field.fkField && !$field.isPrimaryKey && $field.model?.isMarkedModel && !$field.model?.isEmbedded;
|
|
512
513
|
$field.isEmbedded = Boolean($field.model && !$field.isFKReference && !$field.isPrimaryKey);
|