@coderich/autograph 0.13.5 → 0.13.6

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.5",
4
+ "version": "0.13.6",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -23,7 +23,7 @@ module.exports = class Resolver {
23
23
  this.#dataLoaders = this.#createDataLoaders();
24
24
  this.driver = this.raw; // Alias
25
25
  this.model = this.match; // Alias
26
- Util.set(this.#context, 'autograph.resolver', this);
26
+ Util.set(this.#context, `${this.#schema.namespace}.resolver`, this);
27
27
  }
28
28
 
29
29
  getContext() {
@@ -23,6 +23,7 @@ module.exports = class Schema {
23
23
 
24
24
  constructor(config) {
25
25
  this.#config = config;
26
+ this.#config.namespace ??= 'autograph';
26
27
  this.#typeDefs = Schema.#framework();
27
28
  }
28
29
 
@@ -66,7 +67,16 @@ module.exports = class Schema {
66
67
  else if (schema instanceof Schema) schema = schema.toObject();
67
68
 
68
69
  if (schema.typeDefs) {
69
- const typeDefs = Util.ensureArray(schema.typeDefs).map(td => (typeof td === 'string' ? parse(td) : td));
70
+ const typeDefs = Util.ensureArray(schema.typeDefs).map((td) => {
71
+ try {
72
+ const $td = typeof td === 'string' ? parse(td) : td;
73
+ return $td;
74
+ } catch (e) {
75
+ console.log(`Unable to parse typeDef (being ignored):\n${td}`); // eslint-disable-line
76
+ return null;
77
+ }
78
+ }).filter(Boolean);
79
+
70
80
  this.#typeDefs = mergeTypeDefs([typeDefs, this.#typeDefs], { noLocation: true, reverseDirectives: true, onFieldTypeConflict: a => a });
71
81
  }
72
82
 
@@ -84,7 +94,7 @@ module.exports = class Schema {
84
94
  if (this.#schema) return this.#schema;
85
95
 
86
96
  // const schema = buildASTSchema(this.#typeDefs);
87
- this.#schema = { types: {}, models: {}, indexes: [] };
97
+ this.#schema = { types: {}, models: {}, indexes: [], namespace: this.#config.namespace };
88
98
  let model, field, isField, isList;
89
99
  const thunks = [];
90
100
 
@@ -535,12 +545,12 @@ module.exports = class Schema {
535
545
  }, {}),
536
546
  Query: queryModels.reduce((prev, model) => {
537
547
  return Object.assign(prev, {
538
- [`get${model}`]: (doc, args, context, info) => context.autograph.resolver.match(model).args(args).info(info).one({ required: true }),
548
+ [`get${model}`]: (doc, args, context, info) => context[schema.namespace].resolver.match(model).args(args).info(info).one({ required: true }),
539
549
  [`find${model}`]: (doc, args, context, info) => {
540
550
  return {
541
- edges: () => context.autograph.resolver.match(model).args(args).info(info).many(),
542
- count: () => context.autograph.resolver.match(model).args(args).info(info).count(),
543
- pageInfo: () => context.autograph.resolver.match(model).args(args).info(info).many(),
551
+ edges: () => context[schema.namespace].resolver.match(model).args(args).info(info).many(),
552
+ count: () => context[schema.namespace].resolver.match(model).args(args).info(info).count(),
553
+ pageInfo: () => context[schema.namespace].resolver.match(model).args(args).info(info).many(),
544
554
  };
545
555
  },
546
556
  });
@@ -549,7 +559,7 @@ module.exports = class Schema {
549
559
  const { id } = args;
550
560
  const [modelName] = fromGUID(id);
551
561
  const model = schema.models[modelName];
552
- return context.autograph.resolver.match(model).id(id).info(info).one().then((result) => {
562
+ return context[schema.namespace].resolver.match(model).id(id).info(info).one().then((result) => {
553
563
  if (result == null) return result;
554
564
  result.__typename = modelName; // eslint-disable-line no-underscore-dangle
555
565
  return result;
@@ -558,9 +568,9 @@ module.exports = class Schema {
558
568
  }),
559
569
  ...(mutationModels.length ? {
560
570
  Mutation: mutationModels.reduce((prev, model) => {
561
- if (model.crud?.includes('c')) prev[`create${model}`] = (doc, args, context, info) => context.autograph.resolver.match(model).args(args).info(info).save(args.input);
562
- if (model.crud?.includes('u')) prev[`update${model}`] = (doc, args, context, info) => context.autograph.resolver.match(model).args(args).info(info).save(args.input);
563
- if (model.crud?.includes('d')) prev[`delete${model}`] = (doc, args, context, info) => context.autograph.resolver.match(model).args(args).info(info).delete();
571
+ if (model.crud?.includes('c')) prev[`create${model}`] = (doc, args, context, info) => context[schema.namespace].resolver.match(model).args(args).info(info).save(args.input);
572
+ if (model.crud?.includes('u')) prev[`update${model}`] = (doc, args, context, info) => context[schema.namespace].resolver.match(model).args(args).info(info).save(args.input);
573
+ if (model.crud?.includes('d')) prev[`delete${model}`] = (doc, args, context, info) => context[schema.namespace].resolver.match(model).args(args).info(info).delete();
564
574
  return prev;
565
575
  }, {}),
566
576
  } : {}),
@@ -569,7 +579,7 @@ module.exports = class Schema {
569
579
  [model]: Object.values(model.fields).filter(field => field.model?.isEntity).reduce((prev2, field) => {
570
580
  return Object.assign(prev2, {
571
581
  [field]: (doc, args, context, info) => {
572
- return context.autograph.resolver.match(field.model).where({ [field.linkBy]: doc[field.linkField.name] }).args(args).info(info).resolve(info);
582
+ return context[schema.namespace].resolver.match(field.model).where({ [field.linkBy]: doc[field.linkField.name] }).args(args).info(info).resolve(info);
573
583
  },
574
584
  });
575
585
  }, {}),