@coderich/autograph 0.10.13 → 0.10.15

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
  "author": "Richard Livolsi (coderich)",
4
- "version": "0.10.13",
4
+ "version": "0.10.15",
5
5
  "description": "AutoGraph",
6
6
  "keywords": [
7
7
  "graphql",
@@ -30,6 +30,7 @@
30
30
  "ratchet": "ratchet"
31
31
  },
32
32
  "dependencies": {
33
+ "@coderich/util": "^0.1.0",
33
34
  "@hapi/boom": "^9.1.0",
34
35
  "dataloader": "^2.0.0",
35
36
  "deepmerge": "^4.2.2",
package/src/data/Model.js CHANGED
@@ -1,4 +1,6 @@
1
1
  const Stream = require('stream');
2
+ const { get } = require('lodash');
3
+ const { flatten } = require('@coderich/util');
2
4
  const Field = require('./Field');
3
5
  const Model = require('../graphql/ast/Model');
4
6
  const { eventEmitter } = require('../service/event.service');
@@ -129,13 +131,14 @@ module.exports = class extends Model {
129
131
  shape.model = this;
130
132
  shape.serdes = serdes;
131
133
  shape.target = target;
134
+ // console.log(shape.modelRef);
132
135
 
133
136
  // Cache and return
134
137
  this.shapesCache.set(cacheKey, shape);
135
138
  return shape;
136
139
  }
137
140
 
138
- shapeObject(shape, obj, query, root, base) {
141
+ shapeObject(shape, obj, query, root, base, toFlat = false) {
139
142
  const { serdes, model } = shape;
140
143
  const { context, resolver, doc = {}, flags = {} } = query.toObject();
141
144
  const { pipeline } = flags;
@@ -170,7 +173,13 @@ module.exports = class extends Model {
170
173
  if (!instructed && subShape && typeof transformedValue !== 'object') return prev;
171
174
 
172
175
  // Rename key & assign value
173
- prev[to] = (!subShape || transformedValue == null) ? transformedValue : this.shapeObject(subShape, transformedValue, query, root, base);
176
+ prev[to] = (!subShape || transformedValue == null) ? transformedValue : this.shapeObject(subShape, transformedValue, query, root, base, toFlat);
177
+
178
+ if (toFlat && get(doc, to) && field.getModelRef()) {
179
+ const val = prev[to];
180
+ delete prev[to];
181
+ Object.assign(prev, flatten({ [to]: val }, { safe: true }));
182
+ }
174
183
 
175
184
  return prev;
176
185
  }, {});
@@ -1,5 +1,6 @@
1
1
  const Util = require('util');
2
2
  const { get } = require('lodash');
3
+ const { unflatten } = require('@coderich/util');
3
4
  const { MongoClient, ObjectId } = require('mongodb');
4
5
  const { map, ensureArray, proxyDeep, toKeyObj, globToRegex, proxyPromise, isScalarDataType, promiseRetry } = require('../service/app.service');
5
6
 
@@ -71,7 +72,7 @@ module.exports = class MongoDriver {
71
72
 
72
73
  updateOne({ model, where, $doc, options, flags }) {
73
74
  const $update = { $set: $doc };
74
- return this.query(model, 'updateOne', where, $update, options, flags).then(() => $doc);
75
+ return this.query(model, 'updateOne', where, $update, options, flags).then(() => unflatten($doc));
75
76
  }
76
77
 
77
78
  deleteOne({ model, where, options, flags }) {
@@ -86,7 +86,8 @@ module.exports = class QueryResolver {
86
86
  return createSystemEvent('Mutation', { query: query.doc(doc).merged(merged) }, async () => {
87
87
  const payload = model.shapeObject(inputShape, merged, query);
88
88
  await model.validateObject(inputShape, payload, query.payload(payload));
89
- return this.resolver.resolve(query.$doc(model.shapeObject(docShape, payload, query)));
89
+ const $doc = model.shapeObject(docShape, payload, query, undefined, undefined, true);
90
+ return this.resolver.resolve(query.$doc($doc));
90
91
  });
91
92
  });
92
93
  }
package/CHANGELOG.md DELETED
@@ -1,41 +0,0 @@
1
- # CHANGELOG
2
-
3
- ## v0.10.x
4
- - Replaced ResultSet -> POJOs
5
- - Removed all $field methods (auto populated)
6
- - Removed .toObject()
7
- - $model $save remove $delete $lookup $cursor $pageInfo
8
- - Removed embedded API completely
9
- - Removed Directives
10
- - embedApi -> no replacement
11
- - enforce -> use pipeline methods
12
- - resolve -> use graphql resolvers
13
- - @value -> use @field.instruct directive
14
- - Removed Model.tform() -> use Model.shapeObject(shape, data)
15
- - Removed Transformer + Rule -> use Pipeline
16
- - Removed many pre-defined rules + transformers
17
- - Moved "validator" to dev dependency -> isEmail
18
- - Added QueryBuilder.resolve() terminal command
19
- - Exported SchemaDecorator -> Schema
20
- - Removed embedded schema SystemEvents (internal emitter also removed)
21
- - Removed spread of arguments in QueryBuilder terminal commands (must pass in array)
22
- - Mutate "merged" instead of "input"
23
- - Validate "payload"
24
-
25
- ## v0.9.x
26
- - Subscriptions API
27
- - postMutation no longer mutates "doc" and adds "result"
28
- - Added onDelete defer option
29
-
30
- ## v0.8.x
31
- - Engine 14+
32
-
33
- ## v0.7.x
34
- - Complete overhaul of Query to Mongo Driver (pagination, sorting, counts, etc)
35
- - Removed countModel Queries from the API (now available as `count` property on `Connetion` types)
36
- - Dropped Neo4J (temporarily)
37
-
38
- ## v0.6.x
39
- - Mongo driver no longer checks for `version` directive
40
- - Models no longer share a Connection type; removing the need to use `... on Model` for GraphQL queries
41
- - Added `@field(connection: Boolean)` parameter to specifically indicate fields that should return a Connection type
package/src/.DS_Store DELETED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file