@coderich/autograph 0.13.22 → 0.13.23

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.22",
4
+ "version": "0.13.23",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -229,7 +229,7 @@ module.exports = class Resolver {
229
229
  return (...args) => {
230
230
  switch (cmd) {
231
231
  case 'save': {
232
- return queryResolver.save({ ...$doc, ...args[0] });
232
+ return queryResolver.save({ ...$doc, ...args[0] }); // $doc incase it's mutated
233
233
  }
234
234
  case 'lookup': {
235
235
  const field = self.toModel(model).fields[args[0]];
@@ -1,6 +1,6 @@
1
1
  const Util = require('@coderich/util');
2
2
  const Pipeline = require('../data/Pipeline');
3
- const { isGlob, globToRegex, mergeDeep, finalizeWhereClause } = require('../service/AppService');
3
+ const { isGlob, globToRegex, mergeDeep, finalizeWhereClause, JSONParse } = require('../service/AppService');
4
4
 
5
5
  module.exports = class Query {
6
6
  #config;
@@ -82,8 +82,8 @@ module.exports = class Query {
82
82
  input: this.#model.walk(input, node => node.value !== undefined && Object.assign(node, { key: node.field.key })),
83
83
  where: isNative ? where : this.#model.walk(where, node => Object.assign(node, { key: node.field.key })),
84
84
  sort: this.#model.walk(sort, node => Object.assign(node, { key: node.field.key })),
85
- before: (!isCursorPaging || !before) ? undefined : JSON.parse(Buffer.from(before, 'base64').toString('ascii')),
86
- after: (!isCursorPaging || !after) ? undefined : JSON.parse(Buffer.from(after, 'base64').toString('ascii')),
85
+ before: (!isCursorPaging || !before) ? undefined : JSONParse(Buffer.from(before, 'base64').toString('ascii')),
86
+ after: (!isCursorPaging || !after) ? undefined : JSONParse(Buffer.from(after, 'base64').toString('ascii')),
87
87
  $schema: this.#schema.resolvePath,
88
88
  });
89
89
 
@@ -68,7 +68,7 @@ module.exports = class QueryBuilder {
68
68
  }
69
69
 
70
70
  info(info) {
71
- this.select(getGQLSelectFields(this.#query.model, info));
71
+ // this.select(getGQLSelectFields(this.#query.model, info));
72
72
  return this;
73
73
  }
74
74
 
@@ -82,7 +82,7 @@ module.exports = class QueryBuilder {
82
82
  }
83
83
 
84
84
  where(clause) {
85
- this.#propCheck('where', 'native', false);
85
+ this.#propCheck('where', 'native', false); // Allow redefine of "where" because we merge it
86
86
  const $clause = mergeDeep(this.#query.where || {}, clause);
87
87
  this.#query.where = $clause;
88
88
  this.#query.args.where = $clause;
@@ -589,7 +589,7 @@ module.exports = class Schema {
589
589
  }
590
590
  ${connectionFields.length ? `
591
591
  extend type ${model} {
592
- ${connectionFields.map(field => `${field}: ${field.model}Connection`)}
592
+ ${connectionFields.map(field => `${field}(${Schema.#getConnectionArguments(field.model)}): ${field.model}Connection`)}
593
593
  }
594
594
  ` : ''}
595
595
  `;
@@ -619,16 +619,7 @@ module.exports = class Schema {
619
619
  node(id: ID!): Node
620
620
  ${queryModels.map(model => `
621
621
  get${model}(id: ID!): ${model}
622
- find${model}(
623
- where: ${model}InputWhere
624
- sortBy: ${model}InputSort
625
- limit: Int
626
- skip: Int
627
- first: Int
628
- after: String
629
- last: Int
630
- before: String
631
- ): ${model}Connection!
622
+ find${model}(${Schema.#getConnectionArguments(model)}): ${model}Connection!
632
623
  `)}
633
624
  }
634
625
 
@@ -713,13 +704,7 @@ module.exports = class Schema {
713
704
  Query: queryModels.reduce((prev, model) => {
714
705
  return Object.assign(prev, {
715
706
  [`get${model}`]: (doc, args, context, info) => context[schema.namespace].resolver.match(model).args(args).info(info).one({ required: true }),
716
- [`find${model}`]: (doc, args, context, info) => {
717
- return {
718
- edges: () => context[schema.namespace].resolver.match(model).args(args).info(info).many(),
719
- count: () => context[schema.namespace].resolver.match(model).args(args).info(info).count(),
720
- pageInfo: () => context[schema.namespace].resolver.match(model).args(args).info(info).many(),
721
- };
722
- },
707
+ [`find${model}`]: (doc, args, context, info) => context[schema.namespace].resolver.match(model).args(args).info(info).resolve(info),
723
708
  });
724
709
  }, {
725
710
  node: (doc, args, context, info) => {
@@ -746,7 +731,7 @@ module.exports = class Schema {
746
731
  [model]: Object.values(model.fields).filter(field => field.model?.isEntity).reduce((prev2, field) => {
747
732
  return Object.assign(prev2, {
748
733
  [field]: (doc, args, context, info) => {
749
- return context[schema.namespace].resolver.match(field.model).where({ [field.linkBy]: doc[field.linkField.name] }).args(args).info(info).resolve(info);
734
+ return doc.$.lookup(field).args(args).info(info).resolve(info);
750
735
  },
751
736
  });
752
737
  }, {}),
@@ -767,6 +752,19 @@ module.exports = class Schema {
767
752
  return type;
768
753
  }
769
754
 
755
+ static #getConnectionArguments(model) {
756
+ return `
757
+ where: ${model}InputWhere
758
+ sortBy: ${model}InputSort
759
+ limit: Int
760
+ skip: Int
761
+ first: Int
762
+ after: String
763
+ last: Int
764
+ before: String
765
+ `;
766
+ }
767
+
770
768
  static #identifyOnDeletes(models, parentName) {
771
769
  return models.reduce((prev, model) => {
772
770
  Object.values(model.fields).filter(f => f.onDelete).forEach((field) => {
@@ -43,3 +43,12 @@ exports.getGQLSelectFields = (model, info) => {
43
43
  // return value === undefined ? prev : Object.assign(prev, { [key]: value });
44
44
  // }, {}));
45
45
  // };
46
+
47
+ exports.JSONParse = (mixed) => {
48
+ try {
49
+ const json = JSON.parse(mixed);
50
+ return json;
51
+ } catch (e) {
52
+ return undefined;
53
+ }
54
+ };