@coderich/autograph 0.9.15 → 0.9.16

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.9.15",
4
+ "version": "0.9.16",
5
5
  "description": "AutoGraph",
6
6
  "keywords": [
7
7
  "graphql",
@@ -87,12 +87,19 @@ module.exports = class Resolver {
87
87
  });
88
88
  }
89
89
  default: {
90
- // This is needed in SF tests...
91
90
  const key = model.idKey();
92
91
  const { where, method } = query.toDriver();
93
- if (Object.prototype.hasOwnProperty.call(where, key) && isEmpty(where[key])) return Promise.resolve(method === 'findMany' ? [] : null);
94
92
 
95
- //
93
+ // This check is to avoid making a db call for no reason
94
+ if (Object.prototype.hasOwnProperty.call(where, key) && isEmpty(where[key])) {
95
+ switch (method) {
96
+ case 'count': return Promise.resolve(0);
97
+ case 'findMany': return Promise.resolve([]);
98
+ default: return Promise.resolve(null);
99
+ }
100
+ }
101
+
102
+ // DB call
96
103
  return this.loaders.get(`${model}`).load(query);
97
104
  }
98
105
  }
@@ -58,7 +58,7 @@ module.exports = class MongoDriver {
58
58
 
59
59
  return this.query(model, 'aggregate', MongoDriver.aggregateQuery(query, true), options, flags).then((cursor) => {
60
60
  return cursor.next().then((doc) => {
61
- return doc ? doc.count : 0;
61
+ return get(doc, 'count', 0);
62
62
  });
63
63
  });
64
64
  }