Advertisement
Guest User

Untitled

a guest
Aug 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. import { Vuetify } from 'vuetify';
  2.  
  3. import { ApolloClient } from 'apollo-client';
  4. import { InMemoryCache } from 'apollo-cache-inmemory';
  5. import { SubscriptionClient } from 'subscriptions-transport-ws';
  6. import { WebSocketLink } from 'apollo-link-ws';
  7. import { HttpLink } from 'apollo-link-http';
  8. import { split } from 'apollo-link';
  9. import { getMainDefinition } from 'apollo-utilities';
  10.  
  11. import VueApollo from 'vue-apollo';
  12.  
  13. import Vue from 'vue';
  14.  
  15. import App from './modules/app/App';
  16. import router from './router';
  17.  
  18. import './shared/stylus/main.styl';
  19.  
  20. import { i18n } from './i18n/';
  21.  
  22. import { CAPITALIZE, ABBREVIATE, UPPERCASE } from './shared/filters';
  23.  
  24. import { VUETIFY_COMPONENTS, VUETIFY_STYLE } from './config/vuetify-config';
  25.  
  26. Vue.use(Vuetify, {
  27. components: VUETIFY_COMPONENTS,
  28. theme: VUETIFY_STYLE,
  29. });
  30.  
  31. Vue.config.productionTip = false;
  32.  
  33. // Filter Definitions
  34. Vue.filter(CAPITALIZE.name, CAPITALIZE.handler);
  35. Vue.filter(ABBREVIATE.name, ABBREVIATE.handler);
  36. Vue.filter(UPPERCASE.name, UPPERCASE.handler);
  37.  
  38. const GRAPHQL_ENDPOINT = document.domain === 'chatsphere.de' ?
  39. 'wss://api.chatsphere.de/graphql' : 'ws://localhost:3000/graphql';
  40.  
  41. const client = new SubscriptionClient(GRAPHQL_ENDPOINT, {
  42. reconnect: true,
  43. }, WebSocket);
  44.  
  45. let link = new WebSocketLink(client);
  46.  
  47. // Hard coded: Be able to use HTTP for local testing purposes
  48. if (document.domain !== 'chatsphere.de') {
  49. const httpLink = new HttpLink({
  50. uri: 'http://localhost:3000/graphql',
  51. });
  52.  
  53. link = split(
  54. ({ query }) => {
  55. const { kind, operation } = getMainDefinition(query);
  56. return kind === 'OperationDefinition' && operation === 'subscription';
  57. },
  58. link,
  59. httpLink,
  60. );
  61. }
  62.  
  63.  
  64. // Create the apollo client
  65. const apolloClient = new ApolloClient({
  66. link,
  67. cache: new InMemoryCache(),
  68. connectToDevTools: true,
  69. });
  70.  
  71. const apolloProvider = new VueApollo({
  72. defaultClient: apolloClient,
  73. });
  74.  
  75. // Install the vue plugin
  76. Vue.use(VueApollo);
  77.  
  78. /* eslint-disable no-new */
  79. new Vue({
  80. el: '#app',
  81. i18n,
  82. router,
  83. provide: apolloProvider.provide(),
  84. render: h => h(App),
  85. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement