kamilkisiela / apollo-angular

A fully-featured, production ready caching GraphQL client for Angular and every GraphQL server 🎁
https://apollo-angular.com
MIT License
1.5k stars 309 forks source link

ApolloTestingController doesn't seem to be triggering an HttpInterceptor #2034

Closed KarmaCop213 closed 1 week ago

KarmaCop213 commented 1 year ago

Describe the bug

ApolloTestingController doesn't seem to be triggering an HttpInterceptor I have

To Reproduce

I have an HttpInterceptor declared like so:

export class ErrorHandlerInterceptor implements HttpInterceptor {

and I have call on my code to apollo like this:

import { Apollo } from "apollo-angular"
(...)
constructor(private readonly apollo: Apollo) {}
(...)
return this.apollo.mutate<T>({ mutation, variables })

on my test I make a call to this.apollo.mutate<T>({ mutation, variables }). And to simulate the call, the only way I could find that triggers the HttpInterceptor is to make a dummy call to an endpoint using HttpClient:

const apolloTestingController = TestBed.inject(ApolloTestingController),
const httpMock  = TestBed.inject(HttpTestingController),
const httpClient  = TestBed.inject(HttpClient)

this.apolloTestingController.expectOne(callingGraphqlQuery).flush(responseBody as unknown)
this.apolloTestingController.verify()

this.httpClient.post("/graphql", { operationName }).subscribe()
this.httpMock.expectOne({ method: "POST" }).flush(responseBody, opts)
this.httpMock.verify()

Expected behavior

From my point of view ApolloTestingController should trigger HttpInterceptor.

Environment:

β”œβ”€β”€ @angular/cli@14.2.7
β”œβ”€β”€ @angular/core@14.2.7
β”œβ”€β”€ @apollo/client@3.6.9
β”œβ”€β”€ apollo-angular@4.1.1
β”œβ”€β”€ graphql@15.8.0
└── typescript@4.8.4
PowerKiKi commented 1 week ago

HttpInterceptor works with HttpService, but ApolloTestingController does not use HttpService at all. So it is pretty much impossible have the interceptor reacts to what is going on in the tests using ApolloTestingController.