Skip to content

Instantly share code, notes, and snippets.

@komkanit
Last active November 10, 2017 14:59
Show Gist options
  • Save komkanit/86b7da9f4ba858671541c9db888c5a34 to your computer and use it in GitHub Desktop.
Save komkanit/86b7da9f4ba858671541c9db888c5a34 to your computer and use it in GitHub Desktop.
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