@coderich/autograph 0.11.1 → 0.11.3
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 +5 -5
- package/src/data/Model.js +2 -2
- package/src/driver/MongoDriver.js +1 -1
- package/src/graphql/ast/Schema.js +8 -12
- package/src/graphql/extension/api.js +1 -1
- package/src/graphql/extension/framework.js +10 -0
- package/src/query/QueryService.js +7 -3
- package/src/service/app.service.js +1 -1
- package/src/service/schema.service.js +0 -47
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coderich/autograph",
|
|
3
3
|
"author": "Richard Livolsi (coderich)",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.3",
|
|
5
5
|
"description": "AutoGraph",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"graphql",
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
"ratchet": "ratchet"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@coderich/util": "
|
|
33
|
+
"@coderich/util": "1.0.5",
|
|
34
34
|
"@hapi/boom": "^9.1.0",
|
|
35
35
|
"dataloader": "^2.0.0",
|
|
36
36
|
"deepmerge": "^4.2.2",
|
|
37
37
|
"fill-range": "^7.0.1",
|
|
38
|
-
"glob": "^
|
|
38
|
+
"glob": "^9.3.5",
|
|
39
39
|
"graphql-fields": "^2.0.3",
|
|
40
40
|
"lodash": "^4.17.21",
|
|
41
|
-
"mongodb": "4.
|
|
41
|
+
"mongodb": "4.17.0",
|
|
42
42
|
"object-hash": "^3.0.0",
|
|
43
43
|
"picomatch": "^2.1.1"
|
|
44
44
|
},
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@coderich/ratchet": "^1.5.8",
|
|
47
47
|
"@graphql-tools/schema": "^9.0.1",
|
|
48
48
|
"graphql": "^15.5.0",
|
|
49
|
-
"mongodb-memory-server": "
|
|
49
|
+
"mongodb-memory-server": "8.13.0",
|
|
50
50
|
"validator": "^13.7.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
package/src/data/Model.js
CHANGED
|
@@ -82,9 +82,9 @@ module.exports = class extends Model {
|
|
|
82
82
|
|
|
83
83
|
// Define target mapping
|
|
84
84
|
const targetMap = {
|
|
85
|
-
doc: [
|
|
86
|
-
// doc: ['defaultValue', 'castValue', 'ensureArrayValue', 'normalizers', 'instructs', ...crudKeys, `$${serdes}rs`, `${serdes}rs`, 'transforms'],
|
|
85
|
+
doc: ['defaultValue', 'castValue', 'ensureArrayValue', 'normalizers', 'instructs', ...crudKeys, `$${serdes}rs`, `${serdes}rs`, 'transforms'],
|
|
87
86
|
input: ['defaultValue', 'castValue', 'ensureArrayValue', 'normalizers', 'instructs', ...crudKeys, `$${serdes}rs`, `${serdes}rs`, 'transforms'],
|
|
87
|
+
// input: ['defaultValue', 'castValue', 'ensureArrayValue'],
|
|
88
88
|
where: ['castValue', 'instructs', `$${serdes}rs`],
|
|
89
89
|
};
|
|
90
90
|
|
|
@@ -29,7 +29,7 @@ module.exports = class MongoDriver {
|
|
|
29
29
|
query(collection, method, ...args) {
|
|
30
30
|
if (get(args[args.length - 1], 'debug') === true) console.log(collection, method, Util.inspect(args, { depth: null, showHidden: false, colors: true }));
|
|
31
31
|
if (method === 'aggregate') args.splice(2);
|
|
32
|
-
return this.raw(collection)[method](
|
|
32
|
+
return this.raw(collection)[method](args[0], args[1]);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
resolve(query) {
|
|
@@ -70,18 +70,14 @@ module.exports = class Schema extends TypeDefApi {
|
|
|
70
70
|
* Asynchronously load files from a given glob pattern and merge each schema
|
|
71
71
|
*/
|
|
72
72
|
mergeSchemaFromFiles(globPattern, options) {
|
|
73
|
-
return
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}).then(schema => this.mergeSchema(schema, options));
|
|
82
|
-
})).then(() => resolve(this)).catch(e => reject(e));
|
|
83
|
-
});
|
|
84
|
-
});
|
|
73
|
+
return Glob(globPattern, options).then((files) => {
|
|
74
|
+
return Promise.all(files.map((file) => {
|
|
75
|
+
return new Promise((res) => {
|
|
76
|
+
if (file.endsWith('.js')) res(require(file)); // eslint-disable-line global-require,import/no-dynamic-require
|
|
77
|
+
else res(FS.readFileSync(file, 'utf8'));
|
|
78
|
+
}).then(schema => this.mergeSchema(schema, options));
|
|
79
|
+
}));
|
|
80
|
+
}).then(() => this);
|
|
85
81
|
}
|
|
86
82
|
|
|
87
83
|
/**
|
|
@@ -9,7 +9,7 @@ const interfaceKinds = [Kind.INTERFACE_TYPE_DEFINITION, Kind.INTERFACE_TYPE_EXTE
|
|
|
9
9
|
|
|
10
10
|
const getGQLWhereFields = (model) => {
|
|
11
11
|
return model.getFields().filter((field) => {
|
|
12
|
-
if (!field.hasGQLScope('r')) return false;
|
|
12
|
+
if (!field.isPersistable() || !field.hasGQLScope('r')) return false;
|
|
13
13
|
const modelRef = field.getModelRef();
|
|
14
14
|
if (modelRef && !modelRef.isEmbedded() && !modelRef.isEntity()) return false;
|
|
15
15
|
return true;
|
|
@@ -27,6 +27,12 @@ module.exports = (schema) => {
|
|
|
27
27
|
fieldScope: AutoGraphMixed # Dictate how a FIELD may use me
|
|
28
28
|
authz: AutoGraphAuthzEnum # Access level used for authorization (default: private)
|
|
29
29
|
namespace: String # Logical grouping of models that can be globbed (useful for authz)
|
|
30
|
+
|
|
31
|
+
# FOR TRANSITION TO NEW VERSION
|
|
32
|
+
crud: AutoGraphMixed # CRUD API
|
|
33
|
+
scope: AutoGraphMixed #
|
|
34
|
+
source: AutoGraphMixed # Data source (default: "default")
|
|
35
|
+
decorate: AutoGraphMixed # Decorator (default: "default")
|
|
30
36
|
) on OBJECT | INTERFACE
|
|
31
37
|
|
|
32
38
|
directive @field(
|
|
@@ -53,6 +59,10 @@ module.exports = (schema) => {
|
|
|
53
59
|
transform: [AutoGraphPipelineEnum!]
|
|
54
60
|
serialize: [AutoGraphPipelineEnum!]
|
|
55
61
|
deserialize: [AutoGraphPipelineEnum!]
|
|
62
|
+
|
|
63
|
+
# FOR TRANSITION TO NEW VERSION
|
|
64
|
+
crud: AutoGraphMixed # CRUD API
|
|
65
|
+
finalize: [AutoGraphPipelineEnum!]
|
|
56
66
|
) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | SCALAR
|
|
57
67
|
|
|
58
68
|
directive @link(
|
|
@@ -44,6 +44,7 @@ exports.resolveSortBy = (query) => {
|
|
|
44
44
|
const { model, sort = {} } = query.toObject();
|
|
45
45
|
const shape = model.getShape('create', 'sortBy');
|
|
46
46
|
const $sort = model.shapeObject(shape, sort, query);
|
|
47
|
+
const deletions = [];
|
|
47
48
|
|
|
48
49
|
// Because normalize casts the value (sometimes to an array) need special handling
|
|
49
50
|
keyPaths($sort).forEach((path) => {
|
|
@@ -55,14 +56,17 @@ exports.resolveSortBy = (query) => {
|
|
|
55
56
|
|
|
56
57
|
// If you need to sort by something that's in another FK document
|
|
57
58
|
if (join) {
|
|
58
|
-
|
|
59
|
+
deletions.push(attr); // Keep track of what to delete
|
|
59
60
|
query.joins(Object.assign(join, { as: `_.${field}`, left: true }));
|
|
60
61
|
path = `_.${path}`;
|
|
61
|
-
} else {
|
|
62
|
-
set($sort, path, val.toLowerCase() === 'asc' ? 1 : -1);
|
|
63
62
|
}
|
|
63
|
+
|
|
64
|
+
set($sort, path, val.toLowerCase() === 'asc' ? 1 : -1);
|
|
64
65
|
});
|
|
65
66
|
|
|
67
|
+
// Delete the sorts on the "base" collection because you're sorting by _.path.to.it (above)
|
|
68
|
+
deletions.forEach(attr => delete $sort[attr]);
|
|
69
|
+
|
|
66
70
|
return $sort;
|
|
67
71
|
};
|
|
68
72
|
|
|
@@ -40,7 +40,7 @@ exports.isIdValue = value => exports.isScalarValue(value) || value instanceof Ob
|
|
|
40
40
|
exports.mergeDeep = (...args) => DeepMerge.all(args, { isMergeableObject: obj => (exports.isPlainObject(obj) || Array.isArray(obj)), arrayMerge: smartMerge });
|
|
41
41
|
exports.uniq = arr => [...new Set(arr.map(a => `${a}`))];
|
|
42
42
|
exports.timeout = ms => new Promise(res => setTimeout(res, ms));
|
|
43
|
-
exports.hashObject = obj => ObjectHash(obj, { respectType: false, respectFunctionNames: false, respectFunctionProperties: false, unorderedArrays: true, ignoreUnknown: true, replacer: r => (r
|
|
43
|
+
exports.hashObject = obj => ObjectHash(obj, { respectType: false, respectFunctionNames: false, respectFunctionProperties: false, unorderedArrays: true, ignoreUnknown: true, replacer: r => (ObjectId.isValid(r) ? `${r}` : r) });
|
|
44
44
|
exports.globToRegex = (glob, options = {}) => PicoMatch.makeRe(glob, { ...options, expandRange: (a, b) => `(${FillRange(a, b, { toRegex: true })})` });
|
|
45
45
|
exports.globToRegexp = (glob, options = {}) => PicoMatch.toRegex(exports.globToRegex(glob, options));
|
|
46
46
|
exports.toGUID = (model, id) => Buffer.from(`${model},${`${id}`}`).toString('base64');
|
|
@@ -3,53 +3,6 @@
|
|
|
3
3
|
// https://graphql.org/graphql-js/utilities/
|
|
4
4
|
|
|
5
5
|
const { uniqWith } = require('lodash');
|
|
6
|
-
const { GraphQLScalarType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType } = require('graphql');
|
|
7
|
-
|
|
8
|
-
exports.getSchemaData = (schema) => {
|
|
9
|
-
const operations = ['Query', 'Mutation', 'Subscription'];
|
|
10
|
-
|
|
11
|
-
return Object.entries(schema.getTypeMap()).reduce((prev, [key, value]) => {
|
|
12
|
-
let type;
|
|
13
|
-
|
|
14
|
-
if (value instanceof GraphQLScalarType) {
|
|
15
|
-
type = 'scalars';
|
|
16
|
-
} else if (value instanceof GraphQLEnumType) {
|
|
17
|
-
type = 'enums';
|
|
18
|
-
} else if (value instanceof GraphQLUnionType) {
|
|
19
|
-
type = 'unions';
|
|
20
|
-
} else if (value instanceof GraphQLInterfaceType) {
|
|
21
|
-
type = 'interfaces';
|
|
22
|
-
} else if (value instanceof GraphQLInputObjectType) {
|
|
23
|
-
type = 'inputs';
|
|
24
|
-
} else if (value instanceof GraphQLObjectType) {
|
|
25
|
-
if (operations.includes(key)) {
|
|
26
|
-
type = 'operations';
|
|
27
|
-
} else {
|
|
28
|
-
type = 'models';
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (type) {
|
|
33
|
-
if (!key.startsWith('__')) {
|
|
34
|
-
prev[type][key] = value;
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
console.log(`Unknown schema type { ${key}: ${value} }`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return prev;
|
|
41
|
-
}, {
|
|
42
|
-
enums: {},
|
|
43
|
-
models: {},
|
|
44
|
-
inputs: {},
|
|
45
|
-
unions: {},
|
|
46
|
-
scalars: {},
|
|
47
|
-
operations: {},
|
|
48
|
-
directives: {},
|
|
49
|
-
interfaces: {},
|
|
50
|
-
enumerations: {},
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
6
|
|
|
54
7
|
exports.identifyOnDeletes = (models, parentModel) => {
|
|
55
8
|
return models.reduce((prev, model) => {
|
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
|