'Angular re-initiate Class
I have an API service in angular that I would like to reload when backend data is upadted (graphQL API addresses). More specifically, in the code below, I would like for the OnCreateReportListener to refresh as the API.graphql function will have new routes (that are contained in the API import.
import { Injectable } from "@angular/core";
import API, { graphqlOperation, GraphQLResult } from "@aws-amplify/api-graphql";
import { Observable } from "zen-observable-ts";
export class APIService {
async CreateReport(
input: CreateReportInput,
condition?: ModelReportConditionInput
): Promise<CreateReportMutation> {
const statement = `mutation CreateReport($input: CreateReportInput!, $condition:
ModelReportConditionInput) {
createReport(input: $input, condition: $condition) {
__typename
id
report
user
client
timeStamp
}
}`;
const gqlAPIServiceArguments: any = {
input
};
if (condition) {
gqlAPIServiceArguments.condition = condition;
}
const response = (await API.graphql(
graphqlOperation(statement, gqlAPIServiceArguments)
)) as any;
return <CreateReportMutation>response.data.createReport;
}
OnCreateReportListener: Observable<
SubscriptionResponse<OnCreateReportSubscription>
> = API.graphql(
graphqlOperation(
`subscription onCreateReport {
onCreateReport {
__typename
id
report
user
client
timeStamp
}
}`
)
) as Observable<SubscriptionResponse<OnCreateReportSubscription>>;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
