DEV Community

Cover image for The Power of GraphQL, With RESTful APIs: Meet Hypnos
Will Robinson
Will Robinson

Posted on • Originally published at Medium

The Power of GraphQL, With RESTful APIs: Meet Hypnos

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 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
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, Sophie Nye, 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, give us a star, and try out our application.

GitHub logo oslabs-beta / hypnos

The best way to test GraphQL calls to RESTful APIs.

PRs Welcome License: MIT

HYPNOS

Welcome to Hypnos(beta), a streamlined desktop application to sandbox GraphQL calls to RESTful APIs using the Apollo-link-rest package from Apollo Client, as well as giving detailed, helpful error messages.

* We recently added tabs to handle multiple entries!

Getting Started

Requirements

All you need to do is download your respective OS package, install, and go!

How to Install

Download for Mac or Windows (Linux coming soon!)

Mac: hypnos-0.0.2.dmg

Windows Zipped Config: hypnos-0.0.2.zip

Install the app to your applications folder.

How to Use

Enter your API endpoint

Hypnos supports calls to both open APIs and APIs requiring a key. Future versions will include support for APIs requiring Basic Auth and Oauth2

Enter your Apollo-link-rest query

A sample query is provided. Further documentation on Apollo-link-rest calls can be found in the Apollo GraphQL documents here: https://www.apollographql.com/docs/link/links/rest/

Hypnos will return the GraphQL response or meaningful errors

If there are…




Top comments (0)