Skip to content

Instantly share code, notes, and snippets.

@appwiz
Last active October 16, 2018 04:31
Show Gist options
  • Save appwiz/3cb5b2e6e4d518f85525fd6ab1a8ccf0 to your computer and use it in GitHub Desktop.
Save appwiz/3cb5b2e6e4d518f85525fd6ab1a8ccf0 to your computer and use it in GitHub Desktop.
Voice Commands - ReactApp - Add Subscriptions
// 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