Last active
November 10, 2017 14:59
-
-
Save komkanit/86b7da9f4ba858671541c9db888c5a34 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 from 'apollo-client'; | |
import { getOperationAST } from 'graphql'; | |
import { ApolloLink } from 'apollo-link'; | |
import { HttpLink } from 'apollo-link-http'; | |
import { WebSocketLink } from 'apollo-link-ws'; | |
import { InMemoryCache } from 'apollo-cache-inmemory'; | |
const httpLink = new HttpLink({ | |
uri: 'http://localhost:8080/graphql', | |
}); | |
const wsLink = new WebSocketLink({ | |
uri: 'ws://localhost:8080/subscriptions', | |
options: { | |
reconnect: true, | |
}, | |
}); | |
const link = ApolloLink.split( | |
(operation) => { | |
const operationAST = getOperationAST(operation.query, operation.operationName); | |
return !!operationAST && operationAST.operation === 'subscription'; | |
}, | |
wsLink, | |
httpLink, | |
); | |
new ApolloClient({ | |
link, | |
cache: new InMemoryCache(), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment