This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm test- Run Jest tests with coveragenpm run ci- Run tests in watch mode for developmentnpm run lint- Run ESLint on src and test directoriesnpm run lint:fix- Auto-fix ESLint issuesnpm run dev- Run development server with examples/index.js (simple example)npm run dev full- Run development server with examples/full/index.js (full example)npm run deps- Update dependencies interactively using ncunpm run postdeps- Automatically run tests after dependency updates
This is a Moleculer mixin that integrates Apollo GraphQL Server 5 with Moleculer API Gateway. The core architecture consists of:
- src/service.js - Main service mixin factory that returns a Moleculer service schema
- src/ApolloServer.js - Custom ApolloServer class extending @apollo/server
- src/gql.js - GraphQL template literal formatter utility
- index.js - Main module exports
Service Mixin Pattern: The library exports a factory function ApolloService(options) that returns a Moleculer service schema to be mixed into API Gateway services.
Auto-Schema Generation: GraphQL schemas are dynamically generated from:
- Service action definitions with
graphqlproperty containingquery,mutation, orsubscriptionfields - Service-level GraphQL definitions in
settings.graphql - Global typeDefs and resolvers passed to the mixin
Action-to-Resolver Mapping: Moleculer actions automatically become GraphQL resolvers when they include GraphQL definitions. The system creates resolver functions that call ctx.call(actionName, params).
DataLoader Integration: Built-in DataLoader support for batch loading with automatic key mapping and caching via resolver configuration.
WebSocket Subscriptions: GraphQL subscriptions are handled through WebSocket connections with PubSub pattern integration.
- test/unit/ - Unit tests for individual components
- test/integration/ - Integration tests with full service setup
- Jest snapshots for schema generation testing
- examples/simple/ - Basic setup demonstration
- examples/full/ - Complete setup with multiple services, DataLoader, and complex resolvers
Schema Regeneration: The GraphQL schema is automatically regenerated when services change ($services.changed event) unless autoUpdateSchema: false.
TypeScript Support: Full TypeScript definitions in index.d.ts with comprehensive interfaces for all configuration options.
Node.js Version: Requires Node.js >= 20.x.x (specified in package.json engines).