E2E testing in GraphQL
We have only tested blocks of codes separately, but we haven’t tested the nest decorators, such as @Query
or @Mutation
. In this section, let’s do so.
Let’s see how we can test the GetHello
query, one of the operations we have in our resolver file, as it is the simplest one.
By default, Nest installs the supertest
package for us; this package will help us simulate HTTP requests.
As you already know, all the GraphQL requests (mutations and queries) are just POST
requests to the entry point of the app, which is /graphql
. Having that in mind will help us focus on testing our GraphQL as a single endpoint REST API.
The next question would be this: Which body object and query param headers do I use to simulate a GraphQL API?
From a client app (we use this point of view as our E2E test will simulate clients’ requests), Figure 8.1 shows what we send as a payload to that entry point.
Figure 8.1 –...