GraphQL API Performance Testing

Rebecca Miller
The Startup
Published in
3 min readSep 23, 2020
Photo by Markus Spiske on Unsplash

Why GraphQL?

Since it was open-sourced in 2015, GraphQL has skyrocketed in popularity due to its flexibility and efficiency. It can handle complex, nested queries by allowing clients to specify exactly what data they need in one request, thus eliminating the classic problems of overfetching and underfetching inherent to RESTful APIs. Another selling point of GraphQL? As it’s simply a query language, it is protocol agnostic and can thus be used additionally over HTTP2, websockets or TCP.

What’s the catch?

GraphQL is not a silver bullet, though, and there are a few issues to consider when making the switch. When deciding whether GraphQL is the right choice for you, consider the following challenges:

  • Error Messaging: Clients will always receive a 200 status even if a query fails, because non-200 response codes indicate an issue that occurred at the HTTP transport layer — not at the GraphQL layer.
  • Schema Design: developers are not careful when designing a schema design (and especially when defining resolver functions), performance and efficiency can take a nosedive — and may actually be worse with a GraphQL API than a RESTful one.
  • Performance Testing: Meaningful performance testing is difficult with a GraphQL API, as it only exposes one endpoint to test against. When troubleshooting a request containing multiple nested queries, how can developers know where the bottleneck is, or what caused the request to fail?

These are some issues to consider when designing your API, but the good news is that performance optimization and testing can be easily accomplished within these constraints.

So, just how fast was that query?

Enter OpticQL, a recently launched open-source project from OSLabs Beta that’s designed to address these issues with performance testing. OpticQL is a desktop application that exposes a user-friendly testing playground for a GraphQL API, coupled with a lightweight NPM package that allows developers to seamlessly connect their application to OpticQL, import their schema, and capture performance metrics of database requests.

Features of OpticQL include:

  • Schema visualization, which renders a graphical representation of all the schema’s fields and edges. All type names are connected to their fields in a color-coded and dynamic view. A full-screen view of the schema visualization is also available.
  • Input field to write and submit queries and mutations. When a query or mutation is sent to OpticQL, all affected parts of the schema will turn green to indicate that they were “reached” by the request.
  • A view with the returned response data, granular resolver-specific tracing information, and a list of any errors triggered by the request.
  • A graphical overview of the request’s performance in milliseconds, with options to view the most recent request’s performance compared with the performance of historical requests made to OpticQL.
  • A further option to browse expanded performance metrics for each field that was affected by the query.

OpticQL is a robust, easy-to-use option for developers looking to test and optimize their GraphQL API’s performance. To download OpticQL or to learn more, visit OpticsQL’s website. And, of course, OpticQL’s engineering team welcomes any feedback, suggestions, or concerns you may have about the product: we’re always looking to improve!

--

--