-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.py
More file actions
89 lines (76 loc) · 2.82 KB
/
Copy pathexample_usage.py
File metadata and controls
89 lines (76 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""Example usage of Data GraphQL Agent.
This script demonstrates how to use the agent to generate a GraphQL API
from BigQuery queries.
"""
import asyncio
import os
from pathlib import Path
from data_graphql_agent.mcp.handlers import handle_generate_graphql_api
async def main() -> None:
"""Generate example GraphQL API."""
# Define sample queries
arguments = {
"queries": [
{
"queryName": "trendingItems",
"sql": """
SELECT
item_name,
SUM(sales) as total_sales,
AVG(price) as avg_price
FROM `project.dataset.sales`
GROUP BY item_name
ORDER BY total_sales DESC
LIMIT 10
""",
"source_tables": ["project.dataset.sales"],
},
{
"queryName": "salesByRegion",
"sql": """
SELECT
region,
DATE(sale_date) as date,
SUM(amount) as total_amount,
COUNT(*) as num_transactions
FROM `project.dataset.sales`
GROUP BY region, DATE(sale_date)
ORDER BY date DESC
""",
"source_tables": ["project.dataset.sales"],
},
],
"project_name": "example-analytics",
"output_path": "./output/graphql-server",
}
print("Generating GraphQL API...")
print(f" Project: {arguments['project_name']}")
print(f" Queries: {len(arguments['queries'])}")
print(f" Output: {arguments['output_path']}\n")
# Generate the API
result = await handle_generate_graphql_api(arguments)
# Print results
if result["success"]:
print("✓ Generation successful!")
print(f"\nMessage: {result['message']}")
print(f"\nGenerated files ({len(result['files_generated'])}):")
for file_info in result["files_generated"]:
size_kb = file_info["size_bytes"] / 1024
print(f" - {Path(file_info['path']).name}: {size_kb:.1f} KB")
print("\n" + "="*60)
print("Next steps:")
print("="*60)
print(f"1. cd {arguments['output_path']}")
print("2. npm install")
print("3. Set environment variables in .env file")
print("4. npm run dev")
print("\nOr use Docker:")
print(" docker-compose up --build")
else:
print("✗ Generation failed!")
print(f"Error: {result.get('error', 'Unknown error')}")
if __name__ == "__main__":
# Set required environment variable for example
if not os.getenv("GCP_PROJECT_ID"):
os.environ["GCP_PROJECT_ID"] = "example-project"
asyncio.run(main())