This project automates GraphQL schema processing and natural language query-to-GraphQL generation by:
- Fetching GraphQL schema via introspection.
- Storing the schema in a Neo4j graph database.
- Extracting & indexing types, fields, queries, and mutations.
- Using LLM-based expansion to add synonyms & enrich search capabilities.
- Building FAISS indexes for efficient similarity search.
- Processing user queries in natural language using LLM + FAISS + Neo4j traversal.
- Generating optimized GraphQL queries dynamically.
✅ GraphQL Schema Extraction – Pulls schema via introspection & stores in Neo4j
✅ FAISS Indexing – Creates FAISS indexes for types, fields, queries, and mutations
✅ LLM-Based Enrichment – Uses GPT-4 Turbo to expand schema with synonyms & context
✅ Smart FAISS Search – Matches user queries to schema fields with high accuracy
✅ Query Path Selection – Finds optimal queries & traversal paths in Neo4j
✅ GraphQL Query Generation – Converts results into executable GraphQL queries
✅ Minimal Query Optimization – Ensures efficient & minimal query selection
git clone https://github.com/saurabhbansal123/NeoQueryAI.git
cd NeoQueryAI
Ensure Python 3.8+ is installed, then run:
pip install -r requirements.txt
Use the example configuration:
Edit config/config.ini
and set:
- GraphQL API Endpoint & Access Token
- Neo4j Credentials
- OpenAI API Key
Update config/config.ini
:
[graphql]
graphql_api_url = https://your-graphql-endpoint.com/graphql
graphql_access_token = your_graphql_api_key
[neo4j]
uri = bolt://localhost:7687
username = neo4j
password = your_neo4j_password
[openai]
openai_api_key = your_openai_api_key
Run:
python Process_data.py
This will:
- Fetch schema via introspection
- Store schema as a graph in Neo4j
- Process schema into a structured vocabulary
- Build FAISS indexes
Run:
python GenerateGraphQL.py
This will:
- Use LLM to extract structured fields
- Search for matching GraphQL fields in FAISS
- Identify queries from Neo4j schema
- Optimize query selection & build GraphQL
- Extracts types, fields, queries, mutations from GraphQL API.
- Stores schema as a graph in Neo4j.
- Expands vocabulary with GPT-4 Turbo (synonyms & context).
- Indexes schema using FAISS for fast similarity search.
- User inputs a natural language query (e.g., "Fetch event details").
- LLM extracts relevant GraphQL fields, types, and queries.
- FAISS searches for best schema matches.
- Neo4j finds optimal queries & traversal paths.
- Prioritizes minimal depth & efficient query selection.
- Builds GraphQL query dynamically.
- Returns ready-to-use GraphQL query.
"Fetch event details along with attendees and their emails"
{
"queries": ["Query.eventsConnection", "Query.attendeesConnection"],
"fields": ["Event.id", "Event.name", "Attendee.firstName", "Attendee.email"]
}
query {
eventsConnection {
nodes {
id
name
attendees {
nodes {
firstName
email
}
}
}
}
}
This project is licensed under the Apache 2.0 License.
You may:
- Use, modify, and distribute the software for any purpose.
- Create derivative works and incorporate them into other projects.
- Commercially use the software.
You must:
- Provide proper attribution by crediting the original authors when using this work in derivative or redistributed projects.
- Include a copy of this license in any distribution.
- State any modifications you make to the original source code.
- Not hold the original authors liable for any issues arising from the use of this software.
For full details, see: Apache 2.0 License.
💡 Found a bug? Want to improve this? Contributions are welcome!
Some opportunity areas are already highlighted in the code with a TODO comment.
- Fork the repository
- Create a new branch
git checkout -b feature-branch
- Commit your changes
git commit -m "Added new feature"
- Push your branch
git push origin feature-branch
- Create a Pull Request (PR)
For questions or collaboration:
- GitHub Issues: Open an Issue
- Email: [email protected]