@steedos/service-api 2.5.13-beta.9 → 2.5.14-beta.1
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/index.js +22 -12
- package/package.json +6 -6
package/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const { LRUMap } = require('lru_map');
|
|
|
18
18
|
const validator = require('validator');
|
|
19
19
|
const enablePlayground = validator.toBoolean(process.env.STEEDOS_GRAPHQL_ENABLE_CONSOLE || 'true', true);
|
|
20
20
|
const openBrowser = require('react-dev-utils/openBrowser');
|
|
21
|
+
const requestIp = require('request-ip');
|
|
21
22
|
const mixinOptions = {
|
|
22
23
|
|
|
23
24
|
// Global GraphQL typeDefs
|
|
@@ -86,7 +87,7 @@ const mixinOptions = {
|
|
|
86
87
|
introspection: enablePlayground
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
+
const ObjectDataLoaderMapKeys = {};
|
|
90
91
|
/**
|
|
91
92
|
* @typedef {import('moleculer').Context} Context Moleculer's Context
|
|
92
93
|
* @typedef {import('http').IncomingMessage} IncomingRequest Incoming HTTP Request
|
|
@@ -170,10 +171,13 @@ module.exports = {
|
|
|
170
171
|
* @param {ServerResponse} res
|
|
171
172
|
* @param {Object} data
|
|
172
173
|
*
|
|
174
|
+
*
|
|
175
|
+
*/
|
|
173
176
|
onBeforeCall(ctx, route, req, res) {
|
|
174
177
|
// Set request headers to context meta
|
|
175
178
|
ctx.meta.userAgent = req.headers["user-agent"];
|
|
176
|
-
|
|
179
|
+
ctx.meta.clientIp = requestIp.getClientIp(req);
|
|
180
|
+
},
|
|
177
181
|
|
|
178
182
|
/**
|
|
179
183
|
* After call hook. You can modify the data.
|
|
@@ -324,9 +328,14 @@ module.exports = {
|
|
|
324
328
|
* @param {Object.<string, any>} args - Arguments passed to GraphQL child resolver
|
|
325
329
|
* @returns {string} Key to the dataloader instance
|
|
326
330
|
*/
|
|
327
|
-
getObjectDataLoaderMapKey(objectName) {
|
|
331
|
+
getObjectDataLoaderMapKey(objectName, referenceToField = '_id') {
|
|
328
332
|
if (objectName) {
|
|
329
|
-
|
|
333
|
+
const key = `object:${objectName}.${referenceToField}`;
|
|
334
|
+
if(!ObjectDataLoaderMapKeys[objectName]){
|
|
335
|
+
ObjectDataLoaderMapKeys[objectName] = [] ;
|
|
336
|
+
}
|
|
337
|
+
ObjectDataLoaderMapKeys[objectName].push(key);
|
|
338
|
+
return key;
|
|
330
339
|
}
|
|
331
340
|
// 如果没有objectName,则抛出错误信息
|
|
332
341
|
throw new Error("objectName is required");
|
|
@@ -338,6 +347,7 @@ module.exports = {
|
|
|
338
347
|
const {root, args, context, resolveInfo} = graphqlCtx;
|
|
339
348
|
const dataLoaderMapKey = this.getObjectDataLoaderMapKey(
|
|
340
349
|
staticParams.__objectName || staticParams.objectName
|
|
350
|
+
, staticParams.referenceToField || '_id'
|
|
341
351
|
);
|
|
342
352
|
const objectDataLoaders = this.objectDataLoaders;
|
|
343
353
|
// if a dataLoader batching parameter is specified, then all root params can be data loaded;
|
|
@@ -937,19 +947,19 @@ module.exports = {
|
|
|
937
947
|
'@objectRecordEvent.*.*': function(ctx){
|
|
938
948
|
const { objectApiName, isUpdate, isDelete, id, doc } = ctx.params;
|
|
939
949
|
if(objectApiName && (isUpdate || isDelete)){
|
|
940
|
-
const
|
|
941
|
-
objectApiName
|
|
942
|
-
);
|
|
950
|
+
const keys = ObjectDataLoaderMapKeys[objectApiName] || [];
|
|
943
951
|
let dataLoaderKeys = [id];
|
|
944
952
|
if(objectApiName === 'space_users'){
|
|
945
953
|
dataLoaderKeys.push(doc.user)
|
|
946
954
|
}
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
955
|
+
_.each(keys, (key)=>{
|
|
956
|
+
const loader = this.objectDataLoaders.get(key);
|
|
957
|
+
if(loader){
|
|
958
|
+
for(const dataLoaderKey of dataLoaderKeys){
|
|
959
|
+
loader.clear(dataLoaderKey);
|
|
960
|
+
}
|
|
951
961
|
}
|
|
952
|
-
}
|
|
962
|
+
})
|
|
953
963
|
}
|
|
954
964
|
},
|
|
955
965
|
'service-ui.started': function(){
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-api",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.14-beta.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@steedos/auth": "2.5.
|
|
8
|
-
"@steedos/router": "2.5.
|
|
9
|
-
"@steedos/service-object-graphql": "2.5.
|
|
10
|
-
"@steedos/service-ui": "2.5.
|
|
7
|
+
"@steedos/auth": "2.5.14-beta.1",
|
|
8
|
+
"@steedos/router": "2.5.14-beta.1",
|
|
9
|
+
"@steedos/service-object-graphql": "2.5.14-beta.1",
|
|
10
|
+
"@steedos/service-ui": "2.5.14-beta.1",
|
|
11
11
|
"graphql": "^15.8.0",
|
|
12
12
|
"graphql-iso-date": "^3.6.1",
|
|
13
13
|
"graphql-type-json": "^0.3.2",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "65dadab97683db763d4c4d6e63bf5f645e1359bc",
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/graphql-iso-date": "^3.4.0",
|
|
28
28
|
"@types/react-dev-utils": "^9.0.11"
|