All files / src/common_services/appsync appSyncClient.ts

100% Statements 13/13
100% Branches 0/0
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3019x 19x 19x 19x 19x     19x     19x   183x 183x     183x                          
import { AWSAppSyncClient, AUTH_TYPE } from 'aws-appsync';
import { Injectable } from '@nestjs/common';
import 'isomorphic-fetch';
import { EnvironmentService } from '../config';
import { AppSyncUtils } from './appsyncUtils';
 
// this is required by appsync sdk subscription
(global as any).WebSocket = require('ws');
 
@Injectable()
export class AppSyncClient {
  constructor(
    private readonly envService: EnvironmentService,
    public utils: AppSyncUtils,
  ) {}
 
  getAppSyncClient = (): Promise<AWSAppSyncClient<any>> => new AWSAppSyncClient({
    url: this.envService.appSyncEndpoint,
    region: this.envService.awsRegion,
    auth: {
      type: AUTH_TYPE.AWS_IAM,
      credentials: {
        accessKeyId: this.envService.iamUserKey,
        secretAccessKey: this.envService.iamUserSecret,
      },
    },
    disableOffline: true,
  }).hydrated();
}