@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 +1 -1
- package/src/core/Resolver.js +10 -3
- package/src/driver/MongoDriver.js +1 -1
package/package.json
CHANGED
package/src/core/Resolver.js
CHANGED
|
@@ -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
|
|
61
|
+
return get(doc, 'count', 0);
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
64
|
}
|