GraphQL API
AIMatrix GraphQL API provides a flexible, efficient way to query and mutate data with strong typing and introspection capabilities.
Overview
The GraphQL API offers several advantages over REST:
- Single endpoint for all operations
- Flexible queries - request exactly the data you need
- Strong typing with schema introspection
- Real-time subscriptions for live updates
- Batched requests with automatic query optimization
- Federation support for distributed schemas
Endpoint
GraphQL Endpoint: https://api.aimatrix.com/graphql
WebSocket (Subscriptions): wss://api.aimatrix.com/graphql
GraphQL Playground: https://api.aimatrix.com/graphql/playground
Authentication
Include your API key in the Authorization header:
|
|
Schema Overview
Core Types
Agent
|
|
KnowledgeBase
|
|
DigitalTwin
|
|
Queries
Basic Queries
Get Agent
|
|
List Agents with Filtering
|
|
Variables:
|
|
Complex Nested Query
|
|
Knowledge Base Queries
Search Knowledge
|
|
Variables:
|
|
Digital Twin Queries
Get Twin with Simulations
|
|
Mutations
Agent Mutations
Create Agent
|
|
Variables:
|
|
Update Agent
|
|
Execute Agent
|
|
Variables:
|
|
Knowledge Base Mutations
Create Knowledge Base
|
|
Add Knowledge Source
|
|
Digital Twin Mutations
Create Digital Twin
|
|
Run Simulation
|
|
Variables:
|
|
Subscriptions
Real-time Agent Executions
|
|
Knowledge Base Updates
|
|
Simulation Progress
|
|
Advanced Features
Fragments
|
|
Variables and Directives
|
|
Aliases
|
|
Error Handling
GraphQL Errors
|
|
Partial Errors
|
|
Code Examples
JavaScript/Apollo Client
|
|
Python/GQL
|
|
Subscriptions with WebSocket
|
|
Performance Optimization
Query Optimization
- Use fragments to avoid duplication
- Request only needed fields to reduce payload size
- Implement pagination for large datasets
- Use aliases to batch multiple queries
- Cache queries with proper cache policies
Caching Strategy
|
|
DataLoader Pattern
|
|
Schema Introspection
Get Schema Information
|
|
Get Type Information
|
|
For more examples and advanced GraphQL patterns, see our GraphQL Examples section.