Testing GraphQL APIs
Write calls in GraphQL Playground, then transform them into test scripts in Ruby.
A repost of my daughter’s article with permission. I added a few notes. You can find more examples like this in my book: API Testing Recipes in Ruby.
GraphQL is an open-source data query and manipulation language for APIs and a runtime for fulfilling queries with existing data. It stores data in a graph-like structure.
This article will go through some common GraphQL API tests.
How I write GraphQL tests:
Most GraphQL endpoints provide a convenient and user-friendly interface (called Playground) to try out queries: you can type requests and get response data on the right. You can also view the schema there.
I follow the steps:
- Try out queries in GraphQL Playground.
- I also may do it in an HTTP graphic tool that offers more features.
- By then, I have a good idea of the query request I’m sending and what kind of response data I expect.
- Write an automated test in…