The Power of GraphQL, With RESTful APIs: Meet Hypnos
Tags: graphql, apollo, react, javascript
Published: 2019-08-15 13:46:18

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](https://techcrunch.com/2019/06/12/apollo-raises-22m-for-its-graphql-platform/) GraphQL within an application. [Airbnb](https://medium.com/airbnb-engineering/how-airbnb-is-moving-10x-faster-at-scale-with-graphql-and-apollo-aa4ec92d69e2), 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 and/or write a GraphQL backend. 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 frontend), the feedback can be unclear. Hypnos catches syntax errors and plainly describes where the fault in the query construction is.
​![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/vvwrncx96wafhwl4ocbj.gif)
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 aid with this, Hypnos parses the response data to check for null values. Since 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](https://github.com/dillon-garrett), [Sophie Nye](https://github.com/SophieNye), [Will Robinson](https://github.com/wrobinson91)) are very proud of their first release. If you are interested in Hypnos (v0.0.1-beta), please check out our [Github page](https://github.com/oslabs-beta/hypnos/), give us a star, and [try out our application](https://github.com/oslabs-beta/hypnos/releases).
{% github oslabs-beta/hypnos/ %}