diff --git a/lib/process-services-cloud/src/lib/services/web-socket.service.ts b/lib/process-services-cloud/src/lib/services/web-socket.service.ts index 1969f05f33..8ed6ff5530 100644 --- a/lib/process-services-cloud/src/lib/services/web-socket.service.ts +++ b/lib/process-services-cloud/src/lib/services/web-socket.service.ts @@ -23,7 +23,6 @@ import { DefaultContext, FetchResult, from, - HttpLink, InMemoryCache, InMemoryCacheConfig, NextLink, @@ -31,15 +30,16 @@ import { split, SubscriptionOptions } from '@apollo/client/core'; -import { getMainDefinition } from '@apollo/client/utilities'; -import { Kind, OperationTypeNode } from 'graphql'; +import { Observable } from 'rxjs'; import { Apollo } from 'apollo-angular'; +import { HttpLink, HttpLinkHandler } from 'apollo-angular/http'; +import { Kind, OperationTypeNode } from 'graphql'; import { onError } from '@apollo/client/link/error'; import { RetryLink } from '@apollo/client/link/retry'; -import { Observable } from 'rxjs'; +import { getMainDefinition } from '@apollo/client/utilities'; import { filter, map, switchMap, take, tap } from 'rxjs/operators'; -import { FeaturesServiceToken, IFeaturesService } from '@alfresco/adf-core/feature-flags'; import { AuthenticationService, AppConfigService } from '@alfresco/adf-core'; +import { FeaturesServiceToken, IFeaturesService } from '@alfresco/adf-core/feature-flags'; interface serviceOptions { apolloClientName: string; @@ -55,10 +55,11 @@ export class WebSocketService { private host = ''; private subscriptionProtocol: 'graphql-ws' | 'transport-ws' = 'transport-ws'; private wsLink: GraphQLWsLink | WebSocketLink; - private httpLink: HttpLink; + private httpLinkHandler: HttpLinkHandler; constructor( private readonly apollo: Apollo, + private readonly httpLink: HttpLink, private readonly appConfigService: AppConfigService, private readonly authService: AuthenticationService, @Optional() @Inject(FeaturesServiceToken) private featuresService: IFeaturesService @@ -117,11 +118,7 @@ export class WebSocketService { throw new Error('Unknown subscription protocol'); } - this.httpLink = options.httpUrl - ? new HttpLink({ - uri: this.createHttpUrl(options.httpUrl) - }) - : undefined; + this.createHttpLinkHandler(options); const link = split( ({ query }) => { @@ -129,7 +126,7 @@ export class WebSocketService { return definition.kind === Kind.OPERATION_DEFINITION && definition.operation === OperationTypeNode.SUBSCRIPTION; }, this.wsLink, - this.httpLink + this.httpLinkHandler ); const authLink = (operation: Operation, forward: NextLink) => { @@ -179,7 +176,7 @@ export class WebSocketService { }); } - private createTransportWsLink(options: serviceOptions) { + private createTransportWsLink(options: serviceOptions): void { this.wsLink = new WebSocketLink({ uri: this.createWsUrl(options.wsUrl) + '/ws/graphql', options: { @@ -193,7 +190,7 @@ export class WebSocketService { }); } - private createGraphQLWsLink(options: serviceOptions) { + private createGraphQLWsLink(options: serviceOptions): void { this.wsLink = new GraphQLWsLink( createClient({ url: this.createWsUrl(options.wsUrl) + '/v2/ws/graphql', @@ -210,4 +207,12 @@ export class WebSocketService { }) ); } + + private createHttpLinkHandler(options: serviceOptions): void { + this.httpLinkHandler = options.httpUrl + ? this.httpLink.create({ + uri: this.createHttpUrl(options.httpUrl) + }) + : undefined; + } }