Apollo GraphQL subscriptions over Kafka using kafkajs. Version 4.0.10. Provides a KafkaPubSub class that implements the PubSubEngine interface, allowing GraphQL subscriptions to be backed by Kafka topics. Unlike alternatives like graphql-kafka-subscriptions, this library uses kafkajs (modern Kafka client) and supports per-instance consumer group IDs with prefix or fixed group options. Ships TypeScript types. Requires kafkajs as a peer dependency. Released under MIT license.
npm install graphql-kafkajs-subscriptionsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a KafkaPubSub instance with Kafka connection and uses it to subscribe and publish GraphQL subscription events.
Use consumerConfig.groupId with a fixed group ID for production deployments: KafkaPubSub.create({ consumerConfig: { groupId: 'my-group' } })Switch to consumerConfig.groupId for a fixed group ID.
Ensure each instance has its own consumer group ID when using groupIdPrefix, or share group ID for load balancing.
Pass { value: myData } or similar structure to match the expected KafkaMessage interface.Always supply one of the two options.
When upgrading, if you relied on a fixed group ID, pass consumerConfig.groupId explicitly.
Add groupIdPrefix or consumerConfig.groupId to the create options: KafkaPubSub.create({ topic: '...', kafka: ..., groupIdPrefix: 'prefix' })Make sure you import { KafkaPubSub } from 'graphql-kafkajs-subscriptions' and not default import.Check KAFKA_BROKER env var and ensure Kafka is running. Verify SSL/SASL settings.
Create the topic manually or use Kafka auto-creation if enabled.