Skip to content

Instantly share code, notes, and snippets.

@gc-codesnippets
Created August 25, 2017 15:46
Show Gist options
  • Select an option

  • Save gc-codesnippets/cd0a07a710188a662d51d5d1ddee34f0 to your computer and use it in GitHub Desktop.

Select an option

Save gc-codesnippets/cd0a07a710188a662d51d5d1ddee34f0 to your computer and use it in GitHub Desktop.
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