UNPKG

@graphql-mesh/serve-runtime

Version:
52 lines (51 loc) 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getReportingPlugin = getReportingPlugin; const tslib_1 = require("tslib"); const plugin_hive_1 = tslib_1.__importDefault(require("@graphql-mesh/plugin-hive")); const plugin_apollo_usage_report_1 = require("@graphql-yoga/plugin-apollo-usage-report"); function getReportingPlugin(config, configContext) { if (config.reporting?.type === 'hive') { return { name: 'Hive', plugin: (0, plugin_hive_1.default)({ ...configContext, logger: configContext.logger.child('Hive'), ...config.reporting, experimental__persistedDocuments: config.persistedDocuments && 'type' in config.persistedDocuments && config.persistedDocuments?.type === 'hive' ? { cdn: { endpoint: config.persistedDocuments.endpoint, accessToken: config.persistedDocuments.token, }, allowArbitraryDocuments: config.persistedDocuments.allowArbitraryDocuments, } : undefined, }), }; } else if (config.reporting?.type === 'graphos' || (!config.reporting && 'supergraph' in config && typeof config.supergraph === 'object' && 'type' in config.supergraph && config.supergraph.type === 'graphos')) { if ('supergraph' in config && typeof config.supergraph === 'object' && 'type' in config.supergraph && config.supergraph.type === 'graphos') { config.reporting.apiKey ||= config.supergraph.apiKey; config.reporting.graphRef ||= config.supergraph.graphRef; } return { name: 'GraphOS', // @ts-expect-error - TODO: Fix types plugin: (0, plugin_apollo_usage_report_1.useApolloUsageReport)(config.reporting), }; } return { plugin: {}, }; }