• Home
  • Public Speaking
  • Travel

Testing APIs with GraphQL

What is GraphQL

GraphQL is a query language for APIs. As we know, an API is an application protocol interface which returns responses to queries with a code and context. Previously RESTful APIs were commonly used. As always chasing for a better efficiency, the API development world welcomed a new query language: GraphQL.

Suppose that I have an API, over which I can query movies. Each movie entity has several attributes (director, cast, year, language, location, genre, synopsis, etc.). If I am interested in reading the directors of all movies, synopsis info would not contribute to my purpose. Yes, you got the idea: if we pul only director attribute for each movie instead of the whole entity, we save a lot of data transfer and speed. See how it works below. (refer)

Benefits

So the key advantages are:
  • Ask for what you want! No need to pull all attributes
  • Get many resurces in a single request: No need to query all entities one by one.

Testing

As we have already seen in the video above, we should set what we are interested in, in our query. A sample Cypress implementation for getting jobs with a keyword in a location would look like: