@envelop/prometheus 6.5.0 → 6.5.1-alpha-20220824152235-afd061e6
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/cjs/index.js +2 -0
- package/cjs/traced-schema.js +68 -0
- package/esm/index.js +2 -0
- package/esm/traced-schema.js +64 -0
- package/package.json +3 -2
- package/typings/traced-schema.d.cts +2 -0
- package/typings/traced-schema.d.ts +2 -0
package/cjs/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const utils_js_1 = require("./utils.js");
|
|
|
9
9
|
Object.defineProperty(exports, "createHistogram", { enumerable: true, get: function () { return utils_js_1.createHistogram; } });
|
|
10
10
|
Object.defineProperty(exports, "createCounter", { enumerable: true, get: function () { return utils_js_1.createCounter; } });
|
|
11
11
|
Object.defineProperty(exports, "createSummary", { enumerable: true, get: function () { return utils_js_1.createSummary; } });
|
|
12
|
+
const traced_schema_js_1 = require("./traced-schema.js");
|
|
12
13
|
const promPluginContext = Symbol('promPluginContext');
|
|
13
14
|
const promPluginExecutionStartTimeSymbol = Symbol('promPluginExecutionStartTimeSymbol');
|
|
14
15
|
const usePrometheus = (config = {}) => {
|
|
@@ -251,6 +252,7 @@ const usePrometheus = (config = {}) => {
|
|
|
251
252
|
});
|
|
252
253
|
},
|
|
253
254
|
onSchemaChange({ schema }) {
|
|
255
|
+
(0, traced_schema_js_1.prepareTracedSchema)(schema);
|
|
254
256
|
typeInfo = new graphql_1.TypeInfo(schema);
|
|
255
257
|
},
|
|
256
258
|
onParse,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareTracedSchema = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const core_1 = require("@envelop/core");
|
|
6
|
+
const trackedSchemaSymbol = Symbol('TRACKED_SCHEMA');
|
|
7
|
+
function prepareTracedSchema(schema) {
|
|
8
|
+
if (!schema || schema[trackedSchemaSymbol]) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
schema[trackedSchemaSymbol] = true;
|
|
12
|
+
const entries = Object.values(schema.getTypeMap());
|
|
13
|
+
for (const type of entries) {
|
|
14
|
+
if (!(0, graphql_1.isIntrospectionType)(type) && (0, graphql_1.isObjectType)(type)) {
|
|
15
|
+
const fields = Object.values(type.getFields());
|
|
16
|
+
for (const field of fields) {
|
|
17
|
+
let resolverFn = (field.resolve || graphql_1.defaultFieldResolver);
|
|
18
|
+
field.resolve = async (root, args, context, info) => {
|
|
19
|
+
if (context && context[core_1.resolversHooksSymbol]) {
|
|
20
|
+
const hooks = context[core_1.resolversHooksSymbol];
|
|
21
|
+
const afterCalls = [];
|
|
22
|
+
for (const hook of hooks) {
|
|
23
|
+
const afterFn = await hook({
|
|
24
|
+
root,
|
|
25
|
+
args,
|
|
26
|
+
context,
|
|
27
|
+
info,
|
|
28
|
+
resolverFn,
|
|
29
|
+
replaceResolverFn: newFn => {
|
|
30
|
+
resolverFn = newFn;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
afterFn && afterCalls.push(afterFn);
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
let result = await resolverFn(root, args, context, info);
|
|
37
|
+
for (const afterFn of afterCalls) {
|
|
38
|
+
afterFn({
|
|
39
|
+
result,
|
|
40
|
+
setResult: newResult => {
|
|
41
|
+
result = newResult;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
let resultErr = e;
|
|
49
|
+
for (const afterFn of afterCalls) {
|
|
50
|
+
afterFn({
|
|
51
|
+
result: resultErr,
|
|
52
|
+
setResult: newResult => {
|
|
53
|
+
resultErr = newResult;
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
throw resultErr;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return resolverFn(root, args, context, info);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.prepareTracedSchema = prepareTracedSchema;
|
package/esm/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { isIntrospectionOperationString, isAsyncIterable, } from '@envelop/core'
|
|
|
3
3
|
import { TypeInfo } from 'graphql';
|
|
4
4
|
import { Summary, Counter, Histogram, register as defaultRegistry } from 'prom-client';
|
|
5
5
|
import { getHistogramFromConfig, createHistogram, createCounter, shouldTraceFieldResolver, createInternalContext, extractDeprecatedFields, createSummary, } from './utils.js';
|
|
6
|
+
import { prepareTracedSchema } from './traced-schema.js';
|
|
6
7
|
export { createCounter, createHistogram, createSummary };
|
|
7
8
|
const promPluginContext = Symbol('promPluginContext');
|
|
8
9
|
const promPluginExecutionStartTimeSymbol = Symbol('promPluginExecutionStartTimeSymbol');
|
|
@@ -246,6 +247,7 @@ export const usePrometheus = (config = {}) => {
|
|
|
246
247
|
});
|
|
247
248
|
},
|
|
248
249
|
onSchemaChange({ schema }) {
|
|
250
|
+
prepareTracedSchema(schema);
|
|
249
251
|
typeInfo = new TypeInfo(schema);
|
|
250
252
|
},
|
|
251
253
|
onParse,
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { defaultFieldResolver, isIntrospectionType, isObjectType } from 'graphql';
|
|
2
|
+
import { resolversHooksSymbol } from '@envelop/core';
|
|
3
|
+
const trackedSchemaSymbol = Symbol('TRACKED_SCHEMA');
|
|
4
|
+
export function prepareTracedSchema(schema) {
|
|
5
|
+
if (!schema || schema[trackedSchemaSymbol]) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
schema[trackedSchemaSymbol] = true;
|
|
9
|
+
const entries = Object.values(schema.getTypeMap());
|
|
10
|
+
for (const type of entries) {
|
|
11
|
+
if (!isIntrospectionType(type) && isObjectType(type)) {
|
|
12
|
+
const fields = Object.values(type.getFields());
|
|
13
|
+
for (const field of fields) {
|
|
14
|
+
let resolverFn = (field.resolve || defaultFieldResolver);
|
|
15
|
+
field.resolve = async (root, args, context, info) => {
|
|
16
|
+
if (context && context[resolversHooksSymbol]) {
|
|
17
|
+
const hooks = context[resolversHooksSymbol];
|
|
18
|
+
const afterCalls = [];
|
|
19
|
+
for (const hook of hooks) {
|
|
20
|
+
const afterFn = await hook({
|
|
21
|
+
root,
|
|
22
|
+
args,
|
|
23
|
+
context,
|
|
24
|
+
info,
|
|
25
|
+
resolverFn,
|
|
26
|
+
replaceResolverFn: newFn => {
|
|
27
|
+
resolverFn = newFn;
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
afterFn && afterCalls.push(afterFn);
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
let result = await resolverFn(root, args, context, info);
|
|
34
|
+
for (const afterFn of afterCalls) {
|
|
35
|
+
afterFn({
|
|
36
|
+
result,
|
|
37
|
+
setResult: newResult => {
|
|
38
|
+
result = newResult;
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
let resultErr = e;
|
|
46
|
+
for (const afterFn of afterCalls) {
|
|
47
|
+
afterFn({
|
|
48
|
+
result: resultErr,
|
|
49
|
+
setResult: newResult => {
|
|
50
|
+
resultErr = newResult;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
throw resultErr;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return resolverFn(root, args, context, info);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/prometheus",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.1-alpha-20220824152235-afd061e6",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "
|
|
6
|
+
"@envelop/core": "2.5.1-alpha-20220824152235-afd061e6",
|
|
7
|
+
"@envelop/types": "2.3.2-alpha-20220824152235-afd061e6",
|
|
7
8
|
"prom-client": "^13 || ^14.0.0",
|
|
8
9
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
9
10
|
},
|