Skip to content

Instantly share code, notes, and snippets.

@JeffML
Last active December 30, 2018 20:15
Show Gist options
  • Save JeffML/eac88bbf969e3c42b4e1776f9a957a56 to your computer and use it in GitHub Desktop.
Save JeffML/eac88bbf969e3c42b4e1776f9a957a56 to your computer and use it in GitHub Desktop.
import { PubSub } from 'apollo-server-express';
const pubsub = new PubSub();
const TOPIC = 'infoTopic';
const infos = ['info1', 'info2', 'info3', 'done']
const publish = () => {
setTimeout( () =>
infos.forEach(info => pubsub.publish(TOPIC, {info})), 1000)
}
export default {
Query: {
go: () => { publish(); return 'going'}
},
Subscription: {
info: {
subscribe: () => pubsub.asyncIterator([TOPIC]),
},
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment