Created
August 25, 2017 15:46
-
-
Save gc-codesnippets/cd0a07a710188a662d51d5d1ddee34f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ApolloClient, { createNetworkInterface } from 'apollo-client' | |
| import {SubscriptionClient, addGraphQLSubscriptions} from 'subscriptions-transport-ws' | |
| import { ApolloProvider } from 'react-apollo' | |
| // Create WebSocket client | |
| const wsClient = new SubscriptionClient(`wss://subscriptions.graph.cool/v1/__PROJECT ID__`, { | |
| reconnect: true, | |
| connectionParams: { | |
| // Pass any arguments you want for initialization | |
| } | |
| }) | |
| const networkInterface = createNetworkInterface({ uri: 'https://api.graph.cool/simple/v1/__PROJECT ID__' }) | |
| // Extend the network interface with the WebSocket | |
| const networkInterfaceWithSubscriptions = addGraphQLSubscriptions( | |
| networkInterface, | |
| wsClient | |
| ) | |
| const client = new ApolloClient({ | |
| networkInterface: networkInterfaceWithSubscriptions, | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment