@coderich/autograph 0.13.9 → 0.13.11
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 +3 -3
- package/src/data/Resolver.js +4 -1
- package/src/query/Query.js +1 -1
- package/src/schema/Schema.js +23 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coderich/autograph",
|
|
3
3
|
"main": "index.js",
|
|
4
|
-
"version": "0.13.
|
|
4
|
+
"version": "0.13.11",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dev": "coderich-dev"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@coderich/util": "0.1.
|
|
18
|
+
"@coderich/util": "0.1.11",
|
|
19
19
|
"@graphql-tools/merge": "9.0.0",
|
|
20
20
|
"@graphql-tools/resolvers-composition": "7.0.0",
|
|
21
21
|
"@hapi/boom": "10.0.1",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@coderich/dev": "0.1.0",
|
|
37
37
|
"@graphql-tools/schema": "10.0.0",
|
|
38
38
|
"graphql": "16.6.0",
|
|
39
|
-
"mongodb": "5.
|
|
39
|
+
"mongodb": "5.9.2",
|
|
40
40
|
"mongodb-memory-server": "8.13.0",
|
|
41
41
|
"validator": "13.9.0"
|
|
42
42
|
},
|
package/src/data/Resolver.js
CHANGED
|
@@ -76,12 +76,15 @@ module.exports = class Resolver {
|
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Execute a user-defined loader (curry in context)
|
|
81
|
+
*/
|
|
79
82
|
loader(name) {
|
|
80
83
|
const context = this.#context;
|
|
81
84
|
|
|
82
85
|
return new Proxy(loaders[name], {
|
|
83
86
|
get(loader, fn, proxy) {
|
|
84
|
-
if (fn
|
|
87
|
+
if (fn.startsWith('load')) return args => loader[fn](args, context);
|
|
85
88
|
return Reflect.get(loader, fn, proxy);
|
|
86
89
|
},
|
|
87
90
|
});
|
package/src/query/Query.js
CHANGED
|
@@ -64,7 +64,7 @@ module.exports = class Query {
|
|
|
64
64
|
transform() {
|
|
65
65
|
return Promise.all([
|
|
66
66
|
this.pipeline('input', this.#query.input),
|
|
67
|
-
this.#query.isNative ? this.#query.where : this.pipeline('where', this.#query.where),
|
|
67
|
+
this.#query.isNative ? this.#query.where : this.pipeline('where', this.#query.where ?? {}),
|
|
68
68
|
this.pipeline('sort', this.#query.sort),
|
|
69
69
|
]).then(([input, where, sort]) => this.clone({ input, where, sort }));
|
|
70
70
|
}
|
package/src/schema/Schema.js
CHANGED
|
@@ -29,8 +29,18 @@ module.exports = class Schema {
|
|
|
29
29
|
this.#config.directives.field ??= 'field';
|
|
30
30
|
this.#config.directives.link ??= 'link';
|
|
31
31
|
this.#config.directives.index ??= 'index';
|
|
32
|
-
|
|
32
|
+
this.#typeDefs = Schema.#framework(this.#config.directives);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* ****** DEPRECATE! ****** */
|
|
36
|
+
getModels() {
|
|
37
|
+
return this.#schema.models;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getModel(name) {
|
|
41
|
+
return this.#schema.models[`${name}`];
|
|
33
42
|
}
|
|
43
|
+
/* ***************** */
|
|
34
44
|
|
|
35
45
|
/**
|
|
36
46
|
* Decorate each marked @model with config-driven field decorators
|
|
@@ -106,6 +116,9 @@ module.exports = class Schema {
|
|
|
106
116
|
let model, field, isField, isList;
|
|
107
117
|
const thunks = [];
|
|
108
118
|
|
|
119
|
+
// Deprecate
|
|
120
|
+
this.#schema.getModel = name => this.#schema.models[`${name}`];
|
|
121
|
+
|
|
109
122
|
// Parse AST
|
|
110
123
|
visit(this.#typeDefs, {
|
|
111
124
|
enter: (node) => {
|
|
@@ -119,9 +132,9 @@ module.exports = class Schema {
|
|
|
119
132
|
name,
|
|
120
133
|
key: name,
|
|
121
134
|
fields: {},
|
|
122
|
-
idField: 'id',
|
|
123
135
|
crud: 'crud',
|
|
124
136
|
scope: 'crud',
|
|
137
|
+
idField: 'id',
|
|
125
138
|
isPersistable: true,
|
|
126
139
|
source: this.#config.dataSources?.default,
|
|
127
140
|
loader: this.#config.dataLoaders?.default,
|
|
@@ -209,6 +222,14 @@ module.exports = class Schema {
|
|
|
209
222
|
target[key] = value;
|
|
210
223
|
break;
|
|
211
224
|
}
|
|
225
|
+
|
|
226
|
+
// Backwards compat (deprecated)
|
|
227
|
+
case 'model-gqlScope': { model.crud = value; break; }
|
|
228
|
+
case 'model-fieldScope': { model.scope = value; break; }
|
|
229
|
+
case 'field-gqlScope': { field.crud = value; break; }
|
|
230
|
+
case 'field-fieldScope': { field.scope = value; break; }
|
|
231
|
+
|
|
232
|
+
// Pipelines
|
|
212
233
|
default: {
|
|
213
234
|
if (pipelines.includes(key)) {
|
|
214
235
|
target.pipelines[key] = target.pipelines[key].concat(value).filter(Boolean);
|