@coderich/autograph 0.10.6 → 0.10.8

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/CHANGELOG.md ADDED
@@ -0,0 +1,41 @@
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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coderich/autograph",
3
3
  "author": "Richard Livolsi (coderich)",
4
- "version": "0.10.6",
4
+ "version": "0.10.8",
5
5
  "description": "AutoGraph",
6
6
  "keywords": [
7
7
  "graphql",
package/src/.DS_Store ADDED
Binary file
Binary file
Binary file
package/src/data/Model.js CHANGED
@@ -135,7 +135,7 @@ module.exports = class extends Model {
135
135
  return shape;
136
136
  }
137
137
 
138
- shapeObject(shape, obj, query, root) {
138
+ shapeObject(shape, obj, query, root, base) {
139
139
  const { serdes, model } = shape;
140
140
  const { context, resolver, doc = {}, flags = {} } = query.toObject();
141
141
  const { pipeline } = flags;
@@ -143,8 +143,11 @@ module.exports = class extends Model {
143
143
  if (!pipeline) return obj;
144
144
  // const filters = pipeline === true ? [] : Object.entries(pipeline).map(([k, v]) => (v === false ? k : null)).filter(Boolean);
145
145
 
146
+ // base is the base model
147
+ base = base || model;
148
+
146
149
  return map(obj, (parent) => {
147
- // "root" is the base of the object
150
+ // root is the base data object
148
151
  root = root || parent;
149
152
 
150
153
  // Lookup helper functions
@@ -158,7 +161,7 @@ module.exports = class extends Model {
158
161
 
159
162
  // Transform value
160
163
  const transformedValue = transformers.reduce((value, t) => {
161
- const v = t({ model, field, path, docPath, rootPath, parentPath, startValue, value, resolver, context });
164
+ const v = t({ base, model, field, path, docPath, rootPath, parentPath, startValue, value, resolver, context });
162
165
  return v === undefined ? value : v;
163
166
  }, startValue);
164
167
 
@@ -167,22 +170,25 @@ module.exports = class extends Model {
167
170
  if (!instructed && subShape && typeof transformedValue !== 'object') return prev;
168
171
 
169
172
  // Rename key & assign value
170
- prev[to] = (!subShape || transformedValue == null) ? transformedValue : this.shapeObject(subShape, transformedValue, query, root);
173
+ prev[to] = (!subShape || transformedValue == null) ? transformedValue : this.shapeObject(subShape, transformedValue, query, root, base);
171
174
 
172
175
  return prev;
173
176
  }, {});
174
177
  });
175
178
  }
176
179
 
177
- validateObject(shape, obj, query, root, silent = false) {
180
+ validateObject(shape, obj, query, root, base, silent = false) {
178
181
  const { model } = shape;
179
182
  const { context, resolver, doc = {}, flags = {} } = query.toObject();
180
183
  const { validate = true } = flags;
181
184
 
182
185
  if (!validate) return Promise.resolve();
183
186
 
187
+ // base is the base model
188
+ base = base || model;
189
+
184
190
  return mapPromise(obj, (parent) => {
185
- // "root" is the base of the object
191
+ // root is the base data object
186
192
  root = root || parent;
187
193
 
188
194
  // Lookup helper functions
@@ -195,10 +201,10 @@ module.exports = class extends Model {
195
201
 
196
202
  return Promise.all(validators.map((v) => {
197
203
  return new Promise((resolve, reject) => {
198
- return Promise.resolve(v({ model, field, path, docPath, rootPath, parentPath, startValue: value, value, resolver, context })).then(resolve).catch(reject);
204
+ return Promise.resolve(v({ base, model, field, path, docPath, rootPath, parentPath, startValue: value, value, resolver, context })).then(resolve).catch(reject);
199
205
  });
200
206
  })).then(() => {
201
- return subShape ? this.validateObject(subShape, value, query, root, true) : Promise.resolve();
207
+ return subShape ? this.validateObject(subShape, value, query, root, base, true) : Promise.resolve();
202
208
  });
203
209
  }));
204
210
  }).then(() => {
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -29,7 +29,7 @@ const makeMiddleware = () => {
29
29
  query.match($$where);
30
30
  }
31
31
 
32
- if (sort) {
32
+ if (sort && Object.keys(sort).length) {
33
33
  query.$sort(QueryService.resolveSortBy(query));
34
34
  }
35
35