Skip to content

Commit

Permalink
Merge pull request #454 from intersective/feature/CORE-6606/use-graph…
Browse files Browse the repository at this point in the history
…ql-url-for-chat-related-apis-trunk

[CORE-6606] Use graphql url for chat related apis trunk
  • Loading branch information
sasangachathumal authored Jul 25, 2024
2 parents 5bef727 + ca26bca commit 5b76547
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 86 deletions.
1 change: 0 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export class AppComponent implements OnInit {
// initialise Pusher
await this.pusherService.initialise();
this.apolloService.initiateCoreClient();
this.apolloService.initiateChatClient();
});
}
}
22 changes: 11 additions & 11 deletions src/app/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class ChatService {
const response = this.demo.getChats();
return of(this._normaliseChatListResponse(response.data)).pipe(delay(1000));
}
return this.apollo.chatGraphQLQuery(
return this.apollo.graphQLFetch(
`query getChannels {
channels{
uuid
Expand Down Expand Up @@ -224,7 +224,7 @@ export class ChatService {
if (!data.scheduledOnly) {
delete params.scheduledOnly;
}
return this.apollo.chatGraphQLQuery(
return this.apollo.graphQLFetch(
`query getChannellogs($uuid:String!, $cursor:String!, $size:Int!, $scheduledOnly:Boolean) {
channel(uuid:$uuid){
chatLogsConnection(cursor:$cursor, size:$size, scheduledOnly:$scheduledOnly){
Expand Down Expand Up @@ -307,7 +307,7 @@ export class ChatService {
const response = this.demo.getMembers(channelId);
return of(this._normaliseChatMembersResponse(response.data)).pipe(delay(1000));
}
return this.apollo.chatGraphQLQuery(
return this.apollo.graphQLFetch(
`query getChannelmembers($uuid:String!) {
channel(uuid:$uuid){
members{
Expand Down Expand Up @@ -349,7 +349,7 @@ export class ChatService {
const response = this.demo.getPusherChannels();
return of(this._normalisePusherChannelsResponse(response.data)).pipe(delay(1000));
}
return this.apollo.chatGraphQLQuery(
return this.apollo.graphQLFetch(
`query getPusherChannels {
channels {
pusherChannel
Expand Down Expand Up @@ -379,7 +379,7 @@ export class ChatService {
if (environment.demo) {
return of({}).pipe(delay(1000));
}
return this.apollo.chatGraphQLMutate(
return this.apollo.graphQLMutate(
`mutation markAsSeen($uuids: [String]!) {
readChatLogs(uuids: $uuids) {
success
Expand All @@ -400,7 +400,7 @@ export class ChatService {
const response = this.demo.getNewMessage(data);
return of(this._normalisePostMessageResponse(response.data)).pipe(delay(1000));
}
return this.apollo.chatGraphQLMutate(
return this.apollo.graphQLMutate(
`mutation createChatLogs($channelUuid: String!, $message: String, $file: String, $scheduled: String) {
createChatLog(channelUuid: $channelUuid, message: $message, file: $file, scheduled: $scheduled) {
uuid
Expand Down Expand Up @@ -481,7 +481,7 @@ export class ChatService {
const response = this.demo.getNewChannel(data);
return of(this._normaliseCreateChannelResponse(response.data)).pipe(delay(1000));
}
return this.apollo.chatGraphQLMutate(
return this.apollo.graphQLMutate(
`mutation createChannel($name: String, $isAnnouncement: Boolean, $roles: [String], $members: [MemberInput]!){
createChannel(name: $name, isAnnouncement: $isAnnouncement, roles: $roles, members: $members) {
uuid
Expand Down Expand Up @@ -545,7 +545,7 @@ export class ChatService {
if (environment.demo) {
return of({}).pipe(delay(1000));
}
return this.apollo.chatGraphQLMutate(
return this.apollo.graphQLMutate(
`mutation deleteChannel($uuid: String!){
deleteChannel(uuid: $uuid) {
success
Expand All @@ -562,7 +562,7 @@ export class ChatService {
const response = this.demo.getEditedChannel(data);
return of(this._normaliseEditChannelResponse(response.data)).pipe(delay(1000));
}
return this.apollo.chatGraphQLMutate(
return this.apollo.graphQLMutate(
`mutation editChannel($uuid: String!, $name: String, $isAnnouncement: Boolean, $roles: [String]){
editChannel(uuid: $uuid, name: $name, isAnnouncement: $isAnnouncement, roles: $roles) {
uuid
Expand Down Expand Up @@ -686,7 +686,7 @@ export class ChatService {
if (environment.demo) {
return of({}).pipe(delay(1000));
}
return this.apollo.chatGraphQLMutate(
return this.apollo.graphQLMutate(
`mutation deletechatMessage($uuid: String!) {
deleteChatLog(uuid: $uuid) {
success
Expand All @@ -702,7 +702,7 @@ export class ChatService {
if (environment.demo) {
return of({}).pipe(delay(1000));
}
return this.apollo.chatGraphQLMutate(
return this.apollo.graphQLMutate(
`mutation edichatMessage($uuid: String!, $message: String, $file: String, $scheduled: String) {
editChatLog(uuid: $uuid, message: $message, file: $file, scheduled: $scheduled) {
success
Expand Down
4 changes: 2 additions & 2 deletions src/app/metrics/metric-card/metric-card.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
<div class="matric-status-chip" [class]="data?.status">
<ion-icon [name]="getStatusIcon(data?.status)"></ion-icon>
</div>
<div class="config-status-chip" [class]="this.data?.dataSourceId ? 'configured' : 'not_configured'">
<ion-icon [name]="getStatusIcon(this.data?.dataSourceId ? 'configured' : 'not_configured')"></ion-icon>
<div class="config-status-chip" [class]="data?.dataSourceId ? 'configured' : 'not_configured'">
<ion-icon [name]="getStatusIcon(data?.dataSourceId ? 'configured' : 'not_configured')"></ion-icon>
</div>
</div>
<ng-container *ngIf="data?.lastRecord">
Expand Down
10 changes: 8 additions & 2 deletions src/app/metrics/metrics.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ModalController } from '@ionic/angular';
import { UtilsService } from '@app/shared/services/utils.service';
import { NavigationEnd, Router } from '@angular/router';
import { PopupService } from '@shared/popup/popup.service';
import { retry } from 'rxjs/operators';

@Component({
selector: 'app-metrics',
Expand All @@ -24,7 +25,7 @@ export class MetricsComponent implements OnInit, OnDestroy {
private modalController: ModalController,
private utils: UtilsService,
private router: Router,
private popupService: PopupService
private popupService: PopupService,
) {
// subscribe to router and once this route activated will trigger fetch
this.router.events.pipe(
Expand Down Expand Up @@ -52,7 +53,12 @@ export class MetricsComponent implements OnInit, OnDestroy {
async fetchData() {
this.isLoading = true;

this.metricsService.getMetrics(false).pipe(takeUntil(this.unsubscribe$)).subscribe({
this.metricsService.getMetrics(false)
.pipe(
retry(3),
takeUntil(this.unsubscribe$)
)
.subscribe({
error: async (_error) => {
await this.popupService.showToast(
'Failed to load metrics, please refresh and try again.',
Expand Down
71 changes: 7 additions & 64 deletions src/app/shared/apollo/apollo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@ import { RequestService } from '../request/request.service';
import { catchError, concatMap, map } from 'rxjs/operators';
import { HttpErrorResponse } from '@angular/common/http';

enum ClientType {
core = 'CORE',
chat = 'CHAT'
}

@Injectable({
providedIn: 'root'
})
export class ApolloService {
private apolloInstance: Apollo;
private _url = {
core: '',
chat: '',
};
private _url = '';

constructor(
private apollo: Apollo,
Expand All @@ -30,7 +22,7 @@ export class ApolloService {
) {}

initiateCoreClient(): Apollo {
if (this._hasInitiated(environment.graphQL, ClientType.core)) {
if (this._hasInitiated()) {
return this.apolloInstance;
}

Expand All @@ -55,45 +47,26 @@ export class ApolloService {
});

this.apolloInstance = this.apollo;
this._url.core = environment.graphQL;
this._url = environment.graphQL;

return this.apolloInstance;
}

/**
* skip if apollo already created for an URI
* pairing conditions: URL & ClientType
* pairing conditions: URL
* - core grahpql domain & 'core'
* - chat grahpql domain & 'chat'
*
* @returns boolean
*/
private _hasInitiated(url: string, type: ClientType = ClientType.core): boolean {
if (type === ClientType.core
&& this.apollo.client
&& this._url.core === environment.graphQL) {
private _hasInitiated(): boolean {
if (this.apollo.client
&& this._url === environment.graphQL) {
return true;
} else if (type === ClientType.chat
&& this.apollo.use('chat')
&& this._url.chat === environment.chatGraphQL) {
return true;
}
return false;
}

initiateChatClient() {
if (this._hasInitiated(environment.chatGraphQL, ClientType.chat)) {
return;
}
this.apollo.createNamed('chat', {
link: this.httpLink.create({
uri: environment.chatGraphQL
}),
cache: new InMemoryCache(),
});
this._url.chat = environment.chatGraphQL;
}

getClient() {
return this.apollo.client;
}
Expand Down Expand Up @@ -190,34 +163,4 @@ export class ApolloService {
catchError((error: HttpErrorResponse) => of({ error }))
);
}

/*
* Valid options:
* noCache: Boolean default false. If set to false, will not cache the result
*/
chatGraphQLQuery(query: string, variables: any = {}) {
const watch = this.apollo.use('chat').query({
query: gql(query),
variables,
fetchPolicy: 'no-cache' // always retrieve a fresh one
});
return watch.pipe(
concatMap(response => {
return of(response);
}),
catchError((error) => this.requestService.handleError(error))
);
}

chatGraphQLMutate(query: string, variables = {}): Observable<any> {
return this.apollo.use('chat').mutate({
mutation: gql(query),
variables: variables
}).pipe(
concatMap(response => {
return of(response);
}),
catchError((error) => this.requestService.handleError(error))
);
}
}
2 changes: 1 addition & 1 deletion src/app/shared/pusher/pusher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class PusherService {
}

getChatChannels(): Observable<any> {
return this.apollo.chatGraphQLQuery(
return this.apollo.graphQLFetch(
`query getPusherChannels {
channels {
pusherChannel
Expand Down
1 change: 0 additions & 1 deletion src/environments/environment.custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const environment = {
APIEndpointOld: '<CUSTOM_APIENDPOINTOLD>',
Practera: '<CUSTOM_PRACTERCORE>',
graphQL: '<CUSTOM_GEAPHQLENDPOINT>',
chatGraphQL: '<CUSTOM_CHATGEAPHQLENDPOINT>',
filestack: {
key: '<CUSTOM_FILESTACK_KEY>',
s3Config: {
Expand Down
1 change: 0 additions & 1 deletion src/environments/environment.demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const environment = {
APIEndpointOld: 'http://127.0.0.1:8080/',
Practera: 'http://127.0.0.1:8080',
graphQL: 'http://127.0.0.1:8000/',
chatGraphQL: 'http://localhost:3000/local/graphql/',
filestack: {
key: 'AO6F4C72uTPGRywaEijdLz',
s3Config: {
Expand Down
1 change: 0 additions & 1 deletion src/environments/environment.local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const environment = {
APIEndpointOld: 'http://127.0.0.1:8080/',
Practera: 'http://127.0.0.1:8080',
graphQL: 'http://127.0.0.1:8000/',
chatGraphQL: 'http://localhost:3000/local/graphql/',
filestack: {
key: 'AO6F4C72uTPGRywaEijdLz',
s3Config: {
Expand Down
1 change: 0 additions & 1 deletion src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const environment = {
APIEndpointOld: 'https://api.practera.com/',
Practera: 'https://my.practera.com',
graphQL: 'https://kixs5acl6j.execute-api.ap-southeast-2.amazonaws.com/sandbox/',
chatGraphQL: 'https://antkrqcqa6.execute-api.ap-southeast-2.amazonaws.com/dev/graphql',
filestack: {
key: 'AO6F4C72uTPGRywaEijdLz',
s3Config: {
Expand Down
1 change: 0 additions & 1 deletion src/environments/environment.sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const environment = {
APIEndpointOld: 'https://sandbox.practera.com/',
Practera: 'https://sandbox.practera.com',
graphQL: 'https://kixs5acl6j.execute-api.ap-southeast-2.amazonaws.com/sandbox/',
chatGraphQL: 'https://antkrqcqa6.execute-api.ap-southeast-2.amazonaws.com/dev/graphql',
filestack: {
key: 'AO6F4C72uTPGRywaEijdLz',
s3Config: {
Expand Down

0 comments on commit 5b76547

Please sign in to comment.