@coderich/autograph 0.13.73 → 0.13.75

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.73",
4
+ "version": "0.13.75",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -16,7 +16,7 @@
16
16
  "dev": "coderich-dev"
17
17
  },
18
18
  "dependencies": {
19
- "@coderich/util": "1.0.6",
19
+ "@coderich/util": "1.2.1",
20
20
  "@graphql-tools/merge": "9.0.0",
21
21
  "@graphql-tools/resolvers-composition": "7.0.0",
22
22
  "@hapi/boom": "10.0.1",
@@ -34,7 +34,7 @@
34
34
  "devDependencies": {
35
35
  "@apollo/server": "4.9.5",
36
36
  "@coderich/autograph-db-tests": "*",
37
- "@coderich/autograph-mongodb": "0.0.4",
37
+ "@coderich/autograph-mongodb": "*",
38
38
  "@graphql-tools/schema": "10.0.0",
39
39
  "graphql": "16.8.1",
40
40
  "mongodb": "5.9.2",
@@ -43,4 +43,4 @@
43
43
  "peerDependencies": {
44
44
  "graphql": "*"
45
45
  }
46
- }
46
+ }
@@ -66,10 +66,12 @@ module.exports = class Transformer {
66
66
  args.thunks ??= [];
67
67
  this.args(args);
68
68
 
69
- return Util.map(mixed, (data) => {
69
+ const transformed = Util.map(mixed, (data) => {
70
70
  const thunks = Object.defineProperty({}, '$thunks', { value: args.thunks });
71
71
  const $data = Object.assign({}, this.#config.defaults, data); // eslint-disable-line
72
72
  return Object.assign(new Proxy(thunks, this.#operation), $data);
73
73
  });
74
+
75
+ return this.#config.postTransform?.(transformed) || transformed;
74
76
  }
75
77
  };
@@ -71,12 +71,14 @@ module.exports = class Query {
71
71
  * Transform entire query for driver
72
72
  */
73
73
  toDriver() {
74
- const { input, where, sort, before, after, isNative, isCursorPaging } = this.#query;
74
+ const { crud, input, where, sort, before, after, isNative, isCursorPaging } = this.#query;
75
+ let $input = this.#model.transformers.toDriver.transform(input);
76
+ if (crud === 'update') $input = Util.flatten($input, { safe: true, ignorePaths: this.#model.ignorePaths });
75
77
 
76
78
  const query = this.clone({
77
79
  model: this.#model.key,
78
80
  select: this.#query.select.map(name => this.#model.fields[name].key),
79
- input: this.#model.transformers.toDriver.transform(input),
81
+ input: $input,
80
82
  where: isNative ? where : this.#model.walk(where, node => Object.assign(node, { key: node.field.key })),
81
83
  sort: this.#model.walk(sort, node => Object.assign(node, { key: node.field.key })),
82
84
  before: (!isCursorPaging || !before) ? undefined : JSONParse(Buffer.from(before, 'base64').toString('ascii')),
@@ -155,6 +155,7 @@ module.exports = class Schema {
155
155
  doc: new Transformer({ args: { schema: this.#schema, path: [] } }),
156
156
  },
157
157
  directives: {},
158
+ ignorePaths: [],
158
159
  toString: () => name,
159
160
  };
160
161
  }
@@ -491,6 +492,13 @@ module.exports = class Schema {
491
492
  return Object.assign(prev, { [curr.name]: rules });
492
493
  }, {}),
493
494
  });
495
+
496
+ Util.traverse(Object.values($model.fields), (f, info) => {
497
+ const path = info.path.concat(f.name);
498
+ if (f.isEmbedded) return { value: f.model.fields, info: { path } };
499
+ if (f.isScalar) $model.ignorePaths.push(path.join('.'));
500
+ return null;
501
+ }, { path: [] });
494
502
  });
495
503
  } else if (node.kind === Kind.FIELD_DEFINITION) {
496
504
  const $field = field;