UNPKG

@wundergraph/apollo-to-cosmo-metrics

Version:

An apollo gateway plugin that exports schema usage metrics to cosmo

33 lines 1.17 kB
import { createClient } from '@connectrpc/connect'; import { createConnectTransport } from '@connectrpc/connect-node'; import { GraphQLMetricsService } from '../generated/graphqlmetrics/v1/graphqlmetrics_connect.js'; export class CosmoClient { client; config; constructor(config) { this.config = config; this.client = createClient(GraphQLMetricsService, createConnectTransport({ baseUrl: config.endpointUrl, httpVersion: '1.1', })); } async reportMetrics(reports) { const aggregatedReports = { Aggregation: [...reports], }; // const numberOfReports = reports.length; // console.log( // {numberOfReports}, // 'Sending to cosmo batch of schema usage reports', // ); try { await this.client.publishAggregatedGraphQLMetrics(aggregatedReports, { headers: new Headers([['Authorization', `Bearer ${this.config.routerToken}`]]), }); } catch (e) { console.error('Error sending metrics to Cosmo', e); } } } //# sourceMappingURL=cosmo-client.js.map