How to use GraphQL APIs from RapidAPI Hub?

Wed Nov 10 2021

3 min read

RapidAPI Hub provides access to a large number of useful GraphQL APIs. It also simplifies the process of setting up, testing and integrating them.

Here are a few pointers on how you can use a GraphQL API from RapidAPI Hub.

Finding the Right API

Finding an API that fits your requirements well can be a demanding task. RapidAPI Hub lets you choose from thousands of public APIs for use in your projects. These also include GraphQL APIs. You can find them easily on RapidAPI Hub.

Create an account on it if you haven’t already. Then, you can look for GraphQL APIs in the search section.

Loading component...


Let's say I want to use one of the GraphQL APIs, GeoDB Cities API, which can serve the global city, region, and country data. To use this API, we need to subscribe to it first. We can do this by clicking on the Subscribe to Test button.

When you click the button, you will be redirected to the pricing page, which will show the subscription packages for the API. You can select any plan which fits your requirements. Once subscribed, you will get an API key named x-rapidapi-key, which you can use to access the API.

API Playground

RapidAPI Hub provides an API playground where you can test all endpoints and check their responses; within your browser. For faster integration, it automatically creates code snippets to request the API in multiple languages. You can copy these snippets and use them in your application right away. It saves a lot of time.

Query Formulation and Testing

For GraphQL APIs, RapidAPI Hub has a dedicated field for testing and formulating your queries. Let's say I wanted to test the following query, which fetches a given country's details:

countries(namePrefix: "America") {
edges {
node {

Let's test it. On the endpoints page, scroll down to find a text section where you can enter your GraphQL query. Copy the GraphQL query above and paste it here.

Now, we can go ahead and click the Test Endpoint button to see whether our query works as intended or not. I received the following response with a status code of 200, which means our request was successful.

"name":"United States of America",
"capital":"Washington, D.C.",

Integration using Code Snippets

All your changes to the query or its variables get synched in the auto-generated code snippets. So, when you are finished with testing, you can simply copy the snippet you need and integrate it into your application. Finally, using RapidAPI's key, you will be able to access the graphQL API and get your requests served.