-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (42 loc) · 1.38 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import AppRouter from './AppRouter';
import registerServiceWorker from './registerServiceWorker';
import { ApolloProvider } from 'react-apollo';
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { WebSocketLink } from 'apollo-link-ws';
import { getMainDefinition } from 'apollo-utilities';
import { split } from 'apollo-link';
// Set up subscription
const wsLink = new WebSocketLink({
uri: `wss://subscriptions.graph.cool/v1/cjitgitwv1vgm01892qi3gzez`,
options: {
reconnect: true
},
});
const httpLink = new HttpLink( { uri:'https://api.graph.cool/simple/v1/cjitgitwv1vgm01892qi3gzez' });
// Splits the requests based on the query type -
// E.g. subscriptions go to wsLink and everything else to httpLink
const link = split(
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' &&
operation === 'subscription';
},
wsLink,
httpLink,
);
const client = new ApolloClient({
link,
cache: new InMemoryCache(),
});
const withApolloProvider = Comp => (
<ApolloProvider client={client}>{Comp}</ApolloProvider>
);
ReactDOM.render(
withApolloProvider(<AppRouter />),
document.getElementById('root'));
registerServiceWorker();