UNPKG

@graphql-yoga/nestjs-federation

Version:

GraphQL Yoga driver with Apollo Federation for NestJS GraphQL.

79 lines (77 loc) 2.98 kB
const require_decorate = require('./_virtual/_@oxc-project_runtime@0.110.0/helpers/decorate.cjs'); let graphql = require("graphql"); let _apollo_gateway = require("@apollo/gateway"); let _apollo_subgraph = require("@apollo/subgraph"); let _envelop_apollo_federation = require("@envelop/apollo-federation"); let _graphql_yoga_nestjs = require("@graphql-yoga/nestjs"); let _graphql_yoga_plugin_apollo_inline_trace = require("@graphql-yoga/plugin-apollo-inline-trace"); let _nestjs_common = require("@nestjs/common"); let _nestjs_graphql = require("@nestjs/graphql"); //#region src/index.ts let YogaFederationDriver = class YogaFederationDriver extends _graphql_yoga_nestjs.AbstractYogaDriver { subscriptionService; constructor(graphqlFederationFactory) { super(); this.graphqlFederationFactory = graphqlFederationFactory; } async generateSchema(options) { return await this.graphqlFederationFactory.generateSchema(options); } async start(options) { if (options.definitions?.path) { if (!options.schema) throw new Error("Schema is required when providing definitions path"); await this.graphQlFactory.generateDefinitions((0, _apollo_subgraph.printSubgraphSchema)(options.schema), options); } await super.start({ ...options, plugins: [...options?.plugins || [], (0, _graphql_yoga_plugin_apollo_inline_trace.useApolloInlineTrace)()] }); if (options.subscriptions && options.schema) { const config = options.subscriptions === true ? { "graphql-ws": true } : options.subscriptions; this.subscriptionService = new _nestjs_graphql.GqlSubscriptionService({ schema: options.schema, path: options.path, context: options.context, ...config }, this.httpAdapterHost.httpAdapter?.getHttpServer()); } } async stop() { await this.subscriptionService?.stop(); } }; YogaFederationDriver = require_decorate.__decorate([(0, _nestjs_common.Injectable)()], YogaFederationDriver); let YogaGatewayDriver = class YogaGatewayDriver extends _graphql_yoga_nestjs.AbstractYogaDriver { async generateSchema(_options) { return new graphql.GraphQLSchema({}); } async start(options) { const { server: serverOpts = {}, gateway: gatewayOpts = {} } = options; const gateway = new _apollo_gateway.ApolloGateway(gatewayOpts); await gateway.load(); await super.start({ ...serverOpts, plugins: [...serverOpts.plugins || [], (0, _envelop_apollo_federation.useApolloFederation)({ gateway })] }); } async mergeDefaultOptions(options) { return { ...options, server: await super.mergeDefaultOptions(options?.["server"] ?? {}) }; } }; YogaGatewayDriver = require_decorate.__decorate([(0, _nestjs_common.Injectable)()], YogaGatewayDriver); //#endregion Object.defineProperty(exports, 'YogaFederationDriver', { enumerable: true, get: function () { return YogaFederationDriver; } }); Object.defineProperty(exports, 'YogaGatewayDriver', { enumerable: true, get: function () { return YogaGatewayDriver; } });