Fix graphql base uri

This commit is contained in:
Chrystian Huot 2020-02-02 10:29:11 -05:00
parent a2eb2005de
commit 2402ee5e15

View file

@ -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: [