@coderich/autograph 0.10.22 → 0.10.24

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
  "author": "Richard Livolsi (coderich)",
4
- "version": "0.10.22",
4
+ "version": "0.10.24",
5
5
  "description": "AutoGraph",
6
6
  "keywords": [
7
7
  "graphql",
@@ -3,7 +3,7 @@ const Boom = require('../core/Boom');
3
3
  const QueryService = require('./QueryService');
4
4
  const DataService = require('../data/DataService');
5
5
  const { createSystemEvent } = require('../service/event.service');
6
- const { mergeDeep, getGQLReturnType } = require('../service/app.service');
6
+ const { mergeDeep, hashObject, getGQLReturnType } = require('../service/app.service');
7
7
 
8
8
  module.exports = class QueryResolver {
9
9
  constructor(query) {
@@ -76,14 +76,23 @@ module.exports = class QueryResolver {
76
76
  }
77
77
 
78
78
  async updateOne(query) {
79
- const { model, match, input } = query.toObject();
79
+ const { model, match, input, flags } = query.toObject();
80
80
  const inputShape = model.getShape('update', 'input');
81
81
  const docShape = model.getShape('update', 'doc');
82
82
 
83
83
  return this.resolver.match(model).match(match).one({ required: true }).then((doc) => {
84
84
  const merged = mergeDeep(doc, input);
85
+ const docHash = hashObject(doc);
86
+ const skipUnchanged = get(flags, 'skipUnchanged');
87
+
88
+ // Prevent udpates when no data has changed
89
+ if (skipUnchanged && docHash === hashObject(merged)) return doc;
85
90
 
86
91
  return createSystemEvent('Mutation', { query: query.doc(doc).merged(merged) }, async () => {
92
+ // Prevent udpates when no data has changed (because merged can be mutated)
93
+ if (skipUnchanged && docHash === hashObject(merged)) return doc;
94
+
95
+ // Process
87
96
  const payload = model.shapeObject(inputShape, merged, query);
88
97
  await model.validateObject(inputShape, payload, query.payload(payload));
89
98
  const $doc = model.shapeObject(docShape, payload, query, undefined, undefined, true);