absinthe-phoenix
JavaScript support for Absinthe GraphQL subscriptions over Phoenix channels.
Examples
The following examples configure a client that connects to a Phoenix socket at
"ws://localhost:4000/socket"
, sends a subscription to Absinthe operating there,
and registers a callback to be invoked every time a result is broadcast for that
subscription.
ES6 Example
From, for example, a React project:
// Import the client class; // Instantiate the client, giving a ws:// or wss:// URL to the Phoenix socketconst client = "ws://localhost:4000/socket"; // Connect to the socket and Absinthe channelclient // Yay, you've connected. // Do something when you can't connect to the socket/channel ;
To unsubscribe:
client ;
Browser Example
If you're using absinthe-phoenix as standalone, embedded dependency (eg, in your own GraphiQL), you can use unpkg, eg:
Note you may want to use a specific version of absinthe-phoenix
from unpkg,
eg, //unpkg.com/absinthe-phoenix@0.1.0
.
Contributing
The code is written in TypeScript (as are many GraphQL projects in the JS ecosystem). We'd happily accept help refactoring, documenting, and expanding the code from more experienced TypeScript developers!
License
See LICENSE.md.