@envelop/apollo-tracing 1.1.0 → 1.2.2-alpha-33ac2d1.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 +1 -1
- package/index.js +2 -33
- package/index.mjs +1 -32
- package/package.json +4 -2
package/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Plugin } from '@envelop/
|
|
1
|
+
import { Plugin } from '@envelop/core';
|
|
2
2
|
export declare const useApolloTracing: () => Plugin;
|
package/index.js
CHANGED
|
@@ -2,40 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
const core = require('@envelop/core');
|
|
5
6
|
const graphql = require('graphql');
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
-
* Returns true if the provided object implements the AsyncIterator protocol via
|
|
9
|
-
* implementing a `Symbol.asyncIterator` method.
|
|
10
|
-
*
|
|
11
|
-
* Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts
|
|
12
|
-
*/
|
|
13
|
-
function isAsyncIterable(maybeAsyncIterable) {
|
|
14
|
-
return (maybeAsyncIterable != null &&
|
|
15
|
-
typeof maybeAsyncIterable === 'object' &&
|
|
16
|
-
typeof maybeAsyncIterable[Symbol.asyncIterator] === 'function');
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* A utility function for hanlding `onExecuteDone` hook result, for simplifying the hanlding of AsyncIterable returned from `execute`.
|
|
20
|
-
*
|
|
21
|
-
* @param payload The payload send to `onExecuteDone` hook function
|
|
22
|
-
* @param fn The handler to be executed on each result
|
|
23
|
-
* @returns a subscription for streamed results, or undefined in case of an non-async
|
|
24
|
-
*/
|
|
25
|
-
function handleStreamOrSingleExecutionResult(payload, fn) {
|
|
26
|
-
if (isAsyncIterable(payload.result)) {
|
|
27
|
-
return { onNext: fn };
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
fn({
|
|
31
|
-
args: payload.args,
|
|
32
|
-
result: payload.result,
|
|
33
|
-
setResult: payload.setResult,
|
|
34
|
-
});
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
8
|
const HR_TO_NS = 1e9;
|
|
40
9
|
const NS_TO_MS = 1e6;
|
|
41
10
|
function durationHrTimeToNanos(hrtime) {
|
|
@@ -94,7 +63,7 @@ const useApolloTracing = () => {
|
|
|
94
63
|
}),
|
|
95
64
|
},
|
|
96
65
|
};
|
|
97
|
-
return handleStreamOrSingleExecutionResult(payload, ({ result }) => {
|
|
66
|
+
return core.handleStreamOrSingleExecutionResult(payload, ({ result }) => {
|
|
98
67
|
result.extensions = result.extensions || {};
|
|
99
68
|
result.extensions.tracing = tracing;
|
|
100
69
|
});
|
package/index.mjs
CHANGED
|
@@ -1,37 +1,6 @@
|
|
|
1
|
+
import { handleStreamOrSingleExecutionResult } from '@envelop/core';
|
|
1
2
|
import { responsePathAsArray } from 'graphql';
|
|
2
3
|
|
|
3
|
-
/**
|
|
4
|
-
* Returns true if the provided object implements the AsyncIterator protocol via
|
|
5
|
-
* implementing a `Symbol.asyncIterator` method.
|
|
6
|
-
*
|
|
7
|
-
* Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts
|
|
8
|
-
*/
|
|
9
|
-
function isAsyncIterable(maybeAsyncIterable) {
|
|
10
|
-
return (maybeAsyncIterable != null &&
|
|
11
|
-
typeof maybeAsyncIterable === 'object' &&
|
|
12
|
-
typeof maybeAsyncIterable[Symbol.asyncIterator] === 'function');
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* A utility function for hanlding `onExecuteDone` hook result, for simplifying the hanlding of AsyncIterable returned from `execute`.
|
|
16
|
-
*
|
|
17
|
-
* @param payload The payload send to `onExecuteDone` hook function
|
|
18
|
-
* @param fn The handler to be executed on each result
|
|
19
|
-
* @returns a subscription for streamed results, or undefined in case of an non-async
|
|
20
|
-
*/
|
|
21
|
-
function handleStreamOrSingleExecutionResult(payload, fn) {
|
|
22
|
-
if (isAsyncIterable(payload.result)) {
|
|
23
|
-
return { onNext: fn };
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
fn({
|
|
27
|
-
args: payload.args,
|
|
28
|
-
result: payload.result,
|
|
29
|
-
setResult: payload.setResult,
|
|
30
|
-
});
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
4
|
const HR_TO_NS = 1e9;
|
|
36
5
|
const NS_TO_MS = 1e6;
|
|
37
6
|
function durationHrTimeToNanos(hrtime) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/apollo-tracing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.2-alpha-33ac2d1.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
+
"@envelop/core": "1.6.6-alpha-33ac2d1.0",
|
|
6
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
8
|
},
|
|
8
9
|
"dependencies": {
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
"./*": {
|
|
30
31
|
"require": "./*.js",
|
|
31
32
|
"import": "./*.mjs"
|
|
32
|
-
}
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
33
35
|
}
|
|
34
36
|
}
|