@coderich/autograph 0.10.5 → 0.10.7
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 +2 -6
- package/src/data/Model.js +14 -8
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coderich/autograph",
|
|
3
3
|
"author": "Richard Livolsi (coderich)",
|
|
4
|
-
"version": "0.10.
|
|
4
|
+
"version": "0.10.7",
|
|
5
5
|
"description": "AutoGraph",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"graphql",
|
|
@@ -42,14 +42,10 @@
|
|
|
42
42
|
"picomatch": "^2.1.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@coderich/ratchet": "^1.5.
|
|
45
|
+
"@coderich/ratchet": "^1.5.8",
|
|
46
46
|
"@graphql-tools/schema": "^9.0.1",
|
|
47
47
|
"graphql": "^15.5.0",
|
|
48
48
|
"mongodb-memory-server": "^8.7.2",
|
|
49
|
-
"neo4j-driver": "^4.0.0",
|
|
50
|
-
"neodb": "^3.0.0",
|
|
51
|
-
"redis": "^2.8.0",
|
|
52
|
-
"redis-mock": "^0.47.0",
|
|
53
49
|
"validator": "^13.7.0"
|
|
54
50
|
},
|
|
55
51
|
"peerDependencies": {
|
package/src/data/Model.js
CHANGED
|
@@ -135,7 +135,7 @@ module.exports = class extends Model {
|
|
|
135
135
|
return shape;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
shapeObject(shape, obj, query, root) {
|
|
138
|
+
shapeObject(shape, obj, query, root, base) {
|
|
139
139
|
const { serdes, model } = shape;
|
|
140
140
|
const { context, resolver, doc = {}, flags = {} } = query.toObject();
|
|
141
141
|
const { pipeline } = flags;
|
|
@@ -143,8 +143,11 @@ module.exports = class extends Model {
|
|
|
143
143
|
if (!pipeline) return obj;
|
|
144
144
|
// const filters = pipeline === true ? [] : Object.entries(pipeline).map(([k, v]) => (v === false ? k : null)).filter(Boolean);
|
|
145
145
|
|
|
146
|
+
// base is the base model
|
|
147
|
+
base = base || model;
|
|
148
|
+
|
|
146
149
|
return map(obj, (parent) => {
|
|
147
|
-
//
|
|
150
|
+
// root is the base data object
|
|
148
151
|
root = root || parent;
|
|
149
152
|
|
|
150
153
|
// Lookup helper functions
|
|
@@ -158,7 +161,7 @@ module.exports = class extends Model {
|
|
|
158
161
|
|
|
159
162
|
// Transform value
|
|
160
163
|
const transformedValue = transformers.reduce((value, t) => {
|
|
161
|
-
const v = t({ model, field, path, docPath, rootPath, parentPath, startValue, value, resolver, context });
|
|
164
|
+
const v = t({ base, model, field, path, docPath, rootPath, parentPath, startValue, value, resolver, context });
|
|
162
165
|
return v === undefined ? value : v;
|
|
163
166
|
}, startValue);
|
|
164
167
|
|
|
@@ -167,22 +170,25 @@ module.exports = class extends Model {
|
|
|
167
170
|
if (!instructed && subShape && typeof transformedValue !== 'object') return prev;
|
|
168
171
|
|
|
169
172
|
// Rename key & assign value
|
|
170
|
-
prev[to] = (!subShape || transformedValue == null) ? transformedValue : this.shapeObject(subShape, transformedValue, query, root);
|
|
173
|
+
prev[to] = (!subShape || transformedValue == null) ? transformedValue : this.shapeObject(subShape, transformedValue, query, root, base);
|
|
171
174
|
|
|
172
175
|
return prev;
|
|
173
176
|
}, {});
|
|
174
177
|
});
|
|
175
178
|
}
|
|
176
179
|
|
|
177
|
-
validateObject(shape, obj, query, root, silent = false) {
|
|
180
|
+
validateObject(shape, obj, query, root, base, silent = false) {
|
|
178
181
|
const { model } = shape;
|
|
179
182
|
const { context, resolver, doc = {}, flags = {} } = query.toObject();
|
|
180
183
|
const { validate = true } = flags;
|
|
181
184
|
|
|
182
185
|
if (!validate) return Promise.resolve();
|
|
183
186
|
|
|
187
|
+
// base is the base model
|
|
188
|
+
base = base || model;
|
|
189
|
+
|
|
184
190
|
return mapPromise(obj, (parent) => {
|
|
185
|
-
//
|
|
191
|
+
// root is the base data object
|
|
186
192
|
root = root || parent;
|
|
187
193
|
|
|
188
194
|
// Lookup helper functions
|
|
@@ -195,10 +201,10 @@ module.exports = class extends Model {
|
|
|
195
201
|
|
|
196
202
|
return Promise.all(validators.map((v) => {
|
|
197
203
|
return new Promise((resolve, reject) => {
|
|
198
|
-
return Promise.resolve(v({ model, field, path, docPath, rootPath, parentPath, startValue: value, value, resolver, context })).then(resolve).catch(reject);
|
|
204
|
+
return Promise.resolve(v({ base, model, field, path, docPath, rootPath, parentPath, startValue: value, value, resolver, context })).then(resolve).catch(reject);
|
|
199
205
|
});
|
|
200
206
|
})).then(() => {
|
|
201
|
-
return subShape ? this.validateObject(subShape, value, query, root, true) : Promise.resolve();
|
|
207
|
+
return subShape ? this.validateObject(subShape, value, query, root, base, true) : Promise.resolve();
|
|
202
208
|
});
|
|
203
209
|
}));
|
|
204
210
|
}).then(() => {
|