A natural language to GraphQL query generator using LangChain and LangGraph.
- Natural language to GraphQL query generation
- Schema-aware query validation
- Automatic query execution
- Built-in error handling and retry logic
- Support for complex nested queries
- Integration with OpenAI's GPT models
/
├── /src
│ ├── /agents
│ │ ├── /query-builder # Query generation agent
│ │ └── graph.ts # LangGraph orchestration
│ ├── /tools
│ │ ├── graphql-executor.ts # GraphQL execution tool
│ │ └── query-validator.ts # Query validation tool
│ ├── /scripts
│ │ ├── introspect.ts # Schema introspection
│ │ ├── chat.ts # Basic chat interface
│ │ ├── preview.ts # Preview generated queries
│ │ └── query.ts # Query generation script
│ └── /lib
│ └── /utils # Utility functions
├── /outputs
│ └── schema.json # Introspected GraphQL schema
└── package.json
- Clone the repository
- Install dependencies:
yarn install
- Copy
.env.exampleto.envand fill in your environment variables:cp .env.example .env
- Run the introspection script to fetch the GraphQL schema:
yarn introspect
Generate and execute GraphQL queries from natural language:
yarn query "Show me all launches with their mission names and crew members"The script will:
- Generate a GraphQL query from your natural language request
- Validate the query against the schema
- Execute the query and return results
For interactive query generation:
yarn chatPreview generated queries without executing them:
yarn preview "Show me all launches with their mission names and crew members"OPENAI_API_KEY: Your OpenAI API keyGRAPHQL_API_URL: The URL of your GraphQL APIMODEL_NAME: (Optional) The OpenAI model to use (defaults to gpt-4-turbo-preview)
- Create new agents in
/src/agents - Add new tools in
/src/tools - Update the LangGraph orchestration in
graph.ts - Add new scripts in
/src/scripts
yarn typecheck # Type checking
yarn lint # Linting
yarn format # Code formattingThe system uses a LangGraph-based architecture with specialized agents:
- Query Builder Agent: Generates GraphQL queries from natural language
- Query Validator: Validates queries against the schema
- GraphQL Executor: Executes validated queries
The workflow is orchestrated by a LangGraph that:
- Handles state management
- Implements retry logic for failed validations
- Manages the flow between agents
- Provides error handling and recovery
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT