Created
May 18, 2017 23:51
-
-
Save rcy/c205c1a14d19da3356860375f25c48d8 to your computer and use it in GitHub Desktop.
apollo client setup for meteor
This file contains 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 { createMeteorNetworkInterface, meteorClientConfig } from 'meteor/apollo'; | |
import { ApolloClient } from 'react-apollo'; | |
import { SubscriptionClient, addGraphQLSubscriptions } from 'subscriptions-transport-ws'; | |
const wsClient = new SubscriptionClient('ws://localhost:5000/', { | |
reconnect: true, | |
}); | |
// Create a normal network interface: | |
const networkInterface = createMeteorNetworkInterface(); | |
// Extend the network interface with the WebSocket | |
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions( | |
networkInterface, | |
wsClient | |
); | |
// Finally, create your ApolloClient instance with the modified network interface | |
export const apolloClient = new ApolloClient(meteorClientConfig({ | |
networkInterface: networkInterfaceWithSubscriptions, | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment