API

subscriptionField


subscriptionField

Often times you want to split up subscription fields into different domains of your application.

Like queryField and mutationField except that like subscriptionType the subscribe field is required on the type configuration. Refer to subscriptionType docs for details

1import { subscriptionField } from '@nexus/schema'
2
3export const SubscriptionField = subscriptionField('truths', {
4 type: 'Boolean',
5 subscribe() {
6 return (async function*() {
7 while (true) {
8 await new Promise(res => setTimeout(res, 1000))
9 yield Math.random() > 0.5
10 }
11 })()
12 },
13 resolve(eventData) {
14 return eventData
15 },
16})
Edit this page on Github