@steedos/service-object-graphql 2.5.5 → 2.6.1-beta.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/package.json +6 -6
- package/package.service.js +58 -97
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-object-graphql",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1-beta.2",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"description": "steedos package",
|
|
16
16
|
"repository": {},
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "9051772a001ba99aeaf026680ef171d508e92b8f",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@steedos/filters": "2.
|
|
21
|
-
"@steedos/i18n": "2.
|
|
22
|
-
"@steedos/objectql": "2.
|
|
23
|
-
"@steedos/service-object-mixin": "2.
|
|
20
|
+
"@steedos/filters": "2.6.1-beta.2",
|
|
21
|
+
"@steedos/i18n": "2.6.1-beta.2",
|
|
22
|
+
"@steedos/objectql": "2.6.1-beta.2",
|
|
23
|
+
"@steedos/service-object-mixin": "2.6.1-beta.2",
|
|
24
24
|
"graphql": "^15.8.0",
|
|
25
25
|
"graphql-parse-resolve-info": "^4.12.3",
|
|
26
26
|
"moleculer": "^0.14.25",
|
package/package.service.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: sunhaolin@hotoa.com
|
|
3
3
|
* @Date: 2023-03-23 15:12:14
|
|
4
4
|
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
-
* @LastEditTime: 2023-06-
|
|
5
|
+
* @LastEditTime: 2023-06-27 10:06:21
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
|
|
@@ -14,7 +14,6 @@ const {
|
|
|
14
14
|
getGraphqlActions,
|
|
15
15
|
getQueryFields
|
|
16
16
|
} = require('./lib');
|
|
17
|
-
const open = require('open');
|
|
18
17
|
|
|
19
18
|
const { formatFiltersToODataQuery } = require("@steedos/filters");
|
|
20
19
|
|
|
@@ -22,6 +21,8 @@ const serviceObjectMixin = require('@steedos/service-object-mixin');
|
|
|
22
21
|
|
|
23
22
|
const { QUERY_DOCS_TOP } = require('./lib/consts');
|
|
24
23
|
|
|
24
|
+
const { Register } = require('@steedos/metadata-registrar')
|
|
25
|
+
|
|
25
26
|
const _ = require('lodash');
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -35,8 +36,6 @@ module.exports = {
|
|
|
35
36
|
globalGraphQLSettings: {}, // service-api 里generateGraphQLSchema使用
|
|
36
37
|
getGraphqlFields: getQueryFields,
|
|
37
38
|
|
|
38
|
-
projectStarted: false,
|
|
39
|
-
|
|
40
39
|
/**
|
|
41
40
|
* Settings
|
|
42
41
|
*/
|
|
@@ -231,70 +230,61 @@ module.exports = {
|
|
|
231
230
|
* Events
|
|
232
231
|
*/
|
|
233
232
|
events: {
|
|
233
|
+
"graphql.schema.changed": {
|
|
234
|
+
params: {},
|
|
235
|
+
async handler(ctx) {
|
|
236
|
+
await this.ChangeGlobalGraphQLSettings()
|
|
237
|
+
}
|
|
238
|
+
},
|
|
234
239
|
// 此事件表示软件包发生变化(包括加载、卸载、对象发生变化),接收到此事件后重新生成graphql schema
|
|
235
240
|
"$packages.changed": {
|
|
236
241
|
params: {},
|
|
237
242
|
async handler(ctx) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
// console.log("Metadata:", ctx.meta);
|
|
241
|
-
// console.log("The called event name:", ctx.eventName);
|
|
242
|
-
|
|
243
|
-
const objGraphqlMap = await this.generateObjGraphqlMap(this.name)
|
|
244
|
-
|
|
245
|
-
let type = []
|
|
246
|
-
let query = []
|
|
247
|
-
let mutation = []
|
|
248
|
-
let resolvers = {}
|
|
249
|
-
let resolversQuery = {}
|
|
250
|
-
let resolversMutation = {}
|
|
251
|
-
|
|
252
|
-
for (const objectName in objGraphqlMap) {
|
|
253
|
-
if (Object.hasOwnProperty.call(objGraphqlMap, objectName)) {
|
|
254
|
-
const gMap = objGraphqlMap[objectName];
|
|
255
|
-
type.push(gMap.type)
|
|
256
|
-
query = query.concat(gMap.query)
|
|
257
|
-
mutation = mutation.concat(gMap.mutation)
|
|
258
|
-
resolvers = Object.assign(resolvers, gMap.resolvers)
|
|
259
|
-
resolversQuery = Object.assign(resolversQuery, gMap.resolversQuery)
|
|
260
|
-
resolversMutation = Object.assign(resolversMutation, gMap.resolversMutation)
|
|
261
|
-
}
|
|
243
|
+
if(broker.nodeID != 'steedos-primary'){
|
|
244
|
+
return ;
|
|
262
245
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
query: query,
|
|
267
|
-
mutation: mutation,
|
|
268
|
-
resolvers: {
|
|
269
|
-
...resolvers,
|
|
270
|
-
Query: resolversQuery,
|
|
271
|
-
Mutation: resolversMutation
|
|
272
|
-
}
|
|
246
|
+
if(this.setTimeoutId){
|
|
247
|
+
clearTimeout(this.setTimeoutId);
|
|
248
|
+
this.setTimeoutId = null;
|
|
273
249
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
250
|
+
this.setTimeoutId = setTimeout(async ()=>{
|
|
251
|
+
// console.log("Payload:", ctx.params);
|
|
252
|
+
// console.log("Sender:", ctx.nodeID);
|
|
253
|
+
// console.log("Metadata:", ctx.meta);
|
|
254
|
+
// console.log("The called event name:", ctx.eventName);
|
|
255
|
+
const objGraphqlMap = await this.generateObjGraphqlMap(this.name)
|
|
256
|
+
let type = []
|
|
257
|
+
let query = []
|
|
258
|
+
let mutation = []
|
|
259
|
+
let resolvers = {}
|
|
260
|
+
let resolversQuery = {}
|
|
261
|
+
let resolversMutation = {}
|
|
262
|
+
|
|
263
|
+
for (const objectName in objGraphqlMap) {
|
|
264
|
+
if (Object.hasOwnProperty.call(objGraphqlMap, objectName)) {
|
|
265
|
+
const gMap = objGraphqlMap[objectName];
|
|
266
|
+
type.push(gMap.type)
|
|
267
|
+
query = query.concat(gMap.query)
|
|
268
|
+
mutation = mutation.concat(gMap.mutation)
|
|
269
|
+
resolvers = Object.assign(resolvers, gMap.resolvers)
|
|
270
|
+
resolversQuery = Object.assign(resolversQuery, gMap.resolversQuery)
|
|
271
|
+
resolversMutation = Object.assign(resolversMutation, gMap.resolversMutation)
|
|
272
|
+
}
|
|
286
273
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
274
|
+
const globalGraphQLSettings = {
|
|
275
|
+
type: type,
|
|
276
|
+
query: query,
|
|
277
|
+
mutation: mutation,
|
|
278
|
+
resolvers: {
|
|
279
|
+
...resolvers,
|
|
280
|
+
Query: resolversQuery,
|
|
281
|
+
Mutation: resolversMutation
|
|
295
282
|
}
|
|
296
283
|
}
|
|
297
|
-
|
|
284
|
+
await Register.add(ctx.broker, {key: 'globalGraphQLSettings', data: globalGraphQLSettings}, {})
|
|
285
|
+
ctx.broker.broadcast("graphql.schema.changed")
|
|
286
|
+
|
|
287
|
+
}, 100)
|
|
298
288
|
}
|
|
299
289
|
}
|
|
300
290
|
},
|
|
@@ -303,7 +293,14 @@ module.exports = {
|
|
|
303
293
|
* Methods
|
|
304
294
|
*/
|
|
305
295
|
methods: {
|
|
306
|
-
|
|
296
|
+
async ChangeGlobalGraphQLSettings() {
|
|
297
|
+
const result = await Register.get(this.broker, 'globalGraphQLSettings');
|
|
298
|
+
if(result){
|
|
299
|
+
this.globalGraphQLSettings = result.metadata;
|
|
300
|
+
// 发送事件,通知ApolloService重新加载graphql schema; api 服务和graphql服务在同一个节点上.
|
|
301
|
+
this.broker.broadcastLocal('$services.changed');
|
|
302
|
+
}
|
|
303
|
+
},
|
|
307
304
|
find: {
|
|
308
305
|
async handler(objectName, query, userSession) {
|
|
309
306
|
const obj = this.getObject(objectName)
|
|
@@ -488,43 +485,7 @@ module.exports = {
|
|
|
488
485
|
* Service started lifecycle event handler
|
|
489
486
|
*/
|
|
490
487
|
async started() {
|
|
491
|
-
|
|
492
|
-
// setTimeout(async function () {
|
|
493
|
-
// const objGraphqlMap = await that.generateObjGraphqlMap(that.name)
|
|
494
|
-
|
|
495
|
-
// let globalTypeDefs = []
|
|
496
|
-
// let query = []
|
|
497
|
-
// let mutation = []
|
|
498
|
-
// let resolvers = {}
|
|
499
|
-
// let resolversQuery = {}
|
|
500
|
-
// let resolversMutation = {}
|
|
501
|
-
|
|
502
|
-
// for (const objectName in objGraphqlMap) {
|
|
503
|
-
// if (Object.hasOwnProperty.call(objGraphqlMap, objectName)) {
|
|
504
|
-
// const gMap = objGraphqlMap[objectName];
|
|
505
|
-
// globalTypeDefs.push(gMap.type)
|
|
506
|
-
// query = query.concat(gMap.query)
|
|
507
|
-
// mutation = mutation.concat(gMap.mutation)
|
|
508
|
-
// resolvers = Object.assign(resolvers, gMap.resolvers)
|
|
509
|
-
// resolversQuery = Object.assign(resolversQuery, gMap.resolversQuery)
|
|
510
|
-
// resolversMutation = Object.assign(resolversMutation, gMap.resolversMutation)
|
|
511
|
-
// }
|
|
512
|
-
// }
|
|
513
|
-
|
|
514
|
-
// that.globalTypeDefs = globalTypeDefs
|
|
515
|
-
|
|
516
|
-
// that.settings.graphql = {
|
|
517
|
-
// query: query,
|
|
518
|
-
// mutation: mutation,
|
|
519
|
-
// resolvers: {
|
|
520
|
-
// ...resolvers,
|
|
521
|
-
// Query: resolversQuery,
|
|
522
|
-
// Mutation: resolversMutation
|
|
523
|
-
// }
|
|
524
|
-
// }
|
|
525
|
-
|
|
526
|
-
// console.log('graphql:', new Date())
|
|
527
|
-
// }, 20000)
|
|
488
|
+
await this.ChangeGlobalGraphQLSettings()
|
|
528
489
|
},
|
|
529
490
|
|
|
530
491
|
/**
|