Hey guys, how would you go about testing apollo federated services ? I want to write e2e tests, but not sure where to begin? Is it possible to write out e2e test for separate service, or should I write these tests in my gateway? Since I have schemas that come from other services/subgraphs. Does someone have some experience with it and could tell me more? Would appreciate any help and tips. Looking forward for your reply
The idea is to keep the business/domain logic away from the gateway. Each federated service can house the e2e tests for the queries that it serves. These e2e tests are run against the gateway end-point. So, you don’t have to worry about the federated/extended types.
Do you mean that I should start all my microservices, start my gateway, and in my tests run the direct connection to my gateway? Isn’t that a bad practice? Did I get your idea right? If no could you expand a bit more? If yes- is it the best approach at the moment? Maybe you already have/could provide some small example of your approach? :>
Usually, E2E tests are run against an already deployed server/endpoint to test the entire flow including the dependencies (like other servers, databases, etc)
In a federated environment, if one of your services (serviceA
) serves query1
, and query2
, you would write e2e tests for both the queries within serviceA
’s codebase and have then run against the gateway endpoint in the test/stage environment.
Take a look at the Testing GraphQL talk where Jake Dawkins talks about Unit, Integration, and E2E test implementation in the fullstack-tutorial repo. Hope this helps.
All that testing documentation is around non-federation testing.
I should be able to do unit testing against my GraphQL server (before doing e2e testing) mocking the data that I need.
But things aren’t quite right when I test @external