@graphql-mesh/transform-hive 0.1.77
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 +16 -0
- package/index.js +84 -0
- package/index.mjs +82 -0
- package/package.json +40 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
|
|
2
|
+
import { HiveClient } from '@graphql-hive/client';
|
|
3
|
+
import { ExecutionResult, GraphQLSchema } from 'graphql';
|
|
4
|
+
import { DelegationContext } from '@graphql-tools/delegate';
|
|
5
|
+
import { ExecutionRequest } from '@graphql-tools/utils';
|
|
6
|
+
interface TransformationContext {
|
|
7
|
+
collectUsageCallback: ReturnType<HiveClient['collectUsage']>;
|
|
8
|
+
}
|
|
9
|
+
export default class HiveTransform implements MeshTransform {
|
|
10
|
+
private hiveClient;
|
|
11
|
+
constructor({ config, pubsub, logger }: MeshTransformOptions<YamlConfig.HivePlugin>);
|
|
12
|
+
transformSchema(schema: GraphQLSchema): GraphQLSchema;
|
|
13
|
+
transformRequest(request: ExecutionRequest, delegationContext: DelegationContext, transformationContext: TransformationContext): ExecutionRequest<Record<string, any>, any, any, Record<string, any>>;
|
|
14
|
+
transformResult(result: ExecutionResult, _delegationContext: DelegationContext, transformationContext: TransformationContext): ExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
package/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const client = require('@graphql-hive/client');
|
|
4
|
+
const stringInterpolation = require('@graphql-mesh/string-interpolation');
|
|
5
|
+
const crossHelpers = require('@graphql-mesh/cross-helpers');
|
|
6
|
+
|
|
7
|
+
class HiveTransform {
|
|
8
|
+
constructor({ config, pubsub, logger }) {
|
|
9
|
+
var _a;
|
|
10
|
+
const token = stringInterpolation.stringInterpolator.parse(config.token, {
|
|
11
|
+
env: crossHelpers.process.env,
|
|
12
|
+
});
|
|
13
|
+
let usage;
|
|
14
|
+
if (config.usage) {
|
|
15
|
+
usage = {
|
|
16
|
+
max: config.usage.max,
|
|
17
|
+
ttl: config.usage.ttl,
|
|
18
|
+
exclude: config.usage.exclude,
|
|
19
|
+
sampleRate: config.usage.sampleRate,
|
|
20
|
+
processVariables: config.usage.processVariables,
|
|
21
|
+
};
|
|
22
|
+
if ((_a = config.usage) === null || _a === void 0 ? void 0 : _a.clientInfo) {
|
|
23
|
+
usage.clientInfo = function (context) {
|
|
24
|
+
return {
|
|
25
|
+
name: stringInterpolation.stringInterpolator.parse(config.usage.clientInfo.name, { context, env: crossHelpers.process.env }),
|
|
26
|
+
version: stringInterpolation.stringInterpolator.parse(config.usage.clientInfo.version, { context, env: crossHelpers.process.env }),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
let reporting;
|
|
32
|
+
if (config.reporting) {
|
|
33
|
+
reporting = {
|
|
34
|
+
author: stringInterpolation.stringInterpolator.parse(config.reporting.author, { env: crossHelpers.process.env }),
|
|
35
|
+
commit: stringInterpolation.stringInterpolator.parse(config.reporting.commit, { env: crossHelpers.process.env }),
|
|
36
|
+
serviceName: stringInterpolation.stringInterpolator.parse(config.reporting.serviceName, { env: crossHelpers.process.env }),
|
|
37
|
+
serviceUrl: stringInterpolation.stringInterpolator.parse(config.reporting.serviceUrl, { env: crossHelpers.process.env }),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const agent = {
|
|
41
|
+
timeout: config.agent.timeout,
|
|
42
|
+
maxRetries: config.agent.maxRetries,
|
|
43
|
+
minTimeout: config.agent.minTimeout,
|
|
44
|
+
sendInterval: config.agent.sendInterval,
|
|
45
|
+
maxSize: config.agent.maxSize,
|
|
46
|
+
logger,
|
|
47
|
+
};
|
|
48
|
+
this.hiveClient = client.createHive({
|
|
49
|
+
enabled: true,
|
|
50
|
+
debug: !!crossHelpers.process.env.DEBUG,
|
|
51
|
+
token,
|
|
52
|
+
agent,
|
|
53
|
+
usage,
|
|
54
|
+
reporting,
|
|
55
|
+
});
|
|
56
|
+
const id = pubsub.subscribe('destroy', () => {
|
|
57
|
+
this.hiveClient
|
|
58
|
+
.dispose()
|
|
59
|
+
.catch(e => logger.error(`Hive client failed to dispose`, e))
|
|
60
|
+
.finally(() => pubsub.unsubscribe(id));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
transformSchema(schema) {
|
|
64
|
+
this.hiveClient.reportSchema({ schema });
|
|
65
|
+
return schema;
|
|
66
|
+
}
|
|
67
|
+
transformRequest(request, delegationContext, transformationContext) {
|
|
68
|
+
transformationContext.collectUsageCallback = this.hiveClient.collectUsage({
|
|
69
|
+
schema: delegationContext.transformedSchema,
|
|
70
|
+
document: request.document,
|
|
71
|
+
rootValue: request.rootValue,
|
|
72
|
+
contextValue: request.context,
|
|
73
|
+
variableValues: request.variables,
|
|
74
|
+
operationName: request.operationName,
|
|
75
|
+
});
|
|
76
|
+
return request;
|
|
77
|
+
}
|
|
78
|
+
transformResult(result, _delegationContext, transformationContext) {
|
|
79
|
+
transformationContext.collectUsageCallback(result);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = HiveTransform;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { createHive } from '@graphql-hive/client';
|
|
2
|
+
import { stringInterpolator } from '@graphql-mesh/string-interpolation';
|
|
3
|
+
import { process } from '@graphql-mesh/cross-helpers';
|
|
4
|
+
|
|
5
|
+
class HiveTransform {
|
|
6
|
+
constructor({ config, pubsub, logger }) {
|
|
7
|
+
var _a;
|
|
8
|
+
const token = stringInterpolator.parse(config.token, {
|
|
9
|
+
env: process.env,
|
|
10
|
+
});
|
|
11
|
+
let usage;
|
|
12
|
+
if (config.usage) {
|
|
13
|
+
usage = {
|
|
14
|
+
max: config.usage.max,
|
|
15
|
+
ttl: config.usage.ttl,
|
|
16
|
+
exclude: config.usage.exclude,
|
|
17
|
+
sampleRate: config.usage.sampleRate,
|
|
18
|
+
processVariables: config.usage.processVariables,
|
|
19
|
+
};
|
|
20
|
+
if ((_a = config.usage) === null || _a === void 0 ? void 0 : _a.clientInfo) {
|
|
21
|
+
usage.clientInfo = function (context) {
|
|
22
|
+
return {
|
|
23
|
+
name: stringInterpolator.parse(config.usage.clientInfo.name, { context, env: process.env }),
|
|
24
|
+
version: stringInterpolator.parse(config.usage.clientInfo.version, { context, env: process.env }),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
let reporting;
|
|
30
|
+
if (config.reporting) {
|
|
31
|
+
reporting = {
|
|
32
|
+
author: stringInterpolator.parse(config.reporting.author, { env: process.env }),
|
|
33
|
+
commit: stringInterpolator.parse(config.reporting.commit, { env: process.env }),
|
|
34
|
+
serviceName: stringInterpolator.parse(config.reporting.serviceName, { env: process.env }),
|
|
35
|
+
serviceUrl: stringInterpolator.parse(config.reporting.serviceUrl, { env: process.env }),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const agent = {
|
|
39
|
+
timeout: config.agent.timeout,
|
|
40
|
+
maxRetries: config.agent.maxRetries,
|
|
41
|
+
minTimeout: config.agent.minTimeout,
|
|
42
|
+
sendInterval: config.agent.sendInterval,
|
|
43
|
+
maxSize: config.agent.maxSize,
|
|
44
|
+
logger,
|
|
45
|
+
};
|
|
46
|
+
this.hiveClient = createHive({
|
|
47
|
+
enabled: true,
|
|
48
|
+
debug: !!process.env.DEBUG,
|
|
49
|
+
token,
|
|
50
|
+
agent,
|
|
51
|
+
usage,
|
|
52
|
+
reporting,
|
|
53
|
+
});
|
|
54
|
+
const id = pubsub.subscribe('destroy', () => {
|
|
55
|
+
this.hiveClient
|
|
56
|
+
.dispose()
|
|
57
|
+
.catch(e => logger.error(`Hive client failed to dispose`, e))
|
|
58
|
+
.finally(() => pubsub.unsubscribe(id));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
transformSchema(schema) {
|
|
62
|
+
this.hiveClient.reportSchema({ schema });
|
|
63
|
+
return schema;
|
|
64
|
+
}
|
|
65
|
+
transformRequest(request, delegationContext, transformationContext) {
|
|
66
|
+
transformationContext.collectUsageCallback = this.hiveClient.collectUsage({
|
|
67
|
+
schema: delegationContext.transformedSchema,
|
|
68
|
+
document: request.document,
|
|
69
|
+
rootValue: request.rootValue,
|
|
70
|
+
contextValue: request.context,
|
|
71
|
+
variableValues: request.variables,
|
|
72
|
+
operationName: request.operationName,
|
|
73
|
+
});
|
|
74
|
+
return request;
|
|
75
|
+
}
|
|
76
|
+
transformResult(result, _delegationContext, transformationContext) {
|
|
77
|
+
transformationContext.collectUsageCallback(result);
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export default HiveTransform;
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphql-mesh/transform-hive",
|
|
3
|
+
"version": "0.1.77",
|
|
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
|
+
"@graphql-tools/delegate": "9.0.17",
|
|
14
|
+
"@graphql-tools/utils": "9.1.1",
|
|
15
|
+
"tslib": "^2.4.0"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "Urigo/graphql-mesh",
|
|
20
|
+
"directory": "packages/transforms/hive"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"main": "index.js",
|
|
24
|
+
"module": "index.mjs",
|
|
25
|
+
"typings": "index.d.ts",
|
|
26
|
+
"typescript": {
|
|
27
|
+
"definition": "index.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"require": "./index.js",
|
|
32
|
+
"import": "./index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./*": {
|
|
35
|
+
"require": "./*.js",
|
|
36
|
+
"import": "./*.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
}
|
|
40
|
+
}
|