Skip to content

Commit

Permalink
add createPubSub method
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Aug 30, 2020
1 parent c463180 commit 491c7e6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const GraphQL = require("graphql");
const { PubSub, withFilter } = require("graphql-subscriptions");
const hash = require("object-hash");

module.exports = function (mixinOptions) {
module.exports = function(mixinOptions) {
mixinOptions = _.defaultsDeep(mixinOptions, {
routeOptions: {
path: "/graphql",
Expand Down Expand Up @@ -594,6 +594,16 @@ module.exports = function (mixinOptions) {
return makeExecutableSchema(schemaDef);
},

/**
* Create PubSub instance.
*/
createPubSub() {
return new PubSub();
},

/**
* Prepare GraphQL schemas based on Moleculer services.
*/
prepareGraphQLSchema() {
// Schema is up-to-date
if (!this.shouldUpdateGraphqlSchema && this.graphqlHandler) {
Expand All @@ -606,7 +616,7 @@ module.exports = function (mixinOptions) {
);

try {
this.pubsub = new PubSub();
this.pubsub = this.createPubSub();
const services = this.broker.registry.getServiceList({ withActions: true });
const schema = this.generateGraphQLSchema(services);

Expand Down

0 comments on commit 491c7e6

Please sign in to comment.