# Query your first Subgraph

Source: https://docs.graphops.xyz/subgraphs/getting-started

Query an existing Subgraph and check how recently its data was indexed. This example reads the
five largest pools by total value locked from a Uniswap-style schema and includes `_meta` for
indexing information.

**Expected result:** five pools and the indexed block in `_meta`. Your endpoint can return
different pools and values as indexing advances.

Use a deployment that exposes `pools`, `token0`, `token1`, and `totalValueLockedUSD`, or adapt the
query to [your Subgraph's schema](./schema-reference). Replace
`<UNISWAP_DEPLOYMENT_CID>` with its Deployment CID, not a Graph Network Subgraph ID.

## Prerequisites

* A GraphOps Platform account.
* An organization with access to Subgraphs.
* An Owner or Developer role to create an API key that includes Subgraphs, or such a key supplied by
your team.
* A public Deployment CID for a Subgraph with the fields used in this example.

### Create an API key \[#create-an-api-key]

[Create API key](https://platform.graphops.xyz/organizations/current/api-keys)

Choose your organization, create a query key that includes Subgraphs, and store the plaintext value in your
secret manager.

### Choose the deployment \[#choose-the-deployment]

Use the Deployment CID published by the Subgraph owner or returned by your Graph CLI deployment.
To find a public dataset and its current Deployment CID, search
[Discover Subgraphs](./guides/discover-public-subgraphs). The deployment
endpoint stays on that version even if the owner publishes an upgrade.

The separate `subgraphId` endpoint follows the owner's upgrades, but moves to each new version
before it is indexed. Before you build on either one, see
[Choose your Subgraph setup](./choose-a-setup).

### Query the deployment \[#query-the-deployment]

Run a GraphQL query against the Deployment CID endpoint.

CLI · curl

Prerequisites

1. Set GRAPHOPS\_API\_KEY to your GraphOps API key.

2. Replace `<UNISWAP_DEPLOYMENT_CID>` with the Deployment CID of a Uniswap-style Subgraph.

[Example project](/examples/subgraphs.getting-started.sh-1.tar.gz)

```sh
curl --fail-with-body --silent --show-error "https://subgraphs.graphops.xyz/v1/deploymentCID/<UNISWAP_DEPLOYMENT_CID>" \
  -H "Authorization: Bearer ${GRAPHOPS_API_KEY}" \
  -H "Content-Type: application/json" \
  --data '{
    "query": "query TopPools { pools(first: 5, orderBy: totalValueLockedUSD, orderDirection: desc) { id token0 { symbol } token1 { symbol } totalValueLockedUSD } _meta { block { number hash } hasIndexingErrors } }"
  }'

```

Output

```json
{
  "data": {
    "pools": [
      {
        "id": "0x277667eb3e34f134adf870be9550e9f323d0dc24",
        "token0": {
          "symbol": "ease.org"
        },
        "token1": {
          "symbol": "ez-cvxsteCRV"
        },
        "totalValueLockedUSD": "1110167010695.785900004139211677005"
      },
      {
        "id": "0x8c0411f2ad5470a66cb2e9c64536cfb8dcd54d51",
        "token0": {
          "symbol": "ease.org"
        },
        "token1": {
          "symbol": "ez-yvCurve-IronBank"
        },
        "totalValueLockedUSD": "1432077483.208630196467118329099649"
      },
      {
        "id": "0x055284a4ca6532ecc219ac06b577d540c686669d",
        "token0": {
          "symbol": "ease.org"
        },
        "token1": {
          "symbol": "ez-SLP-WBTC-WETH"
        },
        "totalValueLockedUSD": "1322031013.848042060988788389158996"
      },
      {
        "id": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
        "token0": {
          "symbol": "USDC"
        },
        "token1": {
          "symbol": "WETH"
        },
        "totalValueLockedUSD": "385191775.1218005724860114722196234"
      },
      {
        "id": "0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8",
        "token0": {
          "symbol": "USDC"
        },
        "token1": {
          "symbol": "WETH"
        },
        "totalValueLockedUSD": "321144439.2777974484977405304295032"
      }
    ],
    "_meta": {
      "block": {
        "number": 26285620,
        "hash": "0x7931a9fc337c615e67690a3083685a5680a72653718c13451f7697ea856b14f3"
      },
      "hasIndexingErrors": false
    }
  }
}
```

The entities your query selected

Indexing state behind this result

Highest indexed block served

Check before trusting the data

TypeScript · fetch

Prerequisites

1. Install Node.js.

2. Install tsx. `npm install tsx`

3. Set GRAPHOPS\_API\_KEY to your GraphOps API key.

4. Replace `<UNISWAP_DEPLOYMENT_CID>` with the Deployment CID of a Uniswap-style Subgraph.

Tested with Node.js 24.22.1, tsx 4.23.15.

[Example project](/examples/subgraphs.getting-started.ts-2.tar.gz)

```typescript
export {};

const response = await fetch(
  "https://subgraphs.graphops.xyz/v1/deploymentCID/<UNISWAP_DEPLOYMENT_CID>",
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.GRAPHOPS_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query: `
        query TopPools {
          pools(first: 5, orderBy: totalValueLockedUSD, orderDirection: desc) {
            id
            token0 { symbol }
            token1 { symbol }
            totalValueLockedUSD
          }
          _meta {
            block { number hash }
            hasIndexingErrors
          }
        }
      `,
    }),
  },
);
if (!response.ok) throw new Error(await response.text());

const result = await response.json();
console.log(JSON.stringify(result.data.pools));

```

Output

```json
[
  {
    "id": "0x277667eb3e34f134adf870be9550e9f323d0dc24",
    "token0": {
      "symbol": "ease.org"
    },
    "token1": {
      "symbol": "ez-cvxsteCRV"
    },
    "totalValueLockedUSD": "1110167010695.785900004139211677005"
  },
  {
    "id": "0x8c0411f2ad5470a66cb2e9c64536cfb8dcd54d51",
    "token0": {
      "symbol": "ease.org"
    },
    "token1": {
      "symbol": "ez-yvCurve-IronBank"
    },
    "totalValueLockedUSD": "1432077483.208630196467118329099649"
  },
  {
    "id": "0x055284a4ca6532ecc219ac06b577d540c686669d",
    "token0": {
      "symbol": "ease.org"
    },
    "token1": {
      "symbol": "ez-SLP-WBTC-WETH"
    },
    "totalValueLockedUSD": "1322031013.848042060988788389158996"
  },
  {
    "id": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
    "token0": {
      "symbol": "USDC"
    },
    "token1": {
      "symbol": "WETH"
    },
    "totalValueLockedUSD": "385191775.1218005724860114722196234"
  },
  {
    "id": "0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8",
    "token0": {
      "symbol": "USDC"
    },
    "token1": {
      "symbol": "WETH"
    },
    "totalValueLockedUSD": "321144439.2777974484977405304295032"
  }
]
```

Up to five pools, ordered by total value locked at block 18,000,000

Go · net/http

Prerequisites

1. Install Go.

2. Set GRAPHOPS\_API\_KEY to your GraphOps API key.

3. Replace `<UNISWAP_DEPLOYMENT_CID>` with the Deployment CID of a Uniswap-style Subgraph.

Tested with Go 1.26.0.

[Example project](/examples/subgraphs.getting-started.go-5.tar.gz)

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"time"
)

func main() {
	payload, err := json.Marshal(struct {
		Query string `json:"query"`
	}{
		Query: `
        query TopPools {
          pools(first: 5, orderBy: totalValueLockedUSD, orderDirection: desc) {
            id
            token0 { symbol }
            token1 { symbol }
            totalValueLockedUSD
          }
          _meta {
            block { number hash }
            hasIndexingErrors
          }
        }
        `,
	})
	if err != nil {
		log.Fatal(err)
	}

	req, err := http.NewRequest(http.MethodPost,
		"https://subgraphs.graphops.xyz/v1/deploymentCID/<UNISWAP_DEPLOYMENT_CID>", bytes.NewReader(payload))
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("GRAPHOPS_API_KEY"))
	req.Header.Set("Content-Type", "application/json")

	resp, err := (&http.Client{Timeout: 30 * time.Second}).Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	if resp.StatusCode < 200 || resp.StatusCode > 299 {
		log.Fatalf("HTTP %d: %s", resp.StatusCode, body)
	}

	var result struct {
		Data struct {
			Pools json.RawMessage `json:"pools"`
		} `json:"data"`
	}
	if err := json.Unmarshal(body, &result); err != nil {
		log.Fatal(err)
	}
	var pools bytes.Buffer
	if err := json.Compact(&pools, result.Data.Pools); err != nil {
		log.Fatal(err)
	}
	fmt.Println(pools.String())
}

```

Output

```json
[
  {
    "id": "0x277667eb3e34f134adf870be9550e9f323d0dc24",
    "token0": {
      "symbol": "ease.org"
    },
    "token1": {
      "symbol": "ez-cvxsteCRV"
    },
    "totalValueLockedUSD": "1110167010695.785900004139211677005"
  },
  {
    "id": "0x8c0411f2ad5470a66cb2e9c64536cfb8dcd54d51",
    "token0": {
      "symbol": "ease.org"
    },
    "token1": {
      "symbol": "ez-yvCurve-IronBank"
    },
    "totalValueLockedUSD": "1432077483.208630196467118329099649"
  },
  {
    "id": "0x055284a4ca6532ecc219ac06b577d540c686669d",
    "token0": {
      "symbol": "ease.org"
    },
    "token1": {
      "symbol": "ez-SLP-WBTC-WETH"
    },
    "totalValueLockedUSD": "1322031013.848042060988788389158996"
  },
  {
    "id": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
    "token0": {
      "symbol": "USDC"
    },
    "token1": {
      "symbol": "WETH"
    },
    "totalValueLockedUSD": "385191956.8055480088623983061845949"
  },
  {
    "id": "0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8",
    "token0": {
      "symbol": "USDC"
    },
    "token1": {
      "symbol": "WETH"
    },
    "totalValueLockedUSD": "321144439.2777974484977405304295032"
  }
]
```

Up to five pools, ordered by total value locked at block 18,000,000

Rust · reqwest

Prerequisites

1. Install Rust.

2. Install reqwest, serde\_json, and tokio. `cargo add reqwest serde_json tokio -F reqwest/json -F tokio/macros -F tokio/rt-multi-thread`

3. Set GRAPHOPS\_API\_KEY to your GraphOps API key.

4. Replace `<UNISWAP_DEPLOYMENT_CID>` with the Deployment CID of a Uniswap-style Subgraph.

Tested with Rust 1.98.1, reqwest 0.13.5, serde\_json 1.0.145, tokio 1.48.0.

[Example project](/examples/subgraphs.getting-started.rust-6.tar.gz)

```rust
use serde_json::{json, Value};
use std::{env, error::Error, time::Duration};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let response = reqwest::Client::new()
        .post("https://subgraphs.graphops.xyz/v1/deploymentCID/<UNISWAP_DEPLOYMENT_CID>")
        .bearer_auth(env::var("GRAPHOPS_API_KEY")?)
        .timeout(Duration::from_secs(30))
        .json(&json!({
            "query": r#"
        query TopPools {
          pools(first: 5, orderBy: totalValueLockedUSD, orderDirection: desc) {
            id
            token0 { symbol }
            token1 { symbol }
            totalValueLockedUSD
          }
          _meta {
            block { number hash }
            hasIndexingErrors
          }
        }
        "#,
        }))
        .send()
        .await?
        .error_for_status()?;
    let result: Value = response.json().await?;
    println!("{}", result["data"]["pools"]);
    Ok(())
}

```

Output

```json
[
  {
    "id": "0x277667eb3e34f134adf870be9550e9f323d0dc24",
    "token0": {
      "symbol": "ease.org"
    },
    "token1": {
      "symbol": "ez-cvxsteCRV"
    },
    "totalValueLockedUSD": "1110167010695.785900004139211677005"
  },
  {
    "id": "0x8c0411f2ad5470a66cb2e9c64536cfb8dcd54d51",
    "token0": {
      "symbol": "ease.org"
    },
    "token1": {
      "symbol": "ez-yvCurve-IronBank"
    },
    "totalValueLockedUSD": "1432077483.208630196467118329099649"
  },
  {
    "id": "0x055284a4ca6532ecc219ac06b577d540c686669d",
    "token0": {
      "symbol": "ease.org"
    },
    "token1": {
      "symbol": "ez-SLP-WBTC-WETH"
    },
    "totalValueLockedUSD": "1322031013.848042060988788389158996"
  },
  {
    "id": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
    "token0": {
      "symbol": "USDC"
    },
    "token1": {
      "symbol": "WETH"
    },
    "totalValueLockedUSD": "385191775.1218005724860114722196234"
  },
  {
    "id": "0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8",
    "token0": {
      "symbol": "USDC"
    },
    "token1": {
      "symbol": "WETH"
    },
    "totalValueLockedUSD": "321144439.2777974484977405304295032"
  }
]
```

Up to five pools, ordered by total value locked at block 18,000,000

Python · requests

Prerequisites

1. Install Python.

2. Install requests. `python -m pip install requests`

3. Set GRAPHOPS\_API\_KEY to your GraphOps API key.

4. Replace `<UNISWAP_DEPLOYMENT_CID>` with the Deployment CID of a Uniswap-style Subgraph.

Tested with Python 3.12.12, requests 2.34.2.

[Example project](/examples/subgraphs.getting-started.python-4.tar.gz)

```python
import json
import os

import requests

response = requests.post(
    "https://subgraphs.graphops.xyz/v1/deploymentCID/<UNISWAP_DEPLOYMENT_CID>",
    headers={
        "Authorization": f"Bearer {os.environ['GRAPHOPS_API_KEY']}",
    },
    json={
        "query": """
        query TopPools {
          pools(first: 5, orderBy: totalValueLockedUSD, orderDirection: desc) {
            id
            token0 { symbol }
            token1 { symbol }
            totalValueLockedUSD
          }
          _meta {
            block { number hash }
            hasIndexingErrors
          }
        }
        """
    },
    timeout=30,
)
response.raise_for_status()
print(json.dumps(response.json()["data"]["pools"]))

```

Output

```json
[
  {
    "id": "0x277667eb3e34f134adf870be9550e9f323d0dc24",
    "token0": {
      "symbol": "ease.org"
    },
    "token1": {
      "symbol": "ez-cvxsteCRV"
    },
    "totalValueLockedUSD": "1110167010695.785900004139211677005"
  },
  {
    "id": "0x8c0411f2ad5470a66cb2e9c64536cfb8dcd54d51",
    "token0": {
      "symbol": "ease.org"
    },
    "token1": {
      "symbol": "ez-yvCurve-IronBank"
    },
    "totalValueLockedUSD": "1432077483.208630196467118329099649"
  },
  {
    "id": "0x055284a4ca6532ecc219ac06b577d540c686669d",
    "token0": {
      "symbol": "ease.org"
    },
    "token1": {
      "symbol": "ez-SLP-WBTC-WETH"
    },
    "totalValueLockedUSD": "1322031013.848042060988788389158996"
  },
  {
    "id": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
    "token0": {
      "symbol": "USDC"
    },
    "token1": {
      "symbol": "WETH"
    },
    "totalValueLockedUSD": "385191775.1218005724860114722196234"
  },
  {
    "id": "0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8",
    "token0": {
      "symbol": "USDC"
    },
    "token1": {
      "symbol": "WETH"
    },
    "totalValueLockedUSD": "321144439.2777974484977405304295032"
  }
]
```

Up to five pools, ordered by total value locked at block 18,000,000

GraphQL reports query problems in an `errors` array, often with HTTP status `200`. If the response
has `errors` instead of `data`, compare the field names with the deployment's schema in
[Schema reference](./schema-reference). For `401` or `404` responses, see
[Troubleshooting](./troubleshooting).

## Next steps

* [Manage Endpoint Aliases](./guides/manage-aliases): Give the endpoint a stable name your application can keep across releases.
* [Paginate results](./guides/paginate-results): Read a larger result set in bounded pages a worker can resume.
* [Managed Subgraphs](./managed-subgraphs): Have GraphOps index your own Subgraph and prepare upgrades.