@coderich/autograph 0.13.41 → 0.13.42

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
  "main": "index.js",
4
- "version": "0.13.41",
4
+ "version": "0.13.42",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -50,6 +50,11 @@ module.exports = class Loader {
50
50
  const values = Array.from(new Set(batches.map(batch => batch.values).flat()));
51
51
  const $query = { ...batches[0].$query, op: 'findMany', where: { [key]: values } };
52
52
 
53
+ //
54
+ if (values.length < 3) {
55
+ return batches.map(batch => this.#model.source.client.resolve(batch.$query).then(data => ({ data, ...batch })));
56
+ }
57
+
53
58
  // Collect all the $values (Regular Expressions) to match doc (result) data by
54
59
  const $values = Array.from(new Set(batches.map(batch => batch.$values).flat()));
55
60
  const docsByRegExpKey = $values.reduce((map, re) => map.set(re, []), new Map());
@@ -205,7 +205,22 @@ module.exports = class Resolver {
205
205
  return this.toResultSet(model, results);
206
206
  });
207
207
  } else {
208
- thunk = tquery => this.#dataLoaders[model].resolve(tquery);
208
+ thunk = (tquery) => {
209
+ const { where, op } = query.toObject();
210
+ const values = Object.values(where);
211
+ const $values = values.flat();
212
+ const skipQuery = values.length && (!$values.length || $values.includes(undefined));
213
+
214
+ if (skipQuery) {
215
+ switch (op) {
216
+ case 'count': return Promise.resolve(0);
217
+ case 'findMany': return Promise.resolve([]);
218
+ default: return Promise.resolve(null);
219
+ }
220
+ }
221
+
222
+ return this.#dataLoaders[model].resolve(tquery);
223
+ };
209
224
  }
210
225
 
211
226
  return this.#createSystemEvent(query, (tquery) => {