Last active
October 16, 2018 04:31
-
-
Save appwiz/3cb5b2e6e4d518f85525fd6ab1a8ccf0 to your computer and use it in GitHub Desktop.
Voice Commands - ReactApp - Add Subscriptions
This file contains 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
// Add the subscription query | |
const OnCreateColorCommandSubscription = ` | |
subscription onCreateColorCommand { | |
onCreateColorCommand { | |
__typename | |
id | |
color | |
timestamp | |
} | |
} | |
`; | |
// Add subscription support to the Connect component | |
<Connect query={graphqlOperation(ListColorCommands)} | |
subscription={graphqlOperation(OnCreateColorCommandSubscription)} | |
onSubscriptionMsg={(prev, { onCreateColorCommand }) => | |
{ | |
const { listColorCommands: { items } } = prev; | |
items.push(onCreateColorCommand); | |
return prev; | |
} | |
} | |
> | |
{({ data: { listColorCommands } }) => ( | |
listColorCommands && <ListView commands={listColorCommands.items} /> | |
) | |
} | |
</Connect> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment