Generate GraphQL Queries from Subgraph Hashes with AI

This Dify workflow acts as an intelligent GraphQL query generator for blockchain subgraphs. It takes a user's question and a subgraph IPFS hash, leverages OpenAI to construct a precise query, and automatically executes it to fetch on-chain data. The workflow includes a robust multi-retry mechanism, ensuring the highest possible success rate in data retrieval for your Web3 development needs.

    image for Generate GraphQL Queries from Subgraph Hashes with AI

    Workflow Overview

    What is this?

    What is this?

    This workflow is a powerful tool for developers that automates the generation of GraphQL queries. By providing a subgraph IPFS hash and a question in natural language, the system uses an AI model (GPT-4o-mini) to intelligently construct the correct GraphQL query and fetch the desired on-chain data.
    What problem does it solve?

    What problem does it solve?

    Tired of manually inspecting subgraph schemas and writing complex, trial-and-error GraphQL queries? This workflow eliminates that time-consuming and error-prone process, especially when dealing with unfamiliar or poorly documented subgraphs.
    What will you get?

    What will you get?

    Accelerate your Web3 development by instantly generating queries instead of writing them by hand. Increase data retrieval reliability with an automated, multi-attempt retry logic across different subgraphs. Reduce development friction by interacting with blockchain data using plain English questions. Simplify your dApp or analytics workflow by abstracting away the complexity of GraphQL syntax.

    Apps Included

    • OpenAI Chat Model
    • GitHub
    • GraphQL
    • Information Extractor
    • Sticky Note
    • If
    • HTTP Request
    • Start

    How to Use

    Prerequisites

    Setup Steps

    1

    Import the Workflow

    Download the workflow's YML file and import it into your Dify application.

    2

    Configure LLM Provider

    Navigate to the LLM nodes within the workflow (e.g., 'Generate GraphQL Query') and ensure your OpenAI provider is selected and the API key is correctly configured.

    3

    Set Up Input Variables

    In the 'Start' node, review the input variables. The primary inputs you will use are `subgraph_ipfs_hash` and `question`. The other `subgraph_ipfs_hash_2` and `_3` are for the retry logic.

    4

    Run and Test

    Save the workflow and run it with a test case. Provide a valid subgraph IPFS hash and a clear question to verify that the workflow executes successfully and returns the expected data.

    Pro Tips

    1
    For complex queries, be as specific as possible in your 'question' to guide the AI more effectively. Include details like desired timeframes or specific entities.
    2
    You can customize the 'Failure Summary' LLM node to send notifications to Slack or Discord, allowing you to monitor and debug failed query attempts in real-time.
    3
    To improve performance, consider replacing the gpt-4o-mini model with a more powerful one like GPT-4 if your queries are highly complex and require deeper schema understanding.

    Information

    • Published date8/15/2025
    • Last updated8/15/2025

    Platform