|
1 | 1 | import { Inject, Injectable } from '@angular/core'; |
2 | 2 | import { Apollo, gql } from 'apollo-angular'; |
3 | | -import { includes, uniq } from 'lodash-es'; |
| 3 | +import { includes, isNil, uniq } from 'lodash-es'; |
4 | 4 | import { defer, EMPTY, Observable, Observer, of, Subject, zip } from 'rxjs'; |
5 | | -import { buffer, catchError, debounceTime, filter, map, mergeMap, take } from 'rxjs/operators'; |
| 5 | +import { buffer, catchError, debounceTime, filter, map, mergeMap, take, tap } from 'rxjs/operators'; |
6 | 6 | import { |
7 | 7 | GraphQlHandler, |
8 | 8 | GraphQlHandlerType, |
@@ -151,15 +151,31 @@ export class GraphQlRequestService { |
151 | 151 | errorPolicy: 'all', |
152 | 152 | fetchPolicy: options.cacheability |
153 | 153 | }) |
154 | | - .pipe(map(response => response.data)); |
| 154 | + .pipe( |
| 155 | + tap(response => { |
| 156 | + if (!isNil(response.errors)) { |
| 157 | + // tslint:disable-next-line: no-console |
| 158 | + console.error(`Query response error(s) for request '${requestString}'`, response.errors); |
| 159 | + } |
| 160 | + }), |
| 161 | + map(response => response.data) |
| 162 | + ); |
155 | 163 | } |
156 | 164 |
|
157 | 165 | private executeMutation<TResponse extends { [key: string]: unknown }>(requestString: string): Observable<TResponse> { |
158 | 166 | return this.apollo |
159 | 167 | .mutate<TResponse>({ |
160 | 168 | mutation: gql(`mutation ${requestString}`) |
161 | 169 | }) |
162 | | - .pipe(mergeMap(response => (response.data ? of(response.data) : EMPTY))); |
| 170 | + .pipe( |
| 171 | + tap(response => { |
| 172 | + if (!isNil(response.errors)) { |
| 173 | + // tslint:disable-next-line: no-console |
| 174 | + console.error(`Mutation response error(s) for request '${requestString}'`, response.errors); |
| 175 | + } |
| 176 | + }), |
| 177 | + mergeMap(response => (response.data ? of(response.data) : EMPTY)) |
| 178 | + ); |
163 | 179 | } |
164 | 180 |
|
165 | 181 | private getResultForRequest<T>(request: GraphQlRequest): Observable<T> { |
|
0 commit comments