@coderich/autograph 0.13.2 → 0.13.4

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.2",
4
+ "version": "0.13.4",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -48,7 +48,8 @@ module.exports = class Resolver {
48
48
  }
49
49
 
50
50
  raw(model) {
51
- return this.toModel(model)?.source?.client?.driver(model);
51
+ model = this.toModel(model);
52
+ return model?.source?.client?.driver(model.key);
52
53
  }
53
54
 
54
55
  graphql(args) {
@@ -32,6 +32,7 @@ module.exports = class Query {
32
32
  toCacheKey() {
33
33
  return {
34
34
  op: this.#query.op,
35
+ select: this.#query.select,
35
36
  where: this.#query.where,
36
37
  sort: this.#query.sort,
37
38
  joins: this.#query.joins,
@@ -76,7 +77,7 @@ module.exports = class Query {
76
77
 
77
78
  const query = this.clone({
78
79
  model: this.#model.key,
79
- select: Object.values(this.#model.fields).map(field => field.key),
80
+ select: this.#query.select.map(name => this.#model.fields[name].key),
80
81
  input: this.#model.walk(input, node => node.value !== undefined && Object.assign(node, { key: node.field.key })),
81
82
  where: isNative ? where : this.#model.walk(where, node => Object.assign(node, { key: node.field.key })),
82
83
  sort: this.#model.walk(sort, node => Object.assign(node, { key: node.field.key })),
@@ -2,19 +2,21 @@ const Query = require('./Query');
2
2
  const { getGQLReturnType, getGQLSelectFields, mergeDeep } = require('../service/AppService');
3
3
 
4
4
  module.exports = class QueryBuilder {
5
- #config;
6
5
  #query;
6
+ #config;
7
7
  #terminalCommands = ['one', 'many', 'count', 'save', 'delete', 'first', 'last', 'push', 'pull', 'splice'];
8
8
 
9
9
  constructor(config) {
10
- const { query } = config;
10
+ const { schema, query } = config;
11
11
 
12
12
  this.#config = config;
13
+ const model = schema.models[query.model];
13
14
 
14
15
  this.#query = Object.defineProperties(query, {
15
16
  id: { writable: true, enumerable: true, value: query.id },
16
17
  args: { writable: true, enumerable: true, value: query.args || {} },
17
18
  flags: { writable: true, enumerable: true, value: query.flags || {} },
19
+ select: { writable: true, enumerable: true, value: query.select || Object.keys(model.fields) },
18
20
  options: { writable: true, enumerable: true, value: query.options || {} },
19
21
  });
20
22
 
@@ -41,8 +43,6 @@ module.exports = class QueryBuilder {
41
43
  * For use in GraphQL resolver methods to return the "correct" response
42
44
  */
43
45
  resolve(info) {
44
- this.info(info);
45
-
46
46
  switch (getGQLReturnType(info)) {
47
47
  case 'array': return this.many();
48
48
  case 'number': return this.count();