How to use GraphQL with Python, Javascript, and Ruby
Tags: product, tutorial, bitqueryapis, graphql
Published: 2020-10-29 15:26:19

---
title: How to use GraphQL with Python, Javascript, and Ruby
published: true
date: 2020-10-15 17:56:45 UTC
tags: Product,Tutorial,bitqueryapis,graphql
canonical_url: https://bitquery.io/blog/graphql-with-python-javascript-and-ruby?utm_source=rss&utm_medium=rss&utm_campaign=graphql-with-python-javascript-and-ruby
---

In the last few articles, we talked argued [using GraphQL APIs for blockchain](https://bitquery.io/blog/blockchain-graphql) data and how to create your first [blockchain GraphQL](https://bitquery.io/blog/blockchain-graphql-query) query. In this article, we will show how to call GraphQL APIs using different programming languages. 

However, you should always use our [GraphQL playground](https://graphql.bitquery.io/) to create and test your queries before embedding in your code.


## Basics

Before starting, let’s cover some basics.

- All GraphQL requests are [POST method](https://en.wikipedia.org/wiki/POST_%28HTTP%29).
- In GraphQL APIs endpoint remain the same for all the requests
- Our GraphQL endpoint is — [https://graphql.bitquery.io/](https://graphql.bitquery.io/)

We will be using the following GraphQL query in all our examples.

```
query{
  bitcoin{
    blocks{
      count
    }
   }
}
```

Now let’s see how to call GraphQL APIs using different programming languages.

## GraphQL APIs using cURL

[cURL](https://en.wikipedia.org/wiki/CURL) allows using [HTTP methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) directly through our terminal. It is best for quick testing of any API request.

```
curl \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{ "query": "{ bitcoin { blocks {count} } }" }' \
https://graphql.bitquery.io/
```

## GraphQL APIs using Python

Python is a beginner-friendly programming language. The example below shows how to call a GraphQL API using python.

<script src="https://gist.github.com/buddies2705/f0fbc1a4fa2a0835c7e3758f34cabb30.js"></script><noscript><a href="https://gist.github.com/buddies2705/f0fbc1a4fa2a0835c7e3758f34cabb30">View this gist on GitHub</a></noscript>

### GraphQL Python Libraries 

The libraries below are the most widely used libraries using GraphQL with python.

- [Graphene](https://graphene-python.org/) — Graphene is an opinionated Python library for building GraphQL schemas/types fast and easily.
- [Ariadne](https://ariadnegraphql.org/) — Ariadne is a Python library for implementing GraphQL servers using a schema-first approach.
- [Strawberry](https://strawberry.rocks/) — Strawberry is a new GraphQL library for Python 3, inspired by data classes.

## GraphQL APIs using Javascript

Javascript is one of the most adopted programming languages among developers all over the world. You can call a post request to get results from GraphQL APIs.

<script src="https://gist.github.com/buddies2705/be44d25c50bb76f04a148d37593902f8.js"></script><noscript><a href="https://gist.github.com/buddies2705/be44d25c50bb76f04a148d37593902f8">View this gist on GitHub</a></noscript>

### GraphQL Javascript(NodeJS) Libraries

The following are the most popular javascript libraries for GraphQL.

- [GraphQL.js](https://github.com/graphql/graphql-js) — The JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook.
- [graphql-request](https://www.npmjs.com/package/graphql-request) — Minimal GraphQL client supporting Node and browsers for scripts or simple apps.
- [Apollo client](https://www.npmjs.com/package/@apollo/client) — Apollo Client is a fully-featured caching GraphQL client with integrations for React, Angular, and more. It allows you to build UI components that fetch data via GraphQL easily.

## GraphQL APIs using Ruby

Ruby is also one of the most simple programming languages. The following example shows how to call a GraphQL API using ruby. 

<script src="https://gist.github.com/buddies2705/758ec13469e44e944e787b94fde41869.js"></script><noscript><a href="https://gist.github.com/buddies2705/758ec13469e44e944e787b94fde41869">View this gist on GitHub</a></noscript>

### GraphQL Ruby Libraries

You can use the libraries below to use GraphQL with ruby.

- [graphql-ruby](https://github.com/rmosolgo/graphql-ruby) — Ruby implementation of Facebook’s GraphQL.
- [graphql-client](https://github.com/github/graphql-client) — A Ruby library for declaring, composing, and executing GraphQL queries.
- [graphql-batch](https://github.com/Shopify/graphql-batch) — A query batching executor for the graphql gem.
- [agoo](https://github.com/ohler55/agoo) — Ruby web server that implements Facebook’s GraphQL.
- [GQLi](https://github.com/contentful-labs/gqli.rb) — A GraphQL client and DSL. Allowing to write queries in native Ruby.

## Additional Resources

To see the examples of other programming languages, check the official [website of GraphQL](https://graphql.org/code/). In addition, to learn more about more GraphQL tools and libraries, check [Awesome GraphQL](https://github.com/chentsulin/awesome-graphql).

If you have any questions or need help with your blockchain investigation, just hop on our [Telegram channel](https://t.me/Bloxy_info). Also, let us know if you are looking for blockchain data APIs.

You might also be interested in:

- [Create your first Blockchain GraphQL query](https://bitquery.io/blog/blockchain-graphql-query)
- [API to get Ethereum Smart Contract Events](https://bitquery.io/blog/ethereum-events-api)
- [Why GraphQL is better for blockchain data APIs](https://bitquery.io/blog/blockchain-graphql)
- [APIs to get Latest Uniswap Pair Listing](https://bitquery.io/blog/uniswap-pool-api)
- [Simple rest APIs to get Uniswap data (DEX Data APIs)](https://bitquery.io/blog/dex-data-apis)
- [API to Get Ethereum Token Balance](https://bitquery.io/blog/etheruem-token-api)
- [Simple API To Get Ethereum Supply And Data](https://bitquery.io/blog/get-ethereum-total-supply)
- [How to investigate an Ethereum address?](https://bitquery.io/blog/investigate-ethereum-address)
- [Who is actually using Ethereum?](https://bitquery.io/blog/who-is-actually-using-ethereum)
- [How to get newly created Ethereum Tokens?](https://bitquery.io/blog/newly-created-etheruem-token)
- [Querying Binance Smart Chain (BSC)](https://bitquery.io/blog/binance-smart-chain-api)

#### **About** Bitquery

[**Bitquery**](https://bitquery.io/?source=blog&utm_medium=about_coinpath) is a set of software tools that parse, index, access, search, and use information across blockchain networks in a unified way. Our products are:

- **[Coinpath®](https://bitquery.io/products/coinpath?utm_source=blog) APIs** provide [blockchain money flow analysis](https://blog.bitquery.io/coinpath-blockchain-money-flow-apis) for more than 24 blockchains. With Coinpath’s APIs, you can monitor blockchain transactions, investigate crypto crimes such as bitcoin money laundering, and create crypto forensics tools. Read [this to get started with Coinpath®](https://blog.bitquery.io/coinpath-api-get-start).

- **[Digital Assets API](https://bitquery.io/products/digital_assets?utm_source=blog&utm_medium=about)** provides index information related to all major cryptocurrencies, coins, and tokens. 

- **[DEX API](https://bitquery.io/products/dex?utm_source=blog&utm_medium=about)** provides real-time deposits and transactions, trades, and other related data on different DEX protocols like Uniswap, Kyber Network, Airswap, Matching Network, etc.

If you have any questions about our products, ask them on our [Telegram channel](https://t.me/Bloxy_info) or email us at [hello@bitquery.io](mailto:hello@bitquery.io). Also, subscribe to our newsletter below, we will keep you updated with the latest in the cryptocurrency world.

The post [How to use GraphQL with Python, Javascript, and Ruby](https://bitquery.io/blog/graphql-with-python-javascript-and-ruby) appeared first on [Bitquery](https://bitquery.io).