🔍

Perform Query

After deploying your subgraph, you can easily access and query it via GraphQL playground for query. You can open the "GraphQL API" link in your dashboard to access your data.
Deployed subgraphs
For example, you may access the publicly available Aave-v2 subgraph on Ethereum mainnet at http://api.0xgraph.xyz/subgraphs/name/aave/protocol-v2/graphql
Sample subgraph query

2. Query for Subgraph Sync Status

To get to know the sync status directly inside the subgraph, a user may run the following query by using _meta:
{
_meta {
block {
hash
timestamp
number
}
}
}
The result would be similar to the following:
{
"data": {
"_meta": {
"block": {
"hash": "0x9f2480d4a21fb9743ae35d349fccbc86c0fad084d6a87b53d1f649f1051c6ddb",
"timestamp": 1700267031,
"number": 151479342
}
}
}
}

3. Query a subgraph

Subgraphs expose blockchain data via a GraphQL API, making it easy for anyone familiar with the GraphQL language to get started. A GraphQL API differs from traditional REST APIs in that it relies on a schema definition to outline the available queries, mutations, and data types that clients can access. This schema-driven approach enables clients to precisely specify the data they need, eliminating the need to over-fetch data. Here's why this is beneficial:
  • Precision: GraphQL clients can tailor their queries to retrieve only the data they require, enhancing efficiency.
  • Flexibility: Clients can request related data in a single query, reducing the number of API calls needed.
  • Predictability: The schema provides clear documentation for available data and operations.
GraphQL Syntax
GraphQL queries are composed using a specific syntax that allows for hierarchical data retrieval. Clients specify the fields they want to retrieve and their relationships within a single query. This approach minimizes unnecessary data retrieval, resulting in more concise and efficient requests.
Best Practices for GraphQL with 0xgraph
When working with the 0xgraph service, it's essential to follow best practices to ensure optimal performance and efficiency. These best practices are outlined in official Graph Protocol documentation.
For detailed instructions on querying 0xgraph using GraphQL and to ensure adherence to best practices, refer to the official documentation and guidelines provided by the Ormi Labs and Graph Protocol teams. These resources offer valuable insights and recommendations to streamline your interaction with blockchain data through GraphQL. https://thegraph.com/docs/en/querying/querying-best-practices/
Last modified 3mo ago