Created
September 24, 2017 18:16
-
-
Save Cerberus/c3fab759b681d14c41bea53f70791d10 to your computer and use it in GitHub Desktop.
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
const hasSubscriptionOperation = ({ query: { definitions } }) => | |
definitions.some( | |
({ kind, operation }) => | |
kind === 'OperationDefinition' && operation === 'subscription', | |
) | |
const link = ApolloLink.split( | |
hasSubscriptionOperation, | |
new WebSocketLink({ | |
uri: | |
'wss://hostname/__path__', | |
options: { reconnect: true }, | |
}), | |
new Link({ | |
uri: 'https://hostname/__path__', | |
}), | |
) | |
const client = new ApolloClient({ | |
link, | |
cache: new Cache(window.__APOLLO_STATE__), | |
}) | |
ReactDOM.render( | |
<ApolloProvider client={client}> | |
<App /> | |
</ApolloProvider>, | |
document.getElementById('root'), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello I would like to use this pattern, so subscriptions go to websockets, but I also need to pass a header with my request .. could you help me make this .. work with .split(..)
edit: Oh, I figured it out :)