# Subgraph data (GraphQL)

## The Graph and GraphQL

The Graph is a decentralized protocol for indexing and querying data from blockchains, starting with Ethereum. What that means: it is an easier way to retrieve specific data from the blockchain, within the ethos of web3, with the advantages of decentralization and reliability.

GraphQL is the underlying query language utilised in The Graph. What is the difference between standard RESTFUL API calls and GraphQL calls? The difference is that traditional APIs require the developers to create specific endpoints for users that return specific data. If the user requires more information, they may need to make multiple API calls, sometimes hundreds of API calls, to get the information they require. With The Graph (which uses GraphQL), only one call is needed to a _subgraph_, as long as the developer has created a flexible schema.

For more information on The Graph and the underlying GraphQL, see [this GraphQL primer](https://medium.com/graphprotocol/graphql-will-power-the-decentralized-web-d7443a69c69a).&#x20;

If you are consuming GraphQL data in your app, we'd recommend using a fully featured package such as [Apollo](https://www.apollographql.com/) or a minimal implementation such as [GraphQL-Request](https://github.com/prisma-labs/graphql-request).

## Aave Arc Subgraph

To view the source of our subgraphs, see [Github repo](https://github.com/aave/protocol-v2-subgraph/tree/feat/aave-arc).

<table><thead><tr><th width="298.27116646747305">Tools</th><th>Link</th></tr></thead><tbody><tr><td>Graph Explorer Playground</td><td><a href="https://thegraph.com/hosted-service/subgraph/aave/aave-arc">https://thegraph.com/hosted-service/subgraph/aave/aave-arc</a></td></tr><tr><td>(HTTP) Query API Endpoint</td><td><a href="https://api.thegraph.com/subgraphs/name/aave/aave-arc">https://api.thegraph.com/subgraphs/name/aave/aave-arc</a></td></tr><tr><td>(WS) Subscription API Endpoint </td><td>wss://api.thegraph.com/subgraphs/name/aave/aave-arc</td></tr></tbody></table>

### How to use the playground



If you visit the above **playground** link in your browser, you will be taken to The Graph’s playground, where you can easily construct and test GraphQL queries.&#x20;

* To execute your query, select the purple play button.&#x20;
* The query results will be returned in the middle column.&#x20;
* To find out what data is available, use the ‘Schema’ column on the right, which can be explored to discover the underlying data.&#x20;
* You can also type in the left column and use the auto-complete to find the correct query/types.

### Common Gotchas



* All address values (e.g. when used for `id`) must be in **lower case** format.
* The ID of reserves is the address of the asset and the address of the market's LendingPoolAddressProvider, in lower case.
* When using the **raw** endpoints, depending on the type of numeric value queried, it will be returned either in `wei` units (i.e. 10^18), the decimals of the asset itself (i.e. 10^6 for USDC), or `ray` units (i.e. 10^27).
* Each results 'page' returns 100 entries by default. This can be increased to a maximum of 1000 entries per page.
  * E.g. to list the next 1000 entries, append something similar to: `(skip:1000, first: 1000)` to your query's parameters.
  * This also applies to nested entries, such as arrays.
* All data on our Graph endpoint is static. Therefore to get the latest balance of a user (which includes the interest earned up to that second), you would need to either calculate it yourself or make a `balanceOf()` call to the _aToken contract._

## Accessing GraphQL data from your app

The **recommended** way is to use a client library that can take care of the 'plumbing' to ensure you have up to date data (with caching sometimes included). Internally we use Apollo, but there are many options depending on your programming language, see the official GraphQL page.

If for some reason you cannot use a client library (e.g. querying via Postman), then you can create a POST request to our subgraph's HTTP endpoint, with header: `Content-Type: application/json` and the body consisting of your query on one line in quotations. For example:

```graphql
{"query": "{ reserves (where: {usageAsCollateralEnabled: true})  { id name price {id} liquidityRate variableBorrowRate stableBorrowRate}}" }
```

##
