@coderich/autograph 0.10.30 → 0.10.32
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coderich/autograph",
|
|
3
3
|
"author": "Richard Livolsi (coderich)",
|
|
4
|
-
"version": "0.10.
|
|
4
|
+
"version": "0.10.32",
|
|
5
5
|
"description": "AutoGraph",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"graphql",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"ratchet": "ratchet"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@coderich/util": "0.1.
|
|
33
|
+
"@coderich/util": "0.1.13",
|
|
34
34
|
"@hapi/boom": "^9.1.0",
|
|
35
35
|
"dataloader": "^2.0.0",
|
|
36
36
|
"deepmerge": "^4.2.2",
|
|
@@ -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) => {
|