This folder contains the subgraph for the Neo Quick Poll application. The subgraph is designed to index and query data from the Neo Quick Poll smart contract on the NeoX T4 Testnet.
This subgraph fetches and stores data for all polls created on the Neo Quick Poll application. It allows for efficient querying of poll data without directly interacting with the blockchain for every request.
- Decentralized: Aligns with the blockchain ethos of your application.
- Real-time Updates: Automatically syncs with your smart contract events.
- Efficient Querying: Optimized for blockchain data structures.
- Scalability: Can handle large amounts of data and queries efficiently.
- No Need for Additional Backend: Reduces infrastructure complexity.
The main purposes of this subgraph are:
- To index poll data from the blockchain
- To provide fast and efficient data retrieval for the frontend application
- To enable complex queries that would be difficult or expensive to perform directly on the blockchain
The subgraph consists of the following key files:
schema.graphql: Defines the data structure for the subgraphsubgraph.yaml: Configuration file for the subgraphsrc/mapping.ts: Contains the logic for processing blockchain events and storing data
- The subgraph listens for specific events emitted by the Neo Quick Poll smart contract.
- When an event is detected (e.g., a new poll is created or a vote is cast), the subgraph processes this data.
- The processed data is stored according to the schema defined in
schema.graphql. - The frontend can then query this data using GraphQL, allowing for fast and complex data retrieval.
To set up and deploy the subgraph:
-
Install the Graph CLI:
npm install -g @graphprotocol/graph-cli -
Initialize the subgraph (if not already done):
graph init --studio neo-quick-pollFollow the prompts, inputting your contract address and network (NeoX T4 Testnet).
-
Generate code from the schema:
graph codegen -
Build the subgraph:
graph build -
Deploy the subgraph (you'll need to set up a Graph account and create a subgraph name first):
graph deploy --studio neo-quick-poll
Once deployed, you can query the subgraph using GraphQL. Here's a basic example:
{
polls(first: 5) {
id
question
options
votes
}
}This query would return data for the first 5 polls, including their IDs, questions, options, and vote counts.
If you make changes to the smart contract or need to update the subgraph:
- Update the relevant files (
schema.graphql,subgraph.yaml,mapping.ts) - Regenerate code and rebuild:
graph codegen graph build - Redeploy the subgraph:
graph deploy --studio neo-quick-poll
- Ensure that the contract address in
subgraph.yamlmatches your deployed Neo Quick Poll contract on the NeoX T4 Testnet. - The subgraph may take some time to sync with the blockchain after deployment.
For more information on working with subgraphs, refer to The Graph documentation.