Send push notifications with Pusher in your Graphcool project 🎁
npm -g install graphcool
graphcool init
graphcool modules add graphcool/modules/messaging/pusher
In your base project, you need to configure the following environment variables.
PUSHER_APP_ID
: Pusher app idPUSHER_KEY
: Pusher keyPUSHER_SECRET
: Pusher secretPUSHER_CLUSTER
: Pusher cluster
You can receive them after signing up at Pusher.
An easy way to setup environment variables is using direnv.
To use direnv
, put the following into .envrc
in you project root:
export PUSHER_APP_ID=xxx
export PUSHER_KEY=xxx
export PUSHER_SECRET=xxx
export PUSHER_CLUSTER=xxx
Whenever the triggerPusherEvent
mutation is called, a new push notification event will be sent to the specified channels.
First, setup the Pusher configuration in notification.html
. Please replace the following constants with the same value you used for the environment variables above:
APP_KEY
: Pusher app keyCLUSTER
: Pusher cluster
Then, serve the file notification.html
, for example with:
python -m SimpleHTTPServer
and open it in your browser.
Open the playground:
graphcool playground
and run this mutation to push a notification to your browser:
mutation {
triggerPusherEvent(
channels: ["my-channel"]
event: "my-event"
message: "Hello from the Graphcool pusher module!"
) {
success
}
}