@coderich/autograph 0.13.26 → 0.13.27

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.26",
4
+ "version": "0.13.27",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -190,13 +190,11 @@ module.exports = class Resolver {
190
190
  */
191
191
  async resolve(query) {
192
192
  let thunk;
193
- const { model, crud, isMutation, flags } = query.toObject();
193
+ const { doc, model, crud, isMutation, flags } = query.toObject();
194
194
  const currSession = this.#sessions.slice(-1).pop();
195
195
 
196
196
  if (isMutation) {
197
197
  thunk = tquery => this.#schema.models[model].source.client.resolve(tquery.toDriver().toObject()).then((results) => {
198
- const { doc, input } = tquery.toObject();
199
-
200
198
  // We clear the cache immediately (regardless if we're in transaction or not)
201
199
  this.clear(model);
202
200
 
@@ -205,7 +203,6 @@ module.exports = class Resolver {
205
203
 
206
204
  // Return results
207
205
  if (crud === 'delete') return doc;
208
- if (crud === 'update') return input;
209
206
  return this.toResultSet(model, results);
210
207
  });
211
208
  } else {
@@ -261,6 +258,15 @@ module.exports = class Resolver {
261
258
  },
262
259
  $model: { value: model },
263
260
  $cursor: { value: doc.$cursor },
261
+ // Backwards compat
262
+ $save: { value: (...args) => $doc.$.save(...args) },
263
+ $lookup: {
264
+ value: async (prop, args) => {
265
+ const field = model.fields[prop];
266
+ const method = field.isArray ? 'many' : 'one';
267
+ return $doc.$.lookup(prop).args(args)[method]();
268
+ },
269
+ },
264
270
  });
265
271
  }), {
266
272
  $pageInfo: { value: result.$pageInfo },
@@ -34,7 +34,7 @@ module.exports = class QueryResolver extends QueryBuilder {
34
34
  }
35
35
  case 'updateOne': {
36
36
  return this.#get(query).then((doc) => {
37
- const merged = mergeDeep({}, Util.unflatten(doc, { safe: true }), Util.unflatten(input, { safe: true }));
37
+ const merged = mergeDeep({}, doc, Util.unflatten(input, { safe: true }));
38
38
  return this.#resolver.resolve(query.clone({ doc, input: merged }));
39
39
  });
40
40
  }
@@ -164,13 +164,15 @@ module.exports = class Schema {
164
164
  }
165
165
 
166
166
  if (enumKinds.includes(node.kind)) {
167
+ const values = Schema.#resolveNodeValue(node);
168
+
167
169
  target = this.#schema.enums[name] = {
170
+ values,
168
171
  directives: {},
169
172
  pipelines: pipelines.reduce((prev, key) => Object.assign(prev, { [key]: [] }), {}),
170
173
  };
171
174
 
172
175
  // Define (and assign) an Allow pipeline for the enumeration
173
- const values = Schema.#resolveNodeValue(node);
174
176
  Pipeline.define(name, Pipeline.Allow(...values), { configurable: true });
175
177
  target.pipelines.finalize.push(name);
176
178
  }
@@ -360,7 +362,10 @@ module.exports = class Schema {
360
362
  // Merge Enums and Scalar type definitions
361
363
  const enumer = this.#schema.enums[$field.type];
362
364
  const scalar = this.#schema.scalars[$field.type];
363
- if (enumer) Object.entries(enumer.pipelines).forEach(([key, values]) => $field.pipelines[key].push(...values));
365
+ if (enumer) {
366
+ $field.allows = enumer.values;
367
+ Object.entries(enumer.pipelines).forEach(([key, values]) => $field.pipelines[key].push(...values));
368
+ }
364
369
  if (scalar) Object.entries(scalar.pipelines).forEach(([key, values]) => $field.pipelines[key].push(...values));
365
370
 
366
371
  if ($field.isArray) $field.pipelines.normalize.unshift('toArray');
@@ -745,6 +750,7 @@ module.exports = class Schema {
745
750
  [model]: Object.values(model.fields).filter(field => field.model?.isEntity).reduce((prev2, field) => {
746
751
  return Object.assign(prev2, {
747
752
  [field]: (doc, args, context, info) => {
753
+ if (!doc.$) doc = context[schema.namespace].resolver.toResultSet(model, doc); // Ensure resultSet
748
754
  return doc.$.lookup(field).args(args).info(info).resolve(info);
749
755
  },
750
756
  });