GraphQL API Reference¶
This document provides a complete reference for the apflow GraphQL API, built on Strawberry GraphQL.
Overview¶
The GraphQL API provides: - Typed schema with full introspection support - Queries for reading tasks and task trees - Mutations for creating, updating, cancelling, and deleting tasks - Subscriptions for real-time task status updates via WebSocket - GraphiQL interactive playground for exploring the schema
Installation¶
Install apflow with the GraphQL extra:
Configuration¶
Set the API protocol to graphql:
Start the server:
The GraphQL endpoint is available at http://localhost:8000/graphql.
Environment Variables¶
| Variable | Type | Default | Description |
|---|---|---|---|
APFLOW_API_PROTOCOL | string | a2a | Set to graphql to enable the GraphQL adapter |
APFLOW_ENABLE_DOCS | boolean | true | Enable GraphiQL interactive playground |
APFLOW_ENABLE_SYSTEM_ROUTES | boolean | true | Enable system info endpoint at /system |
APFLOW_API_HOST | string | 0.0.0.0 | Server host |
APFLOW_API_PORT | integer | 8000 | Server port |
Schema Reference¶
Types¶
TaskType¶
The primary task representation:
type TaskType {
id: String!
name: String!
status: TaskStatusEnum!
priority: Int!
progress: Float!
result: String
error: String
createdAt: DateTime
updatedAt: DateTime
parentId: String
description: String
children: [TaskType!]
}
TaskStatusEnum¶
Input Types¶
CreateTaskInput¶
input CreateTaskInput {
name: String!
description: String
executor: String
priority: Int
inputs: JSON
parentId: String
}
UpdateTaskInput¶
Queries¶
task¶
Fetch a single task by ID.
tasks¶
Fetch a list of tasks with optional filters.
Arguments:
| Argument | Type | Description |
|---|---|---|
status | TaskStatusEnum | Filter by task status |
limit | Int | Maximum number of tasks to return |
offset | Int | Number of tasks to skip |
taskChildren¶
Fetch all child tasks of a parent task.
Mutations¶
createTask¶
Create a new task.
mutation {
createTask(taskInput: {
name: "my_task"
description: "A sample task"
executor: "rest_executor"
priority: 5
inputs: { url: "https://api.example.com/data" }
}) {
id
name
status
}
}
updateTask¶
Update an existing task.
mutation {
updateTask(
taskId: "task-123"
taskInput: {
name: "updated_name"
status: CANCELLED
}
) {
id
name
status
updatedAt
}
}
cancelTask¶
Cancel a running task. Returns true on success.
deleteTask¶
Delete a task. Returns true on success.
Subscriptions¶
taskStatusChanged¶
Subscribe to real-time status updates for a specific task. Emits a TaskType each time the task's status changes. The subscription ends automatically when the task reaches a terminal status (COMPLETED, FAILED, or CANCELLED).
The subscription uses the graphql-transport-ws protocol over WebSocket.
Client Examples¶
Python (httpx)¶
import httpx
# Query a task
query = """
query GetTask($taskId: String!) {
task(taskId: $taskId) {
id
name
status
progress
result
}
}
"""
response = httpx.post(
"http://localhost:8000/graphql",
json={"query": query, "variables": {"taskId": "task-123"}},
)
print(response.json())
Python (create task)¶
import httpx
mutation = """
mutation CreateTask($input: CreateTaskInput!) {
createTask(taskInput: $input) {
id
name
status
}
}
"""
variables = {
"input": {
"name": "my_executor",
"description": "Run a data pipeline",
"priority": 5,
"inputs": {"source": "s3://bucket/data.csv"},
}
}
response = httpx.post(
"http://localhost:8000/graphql",
json={"query": mutation, "variables": variables},
)
print(response.json())
cURL¶
# Query tasks
curl -X POST http://localhost:8000/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "{ tasks(status: PENDING, limit: 5) { id name status priority } }"
}'
# Create a task
curl -X POST http://localhost:8000/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "mutation { createTask(taskInput: { name: \"my_task\" }) { id name status } }"
}'
Authentication¶
The GraphQL adapter supports the same JWT authentication as the A2A and MCP adapters. Include the token in the Authorization header:
curl -X POST http://localhost:8000/graphql \
-H "Authorization: Bearer <your-jwt-token>" \
-H "Content-Type: application/json" \
-d '{"query": "{ tasks { id name status } }"}'
See the API Server Guide for token generation details.
GraphiQL Playground¶
When APFLOW_ENABLE_DOCS=true (the default), opening http://localhost:8000/graphql in a browser loads the GraphiQL interactive playground. Use it to:
- Explore the schema with auto-complete
- Run queries and mutations interactively
- View type documentation inline
- Test subscriptions
To disable GraphiQL in production:
Protocol Comparison¶
| Feature | A2A (HTTP) | MCP | GraphQL |
|---|---|---|---|
| Protocol | JSON-RPC over HTTP | JSON-RPC (HTTP/stdio) | GraphQL over HTTP/WS |
| Schema | Agent Card discovery | Tool/Resource listing | Full introspection |
| Streaming | SSE / WebSocket | N/A | Subscriptions (WS) |
| Best for | Agent-to-agent communication | LLM tool integration | Frontend apps, typed APIs |
| Install extra | apflow[a2a] | apflow[a2a] | apflow[graphql] |
See Also¶
- API Server Guide - Server setup and protocol selection
- HTTP API Reference - A2A Protocol HTTP API
- Python API Reference - Python library API
- Environment Variables - All configuration options