Search code examples
node.jsgraphqlapolloapollo-server

PubSub is not a constructor apollo server


I am creating a subscription in apollo server. When I try to create a new instance of PubSub. I get an error PubSub is not a constructor.

const {PubSub} = require("apollo-server")
const pubsub =  new PubSub()

Solution

  • I was able to resolve the issue by installing graphql-subscriptions, then requiring in PubSub from the later like this:

    const {PubSub} = require("graphql-subscriptions")