Monday, 8 May 2017

importing other modules in GraphQL modules returns undefined

In my GraphQL server to I have a file that exports 2 modules.

const PubSub = require('graphql-subscriptions');
const SubscriptionManager = require('graphql-subscriptions');
const schema = require('./rootQuery');
const pubsubs = new PubSub.PubSub();
const subscriptionManagers = new SubscriptionManager.SubscriptionManager({
  schema,
  pubsubs,
  setupFunctions: {
    postAdded: (options, args) => ({
      postAdded: post => console.log("setting post")
    })
  }
})

module.exports = {
  pubsub: pubsubs,
  subscriptionManager: subscriptionManagers
}

and Im requiring pubsub in my mutation.js

const pubsub = require('./subsManager').pubsub;
console.log(pubsub)

When I console.log pubsub it returns undefined. However, when I require pubsub in my index.js file, it works fine.



via Saud Punjwani

No comments:

Post a Comment