(
operation: Operation<TVariables>,
options?: RequestOptions
)
| 265 | } |
| 266 | |
| 267 | request<ResponseData, TGraphQLError = object, TVariables = object>( |
| 268 | operation: Operation<TVariables>, |
| 269 | options?: RequestOptions |
| 270 | ): Promise<Result<ResponseData, TGraphQLError>> { |
| 271 | const responseHandlers: (() => any)[] = [] |
| 272 | const addResponseHook = handler => responseHandlers.push(handler) |
| 273 | |
| 274 | return new Promise((resolve, reject) => |
| 275 | this.middleware.run( |
| 276 | { operation, client: this, addResponseHook, resolve, reject }, |
| 277 | ({ operation: updatedOperation }) => { |
| 278 | const transformResponse = res => { |
| 279 | if (responseHandlers.length > 0) { |
| 280 | // Pipe for promises |
| 281 | return pipeP(responseHandlers)(res) |
| 282 | } |
| 283 | return res |
| 284 | } |
| 285 | |
| 286 | if (this.fullWsTransport) { |
| 287 | return this.requestViaWS(updatedOperation) |
| 288 | .then(transformResponse) |
| 289 | .then(resolve) |
| 290 | .catch(reject) |
| 291 | } |
| 292 | |
| 293 | if (this.url) { |
| 294 | return this.requestViaHttp<ResponseData, TGraphQLError, TVariables>( |
| 295 | updatedOperation, |
| 296 | options |
| 297 | ) |
| 298 | .then(transformResponse) |
| 299 | .then(resolve) |
| 300 | .catch(reject) |
| 301 | } |
| 302 | reject(new Error('GraphQLClient: config.url is required')) |
| 303 | } |
| 304 | ) |
| 305 | ) |
| 306 | } |
| 307 | |
| 308 | requestViaHttp<ResponseData, TGraphQLError = object, TVariables = object>( |
| 309 | operation: Operation<TVariables>, |
no test coverage detected