@coderich/autograph 0.10.22 → 0.10.23

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.23",
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,13 +76,16 @@ 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
85
 
86
+ // Prevent udpates when no data has changed
87
+ if (get(flags, 'skipUnchanged') && hashObject(doc) === hashObject(merged)) return doc;
88
+
86
89
  return createSystemEvent('Mutation', { query: query.doc(doc).merged(merged) }, async () => {
87
90
  const payload = model.shapeObject(inputShape, merged, query);
88
91
  await model.validateObject(inputShape, payload, query.payload(payload));