Last active
December 30, 2018 20:15
-
-
Save JeffML/eac88bbf969e3c42b4e1776f9a957a56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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