diff --git a/client/src/app/shared/apollo/apollo.module.ts b/client/src/app/shared/apollo/apollo.module.ts index f476d12..a3613c7 100644 --- a/client/src/app/shared/apollo/apollo.module.ts +++ b/client/src/app/shared/apollo/apollo.module.ts @@ -1,33 +1,37 @@ import { HttpClientModule } from '@angular/common/http'; import { ModuleWithProviders, NgModule } from '@angular/core'; -import { APOLLO_OPTIONS, ApolloModule } from 'apollo-angular'; +import { ApolloModule, APOLLO_OPTIONS } from 'apollo-angular'; import { HttpLink, HttpLinkModule } from 'apollo-angular-link-http'; import { InMemoryCache } from 'apollo-cache-inmemory'; import { split } from 'apollo-link'; import { WebSocketLink } from 'apollo-link-ws'; import { getMainDefinition } from 'apollo-utilities'; -export const httpLinkFactory = (httpLink: HttpLink) => ({ - cache: new InMemoryCache(), - link: split( - ({ query }) => { - const def = getMainDefinition(query); +export const httpLinkFactory = (httpLink: HttpLink) => { + const href = window.location.href.endsWith('/') ? window.location.href : window.location.href + '/'; - return def.kind === 'OperationDefinition' && def.operation === 'subscription'; - }, + return { + cache: new InMemoryCache(), + link: split( + ({ query }) => { + const def = getMainDefinition(query); - new WebSocketLink({ - options: { - reconnect: true, + return def.kind === 'OperationDefinition' && def.operation === 'subscription'; }, - uri: window.location.href.replace(/^http/, 'ws') + 'graphql', - }), - httpLink.create({ - uri: window.location.href + 'graphql', - }), - ), -}); + new WebSocketLink({ + options: { + reconnect: true, + }, + uri: href.replace(/^http/, 'ws') + 'graphql', + }), + + httpLink.create({ + uri: href + 'graphql', + }), + ), + }; +}; @NgModule({ imports: [