@coderich/autograph 0.13.101 → 0.13.103
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/Resolver.js +13 -7
- package/src/data/Transaction.js +1 -1
- package/src/query/Query.js +13 -3
- package/src/query/QueryResolver.js +1 -10
package/package.json
CHANGED
package/src/data/Resolver.js
CHANGED
|
@@ -47,6 +47,7 @@ module.exports = class Resolver {
|
|
|
47
47
|
clone() {
|
|
48
48
|
return new Resolver({
|
|
49
49
|
schema: this.#schema,
|
|
50
|
+
xschema: this.#xschema,
|
|
50
51
|
context: this.#context,
|
|
51
52
|
});
|
|
52
53
|
}
|
|
@@ -141,11 +142,10 @@ module.exports = class Resolver {
|
|
|
141
142
|
* @returns {*} - The promise resolution
|
|
142
143
|
*/
|
|
143
144
|
run(promise) {
|
|
144
|
-
return
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
145
|
+
return this.commit().then(() => promise);
|
|
146
|
+
// return this.commit().then(() => promise).catch((e) => {
|
|
147
|
+
// return this.rollback().then(() => Promise.reject(e));
|
|
148
|
+
// });
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
/**
|
|
@@ -231,6 +231,8 @@ module.exports = class Resolver {
|
|
|
231
231
|
return thunk(tquery).then((result) => {
|
|
232
232
|
if (flags?.required && (result == null || result?.length === 0)) throw Boom.notFound(`${model} Not Found`);
|
|
233
233
|
return result;
|
|
234
|
+
}).finally(() => {
|
|
235
|
+
query.resolve();
|
|
234
236
|
});
|
|
235
237
|
});
|
|
236
238
|
}
|
|
@@ -306,7 +308,7 @@ module.exports = class Resolver {
|
|
|
306
308
|
const type = query.isMutation ? 'Mutation' : 'Query';
|
|
307
309
|
const event = this.#createEvent(query);
|
|
308
310
|
|
|
309
|
-
|
|
311
|
+
const promise = Emitter.emit(`pre${type}`, event).then(async (resultEarly) => {
|
|
310
312
|
if (resultEarly !== undefined) return resultEarly; // Nothing to validate/transform
|
|
311
313
|
// if (query.crud === 'update' && Util.isEqual({ added: {}, updated: {}, deleted: {} }, Util.changeset(query.doc, query.input))) return query.doc;
|
|
312
314
|
|
|
@@ -317,7 +319,9 @@ module.exports = class Resolver {
|
|
|
317
319
|
}
|
|
318
320
|
|
|
319
321
|
return thunk(tquery);
|
|
320
|
-
})
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
promise.then((result) => {
|
|
321
325
|
event.result = result; // backwards compat
|
|
322
326
|
query.result = result;
|
|
323
327
|
return Emitter.emit(`post${type}`, event);
|
|
@@ -326,6 +330,8 @@ module.exports = class Resolver {
|
|
|
326
330
|
// const { data = {} } = e;
|
|
327
331
|
// throw Boom.boomify(e, { data: { ...event, ...data } });
|
|
328
332
|
});
|
|
333
|
+
|
|
334
|
+
return promise;
|
|
329
335
|
}
|
|
330
336
|
|
|
331
337
|
#createEvent(query) {
|
package/src/data/Transaction.js
CHANGED
|
@@ -45,7 +45,7 @@ module.exports = class Transaction {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
#close(op) {
|
|
48
|
-
return Promise.all(this.#queries.map(q => q.promise())).
|
|
48
|
+
return Promise.all(this.#queries.map(q => q.promise())).finally(() => {
|
|
49
49
|
return Promise.all(Array.from(this.#sourceMap.entries()).map(([client, promise]) => {
|
|
50
50
|
return promise.then(transaction => transaction[op]());
|
|
51
51
|
}));
|
package/src/query/Query.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const Util = require('@coderich/util');
|
|
2
|
-
const { isGlob, globToRegex, mergeDeep, JSONParse } = require('../service/AppService');
|
|
2
|
+
const { isGlob, globToRegex, mergeDeep, JSONParse, withResolvers } = require('../service/AppService');
|
|
3
3
|
|
|
4
4
|
module.exports = class Query {
|
|
5
5
|
#config;
|
|
@@ -8,20 +8,30 @@ module.exports = class Query {
|
|
|
8
8
|
#schema;
|
|
9
9
|
#model;
|
|
10
10
|
#query;
|
|
11
|
+
#resolution;
|
|
11
12
|
|
|
12
13
|
constructor(config) {
|
|
13
|
-
const { schema, context, resolver, query } = config;
|
|
14
|
+
const { schema, context, resolver, query, resolution = withResolvers() } = config;
|
|
14
15
|
this.#config = config;
|
|
15
16
|
this.#resolver = resolver;
|
|
16
17
|
this.#context = context;
|
|
17
18
|
this.#schema = schema;
|
|
18
19
|
this.#model = schema.models[query.model];
|
|
19
20
|
this.#query = query;
|
|
21
|
+
this.#resolution = resolution;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
promise() {
|
|
25
|
+
return this.#resolution.promise;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
resolve() {
|
|
29
|
+
this.#resolution.resolve();
|
|
20
30
|
}
|
|
21
31
|
|
|
22
32
|
clone(query) {
|
|
23
33
|
query = { ...this.#query, ...query }; // NO deepMerge here; must replace fields entirely
|
|
24
|
-
return new Query({ ...this.#config, query });
|
|
34
|
+
return new Query({ ...this.#config, query, resolution: this.#resolution });
|
|
25
35
|
}
|
|
26
36
|
|
|
27
37
|
toObject() {
|
|
@@ -26,17 +26,8 @@ module.exports = class QueryResolver extends QueryBuilder {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
terminate() {
|
|
29
|
-
return this.#terminate().then((result) => {
|
|
30
|
-
this.#resolution.resolve(result);
|
|
31
|
-
return result;
|
|
32
|
-
}).catch((e) => {
|
|
33
|
-
this.#resolution.reject(e);
|
|
34
|
-
return Promise.reject(e);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
#terminate() {
|
|
39
29
|
const query = super.terminate();
|
|
30
|
+
query.promise().then(this.#resolution.resolve).catch(this.#resolution.reject);
|
|
40
31
|
const { op, args: { input } } = query.toObject();
|
|
41
32
|
|
|
42
33
|
// Resolve
|