I am working with Angular10. Calling GraphQL queries. When I call the same GraphQL query multiple times with different POST data all the API calls gets canceled except the last one.
But I want all the APIs needs to be called.
Having this Config in app.module.ts provider
{
provide: APOLLO_OPTIONS,
useFactory: (httpLink: HttpLink) => {
const http = httpLink.create({uri: '/graphql'});
const errors = onError(({graphQLErrors, networkError}) => { return graphQLErrors; });
const link = errors.concat(http);
return {
link,
cache: new InMemoryCache(),
};
},
deps: [HttpLink],
}
app.service.ts
public getEmployeesData(
input: {projectId: number}
): Observable<ApolloQueryResult<{employee_query: any}>> {
return this.apollo.watchQuery<{employee_query: any}>({
query:gql` query employee_query(
$projectId: INT!
) {
employee_query(
projectId: $projectId
) {
firstname
lastname
empId
disignation
}
},
variables: input,
}).valueChanges;
}
My Effect.ts
@Effect()
public getEmployee(): Observable<IAction<any | HttpErrorResponse>> {
return this._actions$.pipe(
ofType(EmployeeAction.GET_EMPLOYEE_DATA),
switchMap((action: IAction<any>) => {
return this.getEmployeesData(action.payload).pipe(map(
(
response: ApolloQueryResult<{
employee_query?: any;
}>,
) => {
return EmployeeAction.getEmployeeResponse(
response.data.employee_query
);
},
),
);
}),
);
}