How to use the graphql-subscriptions.PubSub function in graphql-subscriptions

To help you get started, we’ve selected a few graphql-subscriptions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aerogear / graphback / examples / generator-fullstack / server / src / index.ts View on Github external
});

  const generateConfig = await config!.getDefault().extension('generate');

  // connect to db
  const db = await connect(generateConfig.db.dbConfig);

  const schema = makeExecutableSchema({
    typeDefs,
    resolvers,
    resolverValidationOptions: {
      requireResolversForResolveType: false
    }
  });

  const pubSub = new PubSub();
  const context = createKnexRuntimeContext(db, pubSub);
  const apolloConfig = {
    schema,
    context
  }

  const apolloServer = new ApolloServer(apolloConfig)

  apolloServer.applyMiddleware({ app })

  const httpServer = http.createServer(app)
  apolloServer.installSubscriptionHandlers(httpServer)

  httpServer.listen({ port: 4000 }, () => {
    // tslint:disable-next-line: no-console
    console.log(`🚀  Server ready at http://localhost:4000/graphql`)
github chnirt / nestjs-graphql-best-practice / src / config / graphql / index.ts View on Github external
END_POINT,
	FE_URL,
	GRAPHQL_DEPTH_LIMIT,
	ACCESS_TOKEN
} from '@environments'

// const gateway = new ApolloGateway({
// 	serviceList: [
// 		{ name: 'accounts', url: 'http://localhost:11041/graphql' },
// 		{ name: 'reviews', url: 'http://localhost:11042/graphql' },
// 		{ name: 'products', url: 'http://localhost:11043/graphql' },
// 		{ name: 'inventory', url: 'http://localhost:11044/graphql' }
// 	]
// })

const pubsub = new PubSub()
class MyErrorTrackingExtension extends GraphQLExtension {
	willSendResponse(o) {
		const { context, graphqlResponse } = o

		context.trackErrors(graphqlResponse.errors)

		return o
	}
	// Other lifecycle methods include
	// requestDidStart
	// parsingDidStart
	// validationDidStart
	// executionDidStart
	// willSendResponse
}
github renanmav / relayable / packages / server / src / modules / question / mutation / __tests__ / CreateQuestion.spec.ts View on Github external
it('should create a question when authenticated', async () => {
  const user = await createRows.createUser()
  const pubSub = new PubSub()
  const context = getContext({ user, pubSub })
  const variables = {
    content: 'What does the fox say?',
  }

  const result = await graphql(schema, query, rootValue, context, variables)
  expect(result).toMatchSnapshot()
})
github Innovic-io / apollo-graphql-pintrest-clone / src / graphql / subscription / subscription.resolver.ts View on Github external
import { PubSub } from 'graphql-subscriptions';
import { socket } from '../../server';

export const pubsub = new PubSub();

export const USER_CHANGED_TOPIC = 'user_change';
export const PIN_CHANGED_TOPIC = 'pin_change';

pubsub.subscribe(USER_CHANGED_TOPIC, (message) => socket.emit(USER_CHANGED_TOPIC, message));
pubsub.subscribe(PIN_CHANGED_TOPIC, (message) => socket.emit(PIN_CHANGED_TOPIC, message));
github graphql-zeroconf / zeroconf / dist / classes / ZeroConf.js View on Github external
this.setContext(config.context);
      delete config.context;
    }

    if (config.allows) {
      _acl["default"].allow(config.allows);

      this.acl = _acl["default"];
    }

    for (var _i = 0, _Object$keys = Object.keys(config); _i < _Object$keys.length; _i++) {
      var key = _Object$keys[_i];
      this[key] = config[key];
    }

    this.pubSub = new _graphqlSubscriptions.PubSub();

    if (config.withApollo !== true) {
      (0, _composer.createScalarType)("Upload");
      (0, _composer.addResolver)("Upload", _UploadType["default"]);
    }
  }
github MainframeHQ / onyx / app / server / data / pubsub.js View on Github external
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _graphqlSubscriptions = require('graphql-subscriptions');

exports.default = new _graphqlSubscriptions.PubSub();
github tomyitav / graphql-server-typed / src / graphql / subscriptions / Pubsub / PubsubInstance.ts View on Github external
import { PubSub } from 'graphql-subscriptions';

export const pubsub = new PubSub();
github Chabane / bigdata-playground / webapp / server / src / schema / resolvers / resolvers.ts View on Github external
import { IFlightInfo } from '../../db';
import { KafkaFlightInfoProducer } from '../../kafka';
import { Airport } from '../../db/models/airport';
import { PubSub, withFilter } from 'graphql-subscriptions';

const producer = new KafkaFlightInfoProducer();
export const pubsub = new PubSub();

export const resolvers = {
  Query: {
    fetchAirports: async (_, { airportToSearch, airportId }) => {
      const airports = await Airport.findAirports(airportToSearch, airportId);
      return airports;
    }
  },
  Mutation: {
    sendFlightInfo: async (_, { flightInfo }) => {
      producer.sendFlightInfo(flightInfo as IFlightInfo);
      return flightInfo;
    }
  },
  Subscription: {
    getTweets: {
github fischermatte / geolud / geolud-server-node / src / contact / contact.resolver.ts View on Github external
import { Inject } from '@nestjs/common';
import { MailService } from '../mail/mail.service';
import { Args, Mutation, Resolver, Subscription } from '@nestjs/graphql';
import { PubSub } from 'graphql-subscriptions';
import { Delivery } from './contact.model';

const pubSub = new PubSub();

@Resolver('Contact')
export class ContactResolvers {
  constructor(@Inject('MailService') private mailService: MailService) {}

  @Mutation('submitContactRequest')
  submitContactRequest(@Args('name') name: string, @Args('email') email: string, @Args('message') message: string): Delivery {
    this.mailService.sendEmail(name, email, 'GEOLUD-SITE: Contact Request', message);
    pubSub.publish('contactRequestSubmitted', { contactRequestSubmitted: 'contact request sent' });
    return {
      sentAt: new Date(),
    };
  }

  @Subscription('contactRequestSubmitted')
  contactRequestSubmitted() {

graphql-subscriptions

GraphQL subscriptions for node.js

MIT
Latest version published 3 years ago

Package Health Score

64 / 100
Full package analysis