Apollo network interface for communication with Phoenix (using Absinthe) over websockets.
Currently supports request/response queries and mutations over socket in both browser and server. Subscriptions coming soon.
import { createPhoenixWebSocketNetworkInterface } from 'phoenix-websocket-network-interface'
import ApolloClient from 'apollo-client'
let options = {
uri: 'ws://localhost:4000/socket',
params: { token: 'ABCDEF123456' }
logger: true
}
const networkInterface = createPhoenixWebSocketNetworkInterface(options)
const client = new ApolloClient({ networkInterface })
Options have similar parity to Apollo's default network interface where applicable. Hopefully, the additional options are intuitive.
Socket endpoint declared in your Phoenix app.
Example: ws://localhost:4000/socket
Parameters to be sent to your socket connection. See Phoenix.js hexdocs. One example would be to pass a JWT, which can be used by Guardian to verify permissions to connect.
If true, node-based w3cwebsocket transport will be used to prevent window
errors while running on a server. You can override the transport with the transport
option.
The Websocket Transport, for example WebSocket or Phoenix.LongPoll.
Defaults to WebSocket with automatic LongPoll fallback in the browser, and w3cwebsocket when ssr:true
Log socket and channel info to console. If options.logger
function is not set, default is used.
Logging function. Default:
(kind, msg, data) => console.log(`phoenix apollo \n\t ${kind}: ${msg}`, data)