{"library":"moleculer-apollo-server","title":"Apollo GraphQL Server for Moleculer","description":"moleculer-apollo-server provides an Apollo GraphQL server as a mixin for the Moleculer API Gateway, enabling easy integration of GraphQL endpoints within a Moleculer microservices architecture. It allows developers to define GraphQL queries and mutations directly within Moleculer service actions, automatically generating a unified GraphQL schema. The current stable version is 0.4.1, released recently with updates to Moleculer 0.15.0 and Apollo Server 5. This package differentiates itself by tightly coupling GraphQL schema definition with Moleculer actions, streamlining the process of exposing microservice capabilities via GraphQL. It also offers advanced features like inter-service resolvers and subscription support. The release cadence appears to be moderate, with significant breaking changes typically occurring with major Apollo Server version upgrades, as seen in the recent v0.4.0 release.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install moleculer-apollo-server"],"cli":null},"imports":["import { ApolloService } from 'moleculer-apollo-server';","import { GraphQLContext } from 'moleculer-apollo-server';","import { ApolloServiceOptions } from 'moleculer-apollo-server';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import ApiGateway from 'moleculer-web';\nimport { ApolloService } from 'moleculer-apollo-server';\n\n// Basic Greeter service to expose actions via GraphQL\nconst GreeterService = {\n    name: 'greeter',\n    actions: {\n        hello: {\n            graphql: {\n                query: 'hello: String'\n            },\n            handler(ctx) {\n                return 'Hello Moleculer!';\n            }\n        },\n        welcome: {\n            params: {\n                name: 'string'\n            },\n            graphql: {\n                mutation: 'welcome(name: String!): String'\n            },\n            handler(ctx) {\n                return `Hello ${ctx.params.name}`;\n            }\n        }\n    }\n};\n\n// API Gateway service with ApolloServer mixin\nexport default {\n    name: 'api',\n    mixins: [\n        ApiGateway,\n        ApolloService({\n            typeDefs: `\n                # Extend global types if needed, otherwise leave empty\n            `,\n            resolvers: {},\n            routeOptions: {\n                path: '/graphql',\n                cors: true,\n                mappingPolicy: 'restrict'\n            },\n            serverOptions: {\n                // Apollo Server 5 options go here\n                // E.g., include a basic plugin\n                plugins: [\n                    {\n                        async serverWillStart() {\n                            console.log('Apollo Server starting up...');\n                        }\n                    }\n                ]\n            }\n        })\n    ],\n    // Define settings for the API Gateway itself if necessary\n    settings: {\n        port: process.env.PORT ?? 3000,\n        host: process.env.HOST ?? '0.0.0.0'\n    },\n    // Add the greeter service to the broker in a real app or import it\n    created() {\n        this.broker.createService(GreeterService);\n    }\n};\n","lang":"typescript","description":"This example sets up a Moleculer API Gateway with `moleculer-apollo-server` to expose GraphQL endpoints, demonstrating basic query and mutation definitions from a Moleculer service.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}