2021-08-07 19:56:39 +07:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2021-08-08 19:08:10 +07:00
|
|
|
import './index.less';
|
2021-08-07 19:56:39 +07:00
|
|
|
import App from './App';
|
|
|
|
import reportWebVitals from './reportWebVitals';
|
|
|
|
|
|
|
|
import {split, HttpLink, ApolloClient, InMemoryCache} from '@apollo/client';
|
|
|
|
import {ApolloProvider} from '@apollo/client/react';
|
|
|
|
import {getMainDefinition} from '@apollo/client/utilities';
|
|
|
|
import {WebSocketLink} from '@apollo/client/link/ws';
|
|
|
|
|
|
|
|
const APP_HOST = process.env.APP_HOST || 'localhost:8081'
|
|
|
|
|
|
|
|
const httpLink = new HttpLink({
|
|
|
|
uri: `http://${APP_HOST}/graphql`
|
|
|
|
});
|
|
|
|
|
|
|
|
const wsLink = new WebSocketLink({
|
|
|
|
uri: `ws://${APP_HOST}/subscriptions`,
|
|
|
|
options: {
|
|
|
|
reconnect: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const splitLink = split(
|
|
|
|
({query}) => {
|
|
|
|
const definition = getMainDefinition(query);
|
|
|
|
return (
|
|
|
|
definition.kind === 'OperationDefinition' &&
|
|
|
|
definition.operation === 'subscription'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
wsLink,
|
|
|
|
httpLink,
|
|
|
|
);
|
|
|
|
|
|
|
|
const client = new ApolloClient({
|
|
|
|
link: splitLink,
|
|
|
|
cache: new InMemoryCache()
|
|
|
|
});
|
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
<React.StrictMode>
|
|
|
|
<ApolloProvider client={client}>
|
|
|
|
<App/>
|
|
|
|
</ApolloProvider>
|
|
|
|
</React.StrictMode>,
|
|
|
|
document.getElementById('root')
|
|
|
|
);
|
|
|
|
|
|
|
|
// If you want to start measuring performance in your app, pass a function
|
|
|
|
// to log results (for example: reportWebVitals(console.log))
|
|
|
|
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
|
|
|
reportWebVitals();
|