Desktop app for sandboxing GraphQL-like calls and responses to RESTful API endpoints

Will Robinson
Aug 15 · 3 min read

It’s difficult to discuss GraphQL or Apollo without talking about the other. Since its founding in 2016, Apollo has emerged as one of the leading clients to leverage GraphQL within an application.

Airbnb, Audi, CNBC, and Expedia are among the engineering teams Apollo touts as adopting its technology.

GraphQL is lauded for its speed and declarative querying; unlike REST APIs, a GraphQL query returns exactly what the client requests to a single endpoint, boosting performance for clients with poor internet connections or less powerful devices.

But to implement the querying language, an API overhaul is necessary to appropriately serve GraphQL requests. To test queries, developers have to spin up a quick application or write a GraphQL back end.

Existing playgrounds are useful but they might not have meaningful data or errors for developers. And while GraphQL is very powerful, errors are not descriptive, even with the Apollo Client layer.

That’s where Hypnos comes in.

What Is Hypnos?

Hypnos is an endpoint tester, utilizing Apollo’s link-rest package to make GraphQL-structured queries to authenticated or non-authenticated RESTful APIs.

When a proper query is made, a response object is rendered on the screen with the fields specified by the client.


How Does It Work?

With the link-rest package, the Apollo client makes a fetch request to a given API and path. Upon receiving a response, the client parses through the response to structure data akin to what would be returned from a GraphQL endpoint.

While the under-the-hood actions are via normal fetches to REST APIs, instead of a cumbersome JSON-formatted object with fields irrelevant to the client, the data is parsed according to the query specification.


How Hypnos Helps

Apollo does not inherently handle errors declaratively. It does allow developers to catch errors with the apollo-link-error package in whichever way they choose.

However, if a GraphQL error is not written correctly (e.g. in the front end), the feedback can be unclear. Hypnos catches syntax errors and plainly describes where the fault in the query construction is.

Running a query in Hypnos

For GraphQL, if a query is structured properly to a valid endpoint, it will always run and return information and a 200 status code, even if declared query fields return null.

To help with this, Hypnos parses the response data to check for null values. As REST APIs might have intentionally null values, the entire response is still displayed, along with stack trace where null values exist.

The Hypnos team (Dillon Garrett, Sophie Nye, and Will Robinson) are very proud of their first release. If you are interested in Hypnos (v0.0.1-beta), please check out our GitHub page, and try out our application.

Better Programming

Advice for programmers.

Will Robinson

Written by

Software engineer. Media expat, with stops at @THR , @Thrillist , @EW , @AroundTheNFL , @Reuters .

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade