@coderich/autograph 0.10.4 → 0.11.0
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 +1 -1
- package/src/data/DataService.js +1 -1
- package/src/data/Model.js +4 -2
- package/src/graphql/extension/framework.js +5 -4
- package/src/query/QueryBuilder.js +1 -1
- package/src/query/QueryResolver.js +3 -1
- package/src/service/app.service.js +21 -7
- package/CHANGELOG.md +0 -41
- package/src/.DS_Store +0 -0
- package/src/core/.DS_Store +0 -0
- package/src/data/.DS_Store +0 -0
- package/src/driver/.DS_Store +0 -0
- package/src/graphql/.DS_Store +0 -0
- package/src/graphql/ast/.DS_Store +0 -0
- package/src/graphql/extension/.DS_Store +0 -0
- package/src/query/.DS_Store +0 -0
- package/src/service/.DS_Store +0 -0
package/package.json
CHANGED
package/src/data/DataService.js
CHANGED
|
@@ -11,7 +11,7 @@ exports.finalizeResults = (rs, query) => {
|
|
|
11
11
|
$remove: { value: (...args) => resolver.match(model).id(doc.id).remove(...args) },
|
|
12
12
|
$delete: { value: (...args) => resolver.match(model).id(doc.id).delete(...args) },
|
|
13
13
|
$lookup: { value: (fieldName, args) => model.getFieldByName(fieldName).resolve(resolver, doc, args) },
|
|
14
|
-
// $resolve: { value: (fieldName, args) => model.getFieldByName(fieldName).resolve(resolver, doc, args
|
|
14
|
+
// $resolve: { value: (fieldName, args) => model.getFieldByName(fieldName).resolve(resolver, doc, args) },
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
17
|
};
|
package/src/data/Model.js
CHANGED
|
@@ -65,7 +65,9 @@ module.exports = class extends Model {
|
|
|
65
65
|
}).then(rs => finalizeResults(rs, query));
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
getShape(crud = 'read', target = 'doc', paths = []) {
|
|
68
|
+
getShape(crud = 'read', target = 'doc', paths = [], depth = 0) {
|
|
69
|
+
if (depth++ > 10) return {}; // Prevent infinite circular references
|
|
70
|
+
|
|
69
71
|
// Cache check
|
|
70
72
|
const cacheKey = `${crud}:${target}`;
|
|
71
73
|
if (this.shapesCache.has(cacheKey)) return this.shapesCache.get(cacheKey);
|
|
@@ -113,7 +115,7 @@ module.exports = class extends Model {
|
|
|
113
115
|
const actualTo = target === 'input' || target === 'splice' ? from : to;
|
|
114
116
|
const path = paths.concat(actualTo);
|
|
115
117
|
const subCrud = crud === 'update' && isArray ? 'create' : crud; // Due to limitation to update embedded array
|
|
116
|
-
const subShape = isEmbedded ? modelRef.getShape(subCrud, target, path) : null;
|
|
118
|
+
const subShape = isEmbedded ? modelRef.getShape(subCrud, target, path, depth) : null;
|
|
117
119
|
const transformers = structureKeys.reduce((prev, struct) => {
|
|
118
120
|
const structs = structures[struct];
|
|
119
121
|
if (struct === 'instructs' && structs.length) instructed = true;
|
|
@@ -8,6 +8,7 @@ module.exports = (schema) => {
|
|
|
8
8
|
scalar AutoGraphMixed
|
|
9
9
|
scalar AutoGraphDriver
|
|
10
10
|
scalar AutoGraphDateTime @field(transform: toDate)
|
|
11
|
+
enum AutoGraphSchemaEnum { ${schema.getModels().map(m => m.getName()).join(' ')} }
|
|
11
12
|
enum AutoGraphPipelineEnum { ${Object.keys(Pipeline).join(' ')} }
|
|
12
13
|
enum AutoGraphAuthzEnum { private protected public }
|
|
13
14
|
enum AutoGraphOnDeleteEnum { cascade nullify restrict defer }
|
|
@@ -16,6 +17,7 @@ module.exports = (schema) => {
|
|
|
16
17
|
directive @model(
|
|
17
18
|
id: String # Specify db key (default "id")
|
|
18
19
|
key: String # Specify db table/collection name
|
|
20
|
+
driver: AutoGraphDriver # External data driver
|
|
19
21
|
createdAt: String # Specify db key (default "createdAt")
|
|
20
22
|
updatedAt: String # Specify db key (default "updatedAt")
|
|
21
23
|
meta: AutoGraphMixed # Custom input "meta" field for mutations
|
|
@@ -24,7 +26,6 @@ module.exports = (schema) => {
|
|
|
24
26
|
gqlScope: AutoGraphMixed # Dictate how GraphQL API behaves
|
|
25
27
|
dalScope: AutoGraphMixed # Dictate how the DAL behaves
|
|
26
28
|
fieldScope: AutoGraphMixed # Dictate how a FIELD may use me
|
|
27
|
-
driver: AutoGraphDriver # External data driver
|
|
28
29
|
authz: AutoGraphAuthzEnum # Access level used for authorization (default: private)
|
|
29
30
|
namespace: String # Logical grouping of models that can be globbed (useful for authz)
|
|
30
31
|
) on OBJECT | INTERFACE
|
|
@@ -45,12 +46,12 @@ module.exports = (schema) => {
|
|
|
45
46
|
|
|
46
47
|
# Pipeline Structure
|
|
47
48
|
validate: [AutoGraphPipelineEnum!]
|
|
48
|
-
|
|
49
|
+
construct: [AutoGraphPipelineEnum!]
|
|
49
50
|
restruct: [AutoGraphPipelineEnum!]
|
|
50
51
|
destruct: [AutoGraphPipelineEnum!]
|
|
51
|
-
|
|
52
|
-
transform: [AutoGraphPipelineEnum!]
|
|
52
|
+
instruct: [AutoGraphPipelineEnum!]
|
|
53
53
|
normalize: [AutoGraphPipelineEnum!]
|
|
54
|
+
transform: [AutoGraphPipelineEnum!]
|
|
54
55
|
serialize: [AutoGraphPipelineEnum!]
|
|
55
56
|
deserialize: [AutoGraphPipelineEnum!]
|
|
56
57
|
) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | SCALAR
|
|
@@ -28,7 +28,7 @@ module.exports = class QueryBuilder {
|
|
|
28
28
|
this.after = (cursor) => { this.query.after(cursor); return this; };
|
|
29
29
|
this.meta = (meta) => { this.query.meta(meta); return this; };
|
|
30
30
|
this.flags = (flags) => { this.query.flags(flags); return this; };
|
|
31
|
-
this.merge = (merge) => { this.query.merge(merge); return this; };
|
|
31
|
+
this.merge = (merge) => { this.query.merge(unravelObject(merge)); return this; };
|
|
32
32
|
this.batch = (batch) => { this.query.batch(batch); return this; };
|
|
33
33
|
this.transaction = (txn) => { this.query.transaction(txn); return this; };
|
|
34
34
|
|
|
@@ -3,7 +3,7 @@ const Boom = require('../core/Boom');
|
|
|
3
3
|
const QueryService = require('./QueryService');
|
|
4
4
|
const DataService = require('../data/DataService');
|
|
5
5
|
const { createSystemEvent } = require('../service/event.service');
|
|
6
|
-
const { mergeDeep, getGQLReturnType } = require('../service/app.service');
|
|
6
|
+
const { objectIntersectionEqual, mergeDeep, getGQLReturnType } = require('../service/app.service');
|
|
7
7
|
|
|
8
8
|
module.exports = class QueryResolver {
|
|
9
9
|
constructor(query) {
|
|
@@ -81,6 +81,8 @@ module.exports = class QueryResolver {
|
|
|
81
81
|
const docShape = model.getShape('update', 'doc');
|
|
82
82
|
|
|
83
83
|
return this.resolver.match(model).match(match).one({ required: true }).then((doc) => {
|
|
84
|
+
if (objectIntersectionEqual(doc, input)) return doc; // If no changes do not perform query
|
|
85
|
+
|
|
84
86
|
const merged = mergeDeep(doc, input);
|
|
85
87
|
|
|
86
88
|
return createSystemEvent('Mutation', { query: query.doc(doc).merged(merged) }, async () => {
|
|
@@ -130,6 +130,9 @@ exports.castCmp = (type, value) => {
|
|
|
130
130
|
}
|
|
131
131
|
};
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Returns true if b is a subset of a
|
|
135
|
+
*/
|
|
133
136
|
exports.objectContaining = (a, b) => {
|
|
134
137
|
if (a === b) return true;
|
|
135
138
|
|
|
@@ -137,7 +140,7 @@ exports.objectContaining = (a, b) => {
|
|
|
137
140
|
return exports.keyPathLeafs(b).every((leaf) => {
|
|
138
141
|
const $a = _.get(a, leaf, { a: 'a' });
|
|
139
142
|
const $b = _.get(b, leaf, { b: 'b' });
|
|
140
|
-
if (Array.isArray($b)) return $b.
|
|
143
|
+
if (Array.isArray($b)) return $b.every(bb => exports.ensureArray($a).some(aa => exports.objectContaining(aa, bb)));
|
|
141
144
|
if (exports.isScalarValue($a) && exports.isScalarValue($b)) return PicoMatch.isMatch(`${$a}`, `${$b}`, { nocase: true });
|
|
142
145
|
return exports.hashObject($a) === exports.hashObject($b);
|
|
143
146
|
});
|
|
@@ -146,6 +149,23 @@ exports.objectContaining = (a, b) => {
|
|
|
146
149
|
return exports.hashObject(a) === exports.hashObject(b);
|
|
147
150
|
};
|
|
148
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Returns true if (b intersection a) are equal
|
|
154
|
+
*/
|
|
155
|
+
exports.objectIntersectionEqual = (a, b) => {
|
|
156
|
+
if (a === b) return true;
|
|
157
|
+
|
|
158
|
+
if (exports.isPlainObject(b)) {
|
|
159
|
+
return exports.keyPathLeafs(b).every((leaf) => {
|
|
160
|
+
const $a = _.get(a, leaf, { a: 'a' });
|
|
161
|
+
const $b = _.get(b, leaf, { b: 'b' });
|
|
162
|
+
return exports.hashObject($a) === exports.hashObject($b);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return exports.hashObject(a) === exports.hashObject(b);
|
|
167
|
+
};
|
|
168
|
+
|
|
149
169
|
/**
|
|
150
170
|
* Transform an object with dot.notation keys into an expanded object.
|
|
151
171
|
* eg. { 'user.name': 'richard' } => { user: { name: 'richard' } }
|
|
@@ -180,12 +200,6 @@ exports.keyPaths = (obj = {}, keys = [], path) => {
|
|
|
180
200
|
return Object.entries(obj).reduce((prev, [key, value]) => {
|
|
181
201
|
const keyPath = path ? `${path}.${key}` : key;
|
|
182
202
|
if (exports.isPlainObject(value) && Object.keys(value).length) return exports.keyPaths(value, prev, keyPath);
|
|
183
|
-
|
|
184
|
-
// if (Array.isArray(value)) {
|
|
185
|
-
// const arr = value.filter(v => exports.isPlainObject(v));
|
|
186
|
-
// if (arr.length) return _.flatten(arr.map(val => exports.keyPaths(val, prev, keyPath)));
|
|
187
|
-
// }
|
|
188
|
-
|
|
189
203
|
return prev.concat(keyPath);
|
|
190
204
|
}, keys);
|
|
191
205
|
};
|
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
|
package/src/core/.DS_Store
DELETED
|
Binary file
|
package/src/data/.DS_Store
DELETED
|
Binary file
|
package/src/driver/.DS_Store
DELETED
|
Binary file
|
package/src/graphql/.DS_Store
DELETED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/query/.DS_Store
DELETED
|
Binary file
|
package/src/service/.DS_Store
DELETED
|
Binary file
|