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 keyChoose 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 } }"
}'const response = await fetch(
"https://subgraphs.graphops.xyz/v1/deploymentCID/<UNISWAP_DEPLOYMENT_CID>",
{
method: "POST",
headers: {
Authorization: "Bearer <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
}
}
`,
}),
},
);
const result = await response.json();
console.log(result.data.pools);import { GraphQLClient, gql } from "graphql-request";
const client = new GraphQLClient(
"https://subgraphs.graphops.xyz/v1/deploymentCID/<UNISWAP_DEPLOYMENT_CID>",
{
headers: {
Authorization: "Bearer <GRAPHOPS_API_KEY>",
},
},
);
const query = gql`
query TopPools {
pools(first: 5, orderBy: totalValueLockedUSD, orderDirection: desc) {
id
token0 { symbol }
token1 { symbol }
totalValueLockedUSD
}
_meta {
block { number hash }
hasIndexingErrors
}
}
`;
const result = await client.request(query);
console.log(result.pools);import requests
response = requests.post(
"https://subgraphs.graphops.xyz/v1/deploymentCID/<UNISWAP_DEPLOYMENT_CID>",
headers={
"Authorization": "Bearer <GRAPHOPS_API_KEY>",
"Content-Type": "application/json",
},
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(response.json()["data"]["pools"])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 } }}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.