@graphql-yoga/plugin-apollo-usage-report 0.5.8 → 0.5.9
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 +8 -2
- package/esm/index.js +8 -2
- package/package.json +2 -2
- package/typings/index.d.cts +1 -1
- package/typings/index.d.ts +1 -1
package/cjs/index.js
CHANGED
|
@@ -12,6 +12,7 @@ function getEnvVar(name, defaultValue) {
|
|
|
12
12
|
const DEFAULT_REPORTING_ENDPOINT = 'https://usage-reporting.api.apollographql.com/api/ingress/traces';
|
|
13
13
|
function useApolloUsageReport(options = {}) {
|
|
14
14
|
const [instrumentation, ctxForReq] = (0, plugin_apollo_inline_trace_1.useApolloInstrumentation)(options);
|
|
15
|
+
let schemaIdSet$;
|
|
15
16
|
let schemaId;
|
|
16
17
|
let yoga;
|
|
17
18
|
const logger = Object.fromEntries(['error', 'warn', 'info', 'debug'].map(level => [
|
|
@@ -41,11 +42,15 @@ function useApolloUsageReport(options = {}) {
|
|
|
41
42
|
},
|
|
42
43
|
onSchemaChange({ schema }) {
|
|
43
44
|
if (schema) {
|
|
44
|
-
hashSHA256((0, graphql_1.printSchema)(schema)).then(id => {
|
|
45
|
+
schemaIdSet$ = hashSHA256((0, graphql_1.printSchema)(schema), yoga.fetchAPI).then(id => {
|
|
45
46
|
schemaId = id;
|
|
47
|
+
schemaIdSet$ = undefined;
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
50
|
},
|
|
51
|
+
onRequestParse() {
|
|
52
|
+
return schemaIdSet$;
|
|
53
|
+
},
|
|
49
54
|
onParse() {
|
|
50
55
|
return function onParseEnd({ result, context }) {
|
|
51
56
|
const ctx = ctxForReq.get(context.request)?.traces.get(context);
|
|
@@ -78,7 +83,8 @@ function useApolloUsageReport(options = {}) {
|
|
|
78
83
|
const tracesPerSchema = {};
|
|
79
84
|
for (const trace of reqCtx.traces.values()) {
|
|
80
85
|
if (!trace.schemaId || !trace.operationKey) {
|
|
81
|
-
|
|
86
|
+
logger.debug('Misformed trace, missing operation key or schema id');
|
|
87
|
+
continue;
|
|
82
88
|
}
|
|
83
89
|
const clientName = clientNameFactory(request);
|
|
84
90
|
if (clientName) {
|
package/esm/index.js
CHANGED
|
@@ -8,6 +8,7 @@ function getEnvVar(name, defaultValue) {
|
|
|
8
8
|
const DEFAULT_REPORTING_ENDPOINT = 'https://usage-reporting.api.apollographql.com/api/ingress/traces';
|
|
9
9
|
export function useApolloUsageReport(options = {}) {
|
|
10
10
|
const [instrumentation, ctxForReq] = useApolloInstrumentation(options);
|
|
11
|
+
let schemaIdSet$;
|
|
11
12
|
let schemaId;
|
|
12
13
|
let yoga;
|
|
13
14
|
const logger = Object.fromEntries(['error', 'warn', 'info', 'debug'].map(level => [
|
|
@@ -37,11 +38,15 @@ export function useApolloUsageReport(options = {}) {
|
|
|
37
38
|
},
|
|
38
39
|
onSchemaChange({ schema }) {
|
|
39
40
|
if (schema) {
|
|
40
|
-
hashSHA256(printSchema(schema)).then(id => {
|
|
41
|
+
schemaIdSet$ = hashSHA256(printSchema(schema), yoga.fetchAPI).then(id => {
|
|
41
42
|
schemaId = id;
|
|
43
|
+
schemaIdSet$ = undefined;
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
46
|
},
|
|
47
|
+
onRequestParse() {
|
|
48
|
+
return schemaIdSet$;
|
|
49
|
+
},
|
|
45
50
|
onParse() {
|
|
46
51
|
return function onParseEnd({ result, context }) {
|
|
47
52
|
const ctx = ctxForReq.get(context.request)?.traces.get(context);
|
|
@@ -74,7 +79,8 @@ export function useApolloUsageReport(options = {}) {
|
|
|
74
79
|
const tracesPerSchema = {};
|
|
75
80
|
for (const trace of reqCtx.traces.values()) {
|
|
76
81
|
if (!trace.schemaId || !trace.operationKey) {
|
|
77
|
-
|
|
82
|
+
logger.debug('Misformed trace, missing operation key or schema id');
|
|
83
|
+
continue;
|
|
78
84
|
}
|
|
79
85
|
const clientName = clientNameFactory(request);
|
|
80
86
|
if (clientName) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-yoga/plugin-apollo-usage-report",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
4
4
|
"description": "Apollo's GraphOS usage report plugin for GraphQL Yoga.",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^15.2.0 || ^16.0.0",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@apollo/usage-reporting-protobuf": "^4.1.1",
|
|
11
11
|
"tslib": "^2.8.1",
|
|
12
|
-
"@graphql-yoga/plugin-apollo-inline-trace": "^3.10.
|
|
12
|
+
"@graphql-yoga/plugin-apollo-inline-trace": "^3.10.12"
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
package/typings/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Maybe, Plugin, YogaInitialContext } from 'graphql-yoga';
|
|
1
|
+
import { type Maybe, type Plugin, type YogaInitialContext } from 'graphql-yoga';
|
|
2
2
|
import { ApolloInlineGraphqlTraceContext, ApolloInlineRequestTraceContext, ApolloInlineTracePluginOptions } from '@graphql-yoga/plugin-apollo-inline-trace';
|
|
3
3
|
type ApolloUsageReportOptions = ApolloInlineTracePluginOptions & {
|
|
4
4
|
/**
|
package/typings/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Maybe, Plugin, YogaInitialContext } from 'graphql-yoga';
|
|
1
|
+
import { type Maybe, type Plugin, type YogaInitialContext } from 'graphql-yoga';
|
|
2
2
|
import { ApolloInlineGraphqlTraceContext, ApolloInlineRequestTraceContext, ApolloInlineTracePluginOptions } from '@graphql-yoga/plugin-apollo-inline-trace';
|
|
3
3
|
type ApolloUsageReportOptions = ApolloInlineTracePluginOptions & {
|
|
4
4
|
/**
|