@coderich/autograph 0.14.1 → 0.14.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/package.json +1 -1
- package/src/data/Pipeline.js +1 -0
- package/src/data/Resolver.js +1 -1
- package/src/schema/Schema.js +5 -3
package/package.json
CHANGED
package/src/data/Pipeline.js
CHANGED
|
@@ -63,6 +63,7 @@ module.exports = class Pipeline {
|
|
|
63
63
|
Pipeline.define('$construct', params => Pipeline.resolve(params, 'construct'), { ignoreNull: false });
|
|
64
64
|
Pipeline.define('$restruct', params => Pipeline.resolve(params, 'restruct'), { ignoreNull: false });
|
|
65
65
|
Pipeline.define('$serialize', params => Pipeline.resolve(params, 'serialize'), { ignoreNull: false });
|
|
66
|
+
Pipeline.define('$deserialize', params => Pipeline.resolve(params, 'deserialize'), { ignoreNull: false });
|
|
66
67
|
Pipeline.define('$validate', params => Pipeline.resolve(params, 'validate'), { ignoreNull: false });
|
|
67
68
|
|
|
68
69
|
//
|
package/src/data/Resolver.js
CHANGED
|
@@ -245,7 +245,7 @@ module.exports = class Resolver {
|
|
|
245
245
|
model = this.#schema.models[model];
|
|
246
246
|
|
|
247
247
|
return Object.defineProperties(Util.map(result, (doc) => {
|
|
248
|
-
const $doc = model.docTransform(doc);
|
|
248
|
+
const $doc = model.docTransform(doc, { resolver: this, context: this.#context });
|
|
249
249
|
|
|
250
250
|
// Assign useful/needed meta data
|
|
251
251
|
return Object.defineProperties($doc, {
|
package/src/schema/Schema.js
CHANGED
|
@@ -16,7 +16,7 @@ const scalarKinds = [Kind.SCALAR_TYPE_DEFINITION, Kind.SCALAR_TYPE_EXTENSION];
|
|
|
16
16
|
const fieldKinds = [Kind.FIELD_DEFINITION];
|
|
17
17
|
const modelKinds = [Kind.OBJECT_TYPE_DEFINITION, Kind.OBJECT_TYPE_EXTENSION].concat(interfaceKinds);
|
|
18
18
|
const allowedKinds = modelKinds.concat(fieldKinds).concat(Kind.DOCUMENT, Kind.NON_NULL_TYPE, Kind.NAMED_TYPE, Kind.LIST_TYPE, Kind.DIRECTIVE).concat(scalarKinds).concat(enumKinds);
|
|
19
|
-
const pipelines = ['validate', 'construct', 'restruct', 'instruct', 'normalize', 'serialize'];
|
|
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
22
|
// const validatePipelines = ['validate', 'instruct', 'normalize', 'serialize'];
|
|
@@ -473,14 +473,15 @@ module.exports = class Schema {
|
|
|
473
473
|
|
|
474
474
|
// Deserialize/docs special case handling for performance
|
|
475
475
|
const docFields = Object.values($model.fields);
|
|
476
|
-
$model.docTransform = (doc) => {
|
|
476
|
+
$model.docTransform = (doc, args = {}) => {
|
|
477
477
|
if (doc == null) return doc;
|
|
478
478
|
const out = {};
|
|
479
479
|
for (const docField of docFields) {
|
|
480
480
|
let value = docField.key in doc ? doc[docField.key] : docField.defaultValue;
|
|
481
481
|
if (value === undefined) continue; // eslint-disable-line
|
|
482
482
|
if (docField.isArray) value = value == null ? value : Util.ensureArray(value);
|
|
483
|
-
if (docField.isEmbedded) value = Util.map(value, v => docField.model.docTransform(v));
|
|
483
|
+
if (docField.isEmbedded) value = Util.map(value, v => docField.model.docTransform(v, args));
|
|
484
|
+
if (docField.pipelines.deserialize.length) value = Pipeline.resolve({ ...args, model: $model, field: docField, value }, 'deserialize');
|
|
484
485
|
out[docField.name] = value;
|
|
485
486
|
}
|
|
486
487
|
return out;
|
|
@@ -707,6 +708,7 @@ module.exports = class Schema {
|
|
|
707
708
|
construct: [AutoGraphPipelineEnum!]
|
|
708
709
|
restruct: [AutoGraphPipelineEnum!]
|
|
709
710
|
serialize: [AutoGraphPipelineEnum!]
|
|
711
|
+
deserialize: [AutoGraphPipelineEnum!]
|
|
710
712
|
validate: [AutoGraphPipelineEnum!]
|
|
711
713
|
|
|
712
714
|
# TEMP TO APPEASE TRANSITION
|