mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-32999 Removed subscriptions-transport-ws feature flag (#10727)
* AAE-32999 Removed subscriptions-transport-ws feature flag * AAE-32999 Fixing unit test * AAE-32999 Fixing unit test * AAE-32999 Fixing unit test
This commit is contained in:
@@ -29,7 +29,6 @@
|
||||
"allowedNonPeerDependencies": [
|
||||
"@apollo/client",
|
||||
"apollo-angular",
|
||||
"subscriptions-transport-ws",
|
||||
"@editorjs/editorjs",
|
||||
"@editorjs/code",
|
||||
"@editorjs/header",
|
||||
|
@@ -41,8 +41,7 @@
|
||||
"@alfresco/adf-content-services": ">=8.0.0",
|
||||
"@apollo/client": ">=3.7.2",
|
||||
"@ngx-translate/core": ">=14.0.0",
|
||||
"apollo-angular": ">=4.0.1",
|
||||
"subscriptions-transport-ws": ">=0.11.0"
|
||||
"apollo-angular": ">=4.0.1"
|
||||
},
|
||||
"keywords": [
|
||||
"process-services-cloud",
|
||||
|
@@ -17,12 +17,11 @@
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { NotificationCloudService } from './notification-cloud.service';
|
||||
import { provideMockFeatureFlags } from '@alfresco/adf-core/feature-flags';
|
||||
import { WebSocketService } from './web-socket.service';
|
||||
import { Apollo } from 'apollo-angular';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { AuthenticationService } from '@alfresco/adf-core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { of, Subject } from 'rxjs';
|
||||
|
||||
describe('NotificationCloudService', () => {
|
||||
let service: NotificationCloudService;
|
||||
@@ -46,7 +45,6 @@ describe('NotificationCloudService', () => {
|
||||
imports: [HttpClientTestingModule],
|
||||
providers: [
|
||||
WebSocketService,
|
||||
provideMockFeatureFlags({ ['studio-ws-graphql-subprotocol']: false }),
|
||||
{
|
||||
provide: Apollo,
|
||||
useValue: apolloMock
|
||||
@@ -62,6 +60,7 @@ describe('NotificationCloudService', () => {
|
||||
});
|
||||
service = TestBed.inject(NotificationCloudService);
|
||||
wsService = TestBed.inject(WebSocketService);
|
||||
apolloMock.use.and.returnValue(of({}));
|
||||
});
|
||||
|
||||
it('should call getSubscription with the correct parameters', () => {
|
||||
@@ -72,7 +71,7 @@ describe('NotificationCloudService', () => {
|
||||
expect(getSubscriptionSpy).toHaveBeenCalledWith({
|
||||
apolloClientName: 'myAppName',
|
||||
wsUrl: 'myAppName/notifications',
|
||||
httpUrl: 'myAppName/notifications/graphql',
|
||||
httpUrl: 'myAppName/notifications/v2/ws/graphql',
|
||||
subscriptionOptions: {
|
||||
query: jasmine.any(Object)
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ export class NotificationCloudService {
|
||||
return this.webSocketService.getSubscription({
|
||||
apolloClientName: appName,
|
||||
wsUrl: `${appName}/notifications`,
|
||||
httpUrl: `${appName}/notifications/graphql`,
|
||||
httpUrl: `${appName}/notifications/v2/ws/graphql`,
|
||||
subscriptionOptions: {
|
||||
query: gql(gqlQuery)
|
||||
}
|
||||
|
@@ -22,14 +22,12 @@ import { WebSocketService } from './web-socket.service';
|
||||
import { SubscriptionOptions } from '@apollo/client/core';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { AuthenticationService, AppConfigService } from '@alfresco/adf-core';
|
||||
import { FeaturesServiceToken } from '@alfresco/adf-core/feature-flags';
|
||||
|
||||
describe('WebSocketService', () => {
|
||||
let service: WebSocketService;
|
||||
const onLogoutSubject: Subject<void> = new Subject<void>();
|
||||
|
||||
const apolloMock = jasmine.createSpyObj('Apollo', ['use', 'createNamed']);
|
||||
const isOnSpy = jasmine.createSpy('isOn$');
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
@@ -51,19 +49,11 @@ describe('WebSocketService', () => {
|
||||
getToken: () => 'testToken',
|
||||
onLogout: onLogoutSubject.asObservable()
|
||||
}
|
||||
},
|
||||
{
|
||||
provide: FeaturesServiceToken,
|
||||
useValue: {
|
||||
isOn$: isOnSpy
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
service = TestBed.inject(WebSocketService);
|
||||
TestBed.inject(FeaturesServiceToken);
|
||||
apolloMock.use.and.returnValues(undefined, { subscribe: () => of({}) });
|
||||
isOnSpy.and.returnValues(of(true));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -115,22 +105,4 @@ describe('WebSocketService', () => {
|
||||
expect(apolloMock.createNamed).toHaveBeenCalled();
|
||||
expect(headers).toEqual(expectedHeaders);
|
||||
});
|
||||
|
||||
it('should create named client with the right authentication token when FF is off', async () => {
|
||||
isOnSpy.and.returnValues(of(false));
|
||||
let headers = {};
|
||||
const expectedHeaders = { 'X-Authorization': 'Bearer testToken' };
|
||||
const apolloClientName = 'testClient';
|
||||
const subscriptionOptions: SubscriptionOptions = { query: gql(`subscription {testQuery}`) };
|
||||
const wsOptions = { apolloClientName, wsUrl: 'testUrl', subscriptionOptions };
|
||||
apolloMock.createNamed.and.callFake((_, options) => {
|
||||
headers = options.headers;
|
||||
});
|
||||
|
||||
await lastValueFrom(service.getSubscription(wsOptions));
|
||||
|
||||
expect(apolloMock.use).toHaveBeenCalledTimes(2);
|
||||
expect(apolloMock.createNamed).toHaveBeenCalled();
|
||||
expect(headers).toEqual(expectedHeaders);
|
||||
});
|
||||
});
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { createClient } from 'graphql-ws';
|
||||
import { inject, Inject, Injectable, Optional } from '@angular/core';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
|
||||
import { WebSocketLink } from '@apollo/client/link/ws';
|
||||
import {
|
||||
@@ -37,9 +37,8 @@ import { Kind, OperationTypeNode } from 'graphql';
|
||||
import { onError } from '@apollo/client/link/error';
|
||||
import { RetryLink } from '@apollo/client/link/retry';
|
||||
import { getMainDefinition } from '@apollo/client/utilities';
|
||||
import { switchMap, take, tap } from 'rxjs/operators';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { AppConfigService, AuthenticationService } from '@alfresco/adf-core';
|
||||
import { FeaturesServiceToken, IFeaturesService } from '@alfresco/adf-core/feature-flags';
|
||||
|
||||
interface serviceOptions {
|
||||
apolloClientName: string;
|
||||
@@ -53,16 +52,11 @@ interface serviceOptions {
|
||||
})
|
||||
export class WebSocketService {
|
||||
private appConfigService = inject(AppConfigService);
|
||||
private subscriptionProtocol: 'graphql-ws' | 'transport-ws' = 'transport-ws';
|
||||
private subscriptionProtocol = 'graphql-ws';
|
||||
private wsLink: GraphQLWsLink | WebSocketLink;
|
||||
private httpLinkHandler: HttpLinkHandler;
|
||||
|
||||
constructor(
|
||||
private readonly apollo: Apollo,
|
||||
private readonly httpLink: HttpLink,
|
||||
private readonly authService: AuthenticationService,
|
||||
@Optional() @Inject(FeaturesServiceToken) private featuresService: IFeaturesService
|
||||
) {}
|
||||
constructor(private readonly apollo: Apollo, private readonly httpLink: HttpLink, private readonly authService: AuthenticationService) {}
|
||||
|
||||
public getSubscription<T>(options: serviceOptions): Observable<FetchResult<T>> {
|
||||
const { apolloClientName, subscriptionOptions } = options;
|
||||
@@ -72,19 +66,10 @@ export class WebSocketService {
|
||||
}
|
||||
});
|
||||
|
||||
return this.featuresService.isOn$('studio-ws-graphql-subprotocol').pipe(
|
||||
tap((isOn) => {
|
||||
if (isOn) {
|
||||
this.subscriptionProtocol = 'graphql-ws';
|
||||
}
|
||||
}),
|
||||
switchMap(() => {
|
||||
if (this.apollo.use(apolloClientName) === undefined) {
|
||||
this.initSubscriptions(options);
|
||||
}
|
||||
return this.apollo.use(apolloClientName).subscribe<T>({ errorPolicy: 'all', ...subscriptionOptions });
|
||||
})
|
||||
);
|
||||
if (this.apollo.use(apolloClientName) === undefined) {
|
||||
this.initSubscriptions(options);
|
||||
}
|
||||
return this.apollo.use(apolloClientName).subscribe<T>({ errorPolicy: 'all', ...subscriptionOptions });
|
||||
}
|
||||
|
||||
private get contextRoot() {
|
||||
@@ -106,16 +91,7 @@ export class WebSocketService {
|
||||
}
|
||||
|
||||
private initSubscriptions(options: serviceOptions): void {
|
||||
switch (this.subscriptionProtocol) {
|
||||
case 'graphql-ws':
|
||||
this.createGraphQLWsLink(options);
|
||||
break;
|
||||
case 'transport-ws':
|
||||
this.createTransportWsLink(options);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown subscription protocol');
|
||||
}
|
||||
this.createGraphQLWsLink(options);
|
||||
|
||||
this.createHttpLinkHandler(options);
|
||||
|
||||
@@ -175,20 +151,6 @@ export class WebSocketService {
|
||||
});
|
||||
}
|
||||
|
||||
private createTransportWsLink(options: serviceOptions): void {
|
||||
this.wsLink = new WebSocketLink({
|
||||
uri: this.createWsUrl(options.wsUrl) + '/ws/graphql',
|
||||
options: {
|
||||
reconnect: true,
|
||||
lazy: true,
|
||||
connectionParams: {
|
||||
kaInterval: 2000,
|
||||
'X-Authorization': 'Bearer ' + this.authService.getToken()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private createGraphQLWsLink(options: serviceOptions): void {
|
||||
this.wsLink = new GraphQLWsLink(
|
||||
createClient({
|
||||
|
Reference in New Issue
Block a user