@graphql-mesh/plugin-hive 0.0.0
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.d.ts +2 -0
- package/index.js +71 -0
- package/index.mjs +69 -0
- package/package.json +38 -0
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const client = require('@graphql-hive/client');
|
|
4
|
+
const crossHelpers = require('@graphql-mesh/cross-helpers');
|
|
5
|
+
const stringInterpolation = require('@graphql-mesh/string-interpolation');
|
|
6
|
+
|
|
7
|
+
function useMeshHive(pluginOptions) {
|
|
8
|
+
var _a;
|
|
9
|
+
const token = stringInterpolation.stringInterpolator.parse(pluginOptions.token, {
|
|
10
|
+
env: crossHelpers.process.env,
|
|
11
|
+
});
|
|
12
|
+
if (!token) {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
let usage;
|
|
16
|
+
if (pluginOptions.usage) {
|
|
17
|
+
usage = {
|
|
18
|
+
max: pluginOptions.usage.max,
|
|
19
|
+
ttl: pluginOptions.usage.ttl,
|
|
20
|
+
exclude: pluginOptions.usage.exclude,
|
|
21
|
+
sampleRate: pluginOptions.usage.sampleRate,
|
|
22
|
+
processVariables: pluginOptions.usage.processVariables,
|
|
23
|
+
};
|
|
24
|
+
if ((_a = pluginOptions.usage) === null || _a === void 0 ? void 0 : _a.clientInfo) {
|
|
25
|
+
usage.clientInfo = function (context) {
|
|
26
|
+
return {
|
|
27
|
+
name: stringInterpolation.stringInterpolator.parse(pluginOptions.usage.clientInfo.name, { context, env: crossHelpers.process.env }),
|
|
28
|
+
version: stringInterpolation.stringInterpolator.parse(pluginOptions.usage.clientInfo.version, { context, env: crossHelpers.process.env }),
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
let reporting;
|
|
34
|
+
if (pluginOptions.reporting) {
|
|
35
|
+
reporting = {
|
|
36
|
+
author: stringInterpolation.stringInterpolator.parse(pluginOptions.reporting.author, { env: crossHelpers.process.env }),
|
|
37
|
+
commit: stringInterpolation.stringInterpolator.parse(pluginOptions.reporting.commit, { env: crossHelpers.process.env }),
|
|
38
|
+
serviceName: stringInterpolation.stringInterpolator.parse(pluginOptions.reporting.serviceName, { env: crossHelpers.process.env }),
|
|
39
|
+
serviceUrl: stringInterpolation.stringInterpolator.parse(pluginOptions.reporting.serviceUrl, { env: crossHelpers.process.env }),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const agent = {
|
|
43
|
+
timeout: pluginOptions.agent.timeout,
|
|
44
|
+
maxRetries: pluginOptions.agent.maxRetries,
|
|
45
|
+
minTimeout: pluginOptions.agent.minTimeout,
|
|
46
|
+
sendInterval: pluginOptions.agent.sendInterval,
|
|
47
|
+
maxSize: pluginOptions.agent.maxSize,
|
|
48
|
+
logger: pluginOptions.logger,
|
|
49
|
+
};
|
|
50
|
+
const hiveClient = client.createHive({
|
|
51
|
+
enabled: true,
|
|
52
|
+
debug: !!crossHelpers.process.env.DEBUG,
|
|
53
|
+
token,
|
|
54
|
+
agent,
|
|
55
|
+
usage,
|
|
56
|
+
reporting,
|
|
57
|
+
});
|
|
58
|
+
const id = pluginOptions.pubsub.subscribe('destroy', () => {
|
|
59
|
+
hiveClient
|
|
60
|
+
.dispose()
|
|
61
|
+
.catch(e => pluginOptions.logger.error(`Hive client failed to dispose`, e))
|
|
62
|
+
.finally(() => pluginOptions.pubsub.unsubscribe(id));
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
onPluginInit({ addPlugin }) {
|
|
66
|
+
addPlugin(client.useHive(hiveClient));
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = useMeshHive;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createHive, useHive } from '@graphql-hive/client';
|
|
2
|
+
import { process } from '@graphql-mesh/cross-helpers';
|
|
3
|
+
import { stringInterpolator } from '@graphql-mesh/string-interpolation';
|
|
4
|
+
|
|
5
|
+
function useMeshHive(pluginOptions) {
|
|
6
|
+
var _a;
|
|
7
|
+
const token = stringInterpolator.parse(pluginOptions.token, {
|
|
8
|
+
env: process.env,
|
|
9
|
+
});
|
|
10
|
+
if (!token) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
let usage;
|
|
14
|
+
if (pluginOptions.usage) {
|
|
15
|
+
usage = {
|
|
16
|
+
max: pluginOptions.usage.max,
|
|
17
|
+
ttl: pluginOptions.usage.ttl,
|
|
18
|
+
exclude: pluginOptions.usage.exclude,
|
|
19
|
+
sampleRate: pluginOptions.usage.sampleRate,
|
|
20
|
+
processVariables: pluginOptions.usage.processVariables,
|
|
21
|
+
};
|
|
22
|
+
if ((_a = pluginOptions.usage) === null || _a === void 0 ? void 0 : _a.clientInfo) {
|
|
23
|
+
usage.clientInfo = function (context) {
|
|
24
|
+
return {
|
|
25
|
+
name: stringInterpolator.parse(pluginOptions.usage.clientInfo.name, { context, env: process.env }),
|
|
26
|
+
version: stringInterpolator.parse(pluginOptions.usage.clientInfo.version, { context, env: process.env }),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
let reporting;
|
|
32
|
+
if (pluginOptions.reporting) {
|
|
33
|
+
reporting = {
|
|
34
|
+
author: stringInterpolator.parse(pluginOptions.reporting.author, { env: process.env }),
|
|
35
|
+
commit: stringInterpolator.parse(pluginOptions.reporting.commit, { env: process.env }),
|
|
36
|
+
serviceName: stringInterpolator.parse(pluginOptions.reporting.serviceName, { env: process.env }),
|
|
37
|
+
serviceUrl: stringInterpolator.parse(pluginOptions.reporting.serviceUrl, { env: process.env }),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const agent = {
|
|
41
|
+
timeout: pluginOptions.agent.timeout,
|
|
42
|
+
maxRetries: pluginOptions.agent.maxRetries,
|
|
43
|
+
minTimeout: pluginOptions.agent.minTimeout,
|
|
44
|
+
sendInterval: pluginOptions.agent.sendInterval,
|
|
45
|
+
maxSize: pluginOptions.agent.maxSize,
|
|
46
|
+
logger: pluginOptions.logger,
|
|
47
|
+
};
|
|
48
|
+
const hiveClient = createHive({
|
|
49
|
+
enabled: true,
|
|
50
|
+
debug: !!process.env.DEBUG,
|
|
51
|
+
token,
|
|
52
|
+
agent,
|
|
53
|
+
usage,
|
|
54
|
+
reporting,
|
|
55
|
+
});
|
|
56
|
+
const id = pluginOptions.pubsub.subscribe('destroy', () => {
|
|
57
|
+
hiveClient
|
|
58
|
+
.dispose()
|
|
59
|
+
.catch(e => pluginOptions.logger.error(`Hive client failed to dispose`, e))
|
|
60
|
+
.finally(() => pluginOptions.pubsub.unsubscribe(id));
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
onPluginInit({ addPlugin }) {
|
|
64
|
+
addPlugin(useHive(hiveClient));
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default useMeshHive;
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphql-mesh/plugin-hive",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"peerDependencies": {
|
|
6
|
+
"graphql": "*"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@graphql-hive/client": "0.21.1",
|
|
10
|
+
"@graphql-mesh/cross-helpers": "0.2.10",
|
|
11
|
+
"@graphql-mesh/string-interpolation": "0.3.3",
|
|
12
|
+
"@graphql-mesh/types": "0.86.0",
|
|
13
|
+
"tslib": "^2.4.0"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "Urigo/graphql-mesh",
|
|
18
|
+
"directory": "packages/plugins/hive"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"module": "index.mjs",
|
|
23
|
+
"typings": "index.d.ts",
|
|
24
|
+
"typescript": {
|
|
25
|
+
"definition": "index.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"require": "./index.js",
|
|
30
|
+
"import": "./index.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./*": {
|
|
33
|
+
"require": "./*.js",
|
|
34
|
+
"import": "./*.mjs"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
}
|
|
38
|
+
}
|