Send push notifications with Pusher in your Graphcool project 🎁
graphcool add-template messaging/pusher
The add-template
command is performing three major steps:
- Download the source files from the
src
directory and put them into your service'ssrc
directory (into a subdirectory calledpusher
). - Download the contents from
graphcool.yml
and append them as comments to your service'sgraphcool.yml
. - Download the contents from
types.graphql
and append them as comments to your service'stypes.graphql
.
In order for the changes to take effect, you need to manually uncomment all the lines that have been added by the add-template
command.
You need to configure these credentials as environment variables:
PUSHER_APP_ID
PUSHER_KEY
PUSHER_SECRET
PUSHER_CLUSTER
You can receive them after signing up at Pusher.
To manage your environment variables, you can use a tool like direnv.
Finally, you need to install the node dependencies and apply all the changes you just made by deploying the service:
npm install
graphcool deploy
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 {
pushNotification(
channels: ["my-channel"]
event: "my-event"
message: "Hello from the Graphcool pusher module!"
) {
success
}
}