-
Notifications
You must be signed in to change notification settings - Fork 0
/
poll-schema-registry.js
48 lines (40 loc) · 1.28 KB
/
poll-schema-registry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const { get } = require('lodash');
const request = require('request-promise-native');
const config = require('./config');
exports.getServiceListWithTypeDefs = async (serviceSdlCache) => {
const baseUrl = config.schemaRegistryUrl;
let schemaChanged = false;
const serviceTypeDefinitions = await request({
baseUrl,
method: 'GET',
// Better approach to provide versions of services you have running in production
// instead of using just /schema/latest
url: '/schema/latest',
json: true,
});
const services = get(serviceTypeDefinitions, 'data', []).map((schema) => {
if (!schema.url) {
console.warn(
`Service url not found for type definition "${schema.name}"`
);
} else {
console.log(
`Got ${schema.name} service schema with version ${schema.version}`
);
}
const previousDefinition = serviceSdlCache.get(schema.name);
if (schema.type_defs !== previousDefinition) {
schemaChanged = true;
}
serviceSdlCache.set(schema.name, schema.type_defs);
return {
name: schema.name,
// note that URLs are used based on service name, utilizing docker internal network
url: `http://${schema.url}`,
version: schema.version,
typeDefs: schema.type_defs,
typeDefsOriginal: schema.type_defs_original
};
});
return { services, schemaChanged };
};