@coderich/autograph 0.9.16 → 0.10.2
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 +24 -0
- package/index.js +2 -6
- package/package.json +10 -10
- package/src/.DS_Store +0 -0
- package/src/core/EventEmitter.js +2 -4
- package/src/core/Resolver.js +35 -58
- package/src/core/Schema.js +5 -38
- package/src/core/ServerResolver.js +7 -93
- package/src/data/DataLoader.js +68 -27
- package/src/data/DataService.js +59 -58
- package/src/data/Field.js +71 -96
- package/src/data/Model.js +95 -113
- package/src/data/Pipeline.js +174 -0
- package/src/data/Type.js +19 -60
- package/src/driver/MongoDriver.js +53 -28
- package/src/graphql/ast/Field.js +44 -26
- package/src/graphql/ast/Model.js +5 -16
- package/src/graphql/ast/Node.js +0 -32
- package/src/graphql/ast/Schema.js +109 -112
- package/src/graphql/extension/api.js +22 -35
- package/src/graphql/extension/framework.js +25 -33
- package/src/graphql/extension/type.js +2 -2
- package/src/query/Query.js +73 -15
- package/src/query/QueryBuilder.js +37 -28
- package/src/query/QueryBuilderTransaction.js +3 -3
- package/src/query/QueryResolver.js +93 -44
- package/src/query/QueryService.js +31 -34
- package/src/service/app.service.js +56 -35
- package/src/service/decorator.service.js +21 -288
- package/src/service/event.service.js +5 -79
- package/src/service/graphql.service.js +0 -9
- package/src/service/schema.service.js +5 -3
- package/src/core/Rule.js +0 -107
- package/src/core/SchemaDecorator.js +0 -46
- package/src/core/Transformer.js +0 -68
- package/src/data/Memoizer.js +0 -39
- package/src/data/ResultSet.js +0 -246
- package/src/graphql/ast/SchemaDecorator.js +0 -138
- package/src/graphql/directive/authz.directive.js +0 -84
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
const PicoMatch = require('picomatch');
|
|
2
|
-
const { SchemaDirectiveVisitor } = require('graphql-tools');
|
|
3
|
-
|
|
4
|
-
const getCrudOperation = (mutationName) => {
|
|
5
|
-
const crudMap = {
|
|
6
|
-
create: 'C',
|
|
7
|
-
add: 'C',
|
|
8
|
-
findOrCreate: 'C',
|
|
9
|
-
get: 'R',
|
|
10
|
-
find: 'R',
|
|
11
|
-
count: 'R',
|
|
12
|
-
update: 'U',
|
|
13
|
-
replace: 'U',
|
|
14
|
-
edit: 'U',
|
|
15
|
-
set: 'U',
|
|
16
|
-
move: 'U',
|
|
17
|
-
delete: 'D',
|
|
18
|
-
remove: 'D',
|
|
19
|
-
subscribe: 'S',
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
return Object.entries(crudMap).reduce((prev, [key, value]) => {
|
|
23
|
-
if (prev) return prev;
|
|
24
|
-
if (mutationName.indexOf(key) === 0) return value;
|
|
25
|
-
return null;
|
|
26
|
-
}, null);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const authorize = (context, model, fields, crud) => {
|
|
30
|
-
const { schema, permissions = [] } = context.autograph;
|
|
31
|
-
const namespace = schema.getModel(model).getNamespace();
|
|
32
|
-
const parts = namespace.split('/').reverse();
|
|
33
|
-
|
|
34
|
-
// const flags = fields.reduce((obj, field) => {
|
|
35
|
-
// const directTargets = parts.reduce((prev, part, i) => prev.concat(`${part}/${prev[i]}`), [`${model}/${field}/${crud}`]);
|
|
36
|
-
// let result = directTargets.some(target => PicoMatch.isMatch(target, permissions, { nocase: true }));
|
|
37
|
-
|
|
38
|
-
// if (!result) {
|
|
39
|
-
// const authorTargets = parts.reduce((prev, part, i) => prev.concat(`${part}/${prev[i]}`), [`${model}/${field}/${crud}`]);
|
|
40
|
-
// result = authorTargets.some(target => PicoMatch.isMatch(target, permissions, { nocase: true })) ? 1 : false;
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
// return Object.assign(obj, { [field]: result });
|
|
44
|
-
// }, {});
|
|
45
|
-
|
|
46
|
-
// console.log(flags);
|
|
47
|
-
// console.log('------');
|
|
48
|
-
|
|
49
|
-
const authorized = fields.every((field) => {
|
|
50
|
-
const targets = parts.reduce((prev, part, i) => prev.concat(`${part}/${prev[i]}`), [`${model}/${field}/${crud}`]);
|
|
51
|
-
return targets.some(target => PicoMatch.isMatch(target, permissions, { nocase: true }));
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
if (!authorized) throw new Error('Not Authorized');
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
module.exports = class extends SchemaDirectiveVisitor {
|
|
58
|
-
visitObject(type) { // eslint-disable-line
|
|
59
|
-
const fields = type.getFields();
|
|
60
|
-
|
|
61
|
-
Object.keys(fields).forEach((fieldName) => {
|
|
62
|
-
const field = fields[fieldName];
|
|
63
|
-
const { resolve = root => root[fieldName] } = field;
|
|
64
|
-
const { model = `${type}` } = this.args;
|
|
65
|
-
|
|
66
|
-
field.resolve = async function resolver(root, args, context, info) {
|
|
67
|
-
authorize(context, model, [fieldName], 'R');
|
|
68
|
-
return resolve.call(this, root, args, context, info);
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
visitFieldDefinition(field, details) { // eslint-disable-line
|
|
74
|
-
const { name, type, resolve = root => root[name] } = field;
|
|
75
|
-
const dataType = type.toString().replace(/[[\]!]/g, '');
|
|
76
|
-
const crudOperation = getCrudOperation(name);
|
|
77
|
-
const { model = dataType } = this.args;
|
|
78
|
-
|
|
79
|
-
field.resolve = async function resolver(root, args, context, info) {
|
|
80
|
-
authorize(context, model, Object.keys(args.input || { id: 1 }), crudOperation);
|
|
81
|
-
return resolve.call(this, root, args, context, info);
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
};
|