Skip to content

Query your first Subgraph

Read indexed entities and check their freshness with your first authenticated GraphQL query.

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.

Use a deployment that exposes pools, token0, token1, and totalValueLockedUSD, or adapt the query to your Subgraph's schema. 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 a Subgraphs API key, or 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 a Subgraphs API key

Choose your organization, create the key for Subgraphs, and store the plaintext value in your secret manager.

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. The deployment endpoint stays on that version even if the owner publishes an upgrade.

If you want to follow the owner's upgrades, use the separate subgraphId endpoint described in Identifiers and Endpoint Aliases.

Query the deployment

Run a GraphQL query against the Deployment CID endpoint.

curl "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 } }"
  }'

Response

{  "data": {    "pools": [The entities your query selected      {        "id": "0x...",        "token0": { "symbol": "USDC" },        "token1": { "symbol": "WETH" },        "totalValueLockedUSD": "123456789.123"      }    ],    "_meta": {Indexing state behind this result      "block": {        "number": 18000000,Highest indexed block served        "hash": "0x..."      },      "hasIndexingErrors": falseCheck before trusting the data    }  }}
A successful response returns GraphQL data and Subgraph metadata. Values are illustrative; your deployment returns its own pools and block.

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

Next steps