Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions projects/graphql-client/src/graphql-request.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Inject, Injectable } from '@angular/core';
import { Apollo, gql } from 'apollo-angular';
import { includes, uniq } from 'lodash-es';
import { includes, isNil, uniq } from 'lodash-es';
import { defer, EMPTY, Observable, Observer, of, Subject, zip } from 'rxjs';
import { buffer, catchError, debounceTime, filter, map, mergeMap, take } from 'rxjs/operators';
import { buffer, catchError, debounceTime, filter, map, mergeMap, take, tap } from 'rxjs/operators';
import {
GraphQlHandler,
GraphQlHandlerType,
Expand Down Expand Up @@ -151,15 +151,31 @@ export class GraphQlRequestService {
errorPolicy: 'all',
fetchPolicy: options.cacheability
})
.pipe(map(response => response.data));
.pipe(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should do the same in executeMutation below

tap(response => {
if (!isNil(response.errors)) {
// tslint:disable-next-line: no-console
console.error(`Query response error(s) for request '${requestString}'`, response.errors);
}
}),
map(response => response.data)
);
}

private executeMutation<TResponse extends { [key: string]: unknown }>(requestString: string): Observable<TResponse> {
return this.apollo
.mutate<TResponse>({
mutation: gql(`mutation ${requestString}`)
})
.pipe(mergeMap(response => (response.data ? of(response.data) : EMPTY)));
.pipe(
tap(response => {
if (!isNil(response.errors)) {
// tslint:disable-next-line: no-console
console.error(`Mutation response error(s) for request '${requestString}'`, response.errors);
}
}),
mergeMap(response => (response.data ? of(response.data) : EMPTY))
);
}

private getResultForRequest<T>(request: GraphQlRequest): Observable<T> {
Expand Down