In this short tutorial, I wanna show you how to set up a Fastify web server implementing GraphQL via the mercurius module, and adding the first automated test using supertest while using TypeScript.
To provide you some boilerplate for your future projects and as a reference for this article I created a small GitHub repository that includes all the code mentioned in this article, so make sure to clone it and have it open as a reference while reading this article.
First of all, we have a very simple file structure. On the root level, we have our config files like
package.json. Right beneath we only have our
node_modules folders, so nothing really fancy here.
The whole source (in our case only one
index.ts ) is located under the
src folder and right beneath it we have a
test folder containing our tests. Of course, you are absolutely free to change the structure to your likes. I for myself like it when I have one test file right beneath the actual implementation file it should test, even though I did a bit otherwise here.
What do you do when you have lots of free time on your hands? Why not learn test programming strategies and approaches?
Write readable and maintainable tests .Rethinking Testing Through Declarative Programming
Full Playlist Graphql https://www.youtube.com/playlist?list=PLT5Jhb7lgSBOnwyukLUZb6X-WnliySCUL Github Link https://github.com/tkssharma/Graphql-fullstack-tut
API endpoint when you send the get request to that URL it returns the JSON response. In this article, I am going to use postman assertions for all the examples since it is the most popular tool. But this article is not intended only for the postman tool.