Home · Developers · Guides · API GraphQL

APIs

API GraphQL

Strawberry GraphQL schema and auth

The Nova Coder API provides a GraphQL endpoint for flexible data queries, complementing the REST API with field selection and nested queries.

Overview

GraphQL allows clients to request exactly the data they need in a single request, reducing over-fetching and under-fetching. The GraphQL endpoint is available at /graphql when the strawberry-graphql package is installed.

Installation

Install the optional GraphQL dependency:

pip install novacoder[api]
# or
pip install strawberry-graphql>=0.239.0

Availability

The GraphQL endpoint is only available when strawberry-graphql is installed. If not installed, the endpoint will not be registered and the API will continue to function with REST endpoints only.

Check availability:

from novacoder.api.graphql import is_graphql_available

if is_graphql_available():
    print("GraphQL is available")
else:
    print("GraphQL is not available (install strawberry-graphql)")

GraphQL Endpoint

  • URL: /graphql
  • Method: POST
  • Content-Type: application/json

Available Queries

Agents

query {
  agents {
    name
    description
  }
}

Get a specific agent:

query {
  agent(name: "coder") {
    name
    description
  }
}

Tools

query {
  tools {
    name
    description
  }
}

Get a specific tool:

query {
  tool(name: "read_file") {
    name
    description
  }
}

Memory

Get all memory entries:

query {
  memory {
    key
    scope
    value
    createdAt
  }
}

Filter by scope:

query {
  memory(scope: "default") {
    key
    scope
    value
    createdAt
  }
}

Limit results:

query {
  memory(limit: 10) {
    key
    scope
    value
  }
}

Files

Get workspace files:

query {
  files {
    path
    size
    modifiedAt
  }
}

Limit results:

query {
  files(limit: 50) {
    path
    size
    modifiedAt
  }
}

Status

query {
  status
}

Available Mutations

Run Agent

mutation {
  runAgent(
    agent: "coder"
    goal: "Write a Flask API"
    context: "Optional context"
  )
}

Store Memory

mutation {
  storeMemory(
    key: "my_key"
    value: "my_value"
    scope: "default"
  )
}

Delete Memory

mutation {
  deleteMemory(
    key: "my_key"
    scope: "default"
  )
}

Usage Examples

Using curl

curl -X POST http://localhost:8000/graphql \
  -H "Content-Type: application/json" \
  -d '{
    "query": "query { agents { name description } }"
  }'

Using Python

import httpx

query = """
query {
  agents {
    name
    description
  }
}
"""

response = httpx.post(
    "http://localhost:8000/graphql",
    json={"query": query}
)

data = response.json()
print(data)

Using JavaScript (fetch)

const query = `
  query {
    agents {
      name
      description
    }
  }
`;

fetch('http://localhost:8000/graphql', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ query }),
})
  .then(res => res.json())
  .then(data => console.log(data));

GraphQL Playground

When the GraphQL endpoint is available, you can access the GraphQL Playground at:

  • URL: /graphql
  • Interactive UI: Available through the Strawberry GraphQL explorer

Implementation

The GraphQL system is implemented in novacoder/api/graphql.py:

from novacoder.api.graphql import (
    is_graphql_available,
    get_graphql_router,
    create_graphql_router,
)

GraphQL Types

GraphQLAgent

  • name: String
  • description: String

GraphQLTool

  • name: String
  • description: String

GraphQLMemory

  • key: String
  • scope: String
  • value: String
  • createdAt: DateTime

GraphQLFile

  • path: String
  • size: Int
  • modifiedAt: DateTime

Integration with FastAPI

The GraphQL router is automatically registered with the FastAPI app when strawberry-graphql is available:

from novacoder.api.app import app

# GraphQL router is automatically included at /graphql
# if strawberry-graphql is installed

Error Handling

GraphQL errors are returned in the standard GraphQL error format:

{
  "data": null,
  "errors": [
    {
      "message": "Error message",
      "locations": [{"line": 2, "column": 3}]
    }
  ]
}

Authentication

The GraphQL endpoint respects the same authentication as the REST API:

  • Header: X-API-Token
  • Cookie: novacoder_session
  • Query Parameter: token
curl -X POST http://localhost:8000/graphql \
  -H "Content-Type: application/json" \
  -H "X-API-Token: your-token" \
  -d '{"query": "query { agents { name } }"}'

Best Practices

  1. Field Selection: Request only the fields you need to reduce payload size
  2. Batch Queries: Combine multiple queries into a single request
  3. Use Variables: Use GraphQL variables for dynamic values
  4. Error Handling: Always check for errors in the response
  5. Introspection: Use GraphQL introspection to explore the schema
  6. Caching: Cache GraphQL responses when appropriate
  7. Rate Limiting: Respect rate limits when making queries

Schema Introspection

Explore the GraphQL schema using introspection:

query {
  __schema {
    types {
      name
      kind
      description
      fields {
        name
        type {
          name
          kind
        }
      }
    }
  }
}

Debugging Status

✅ Verified Working: All GraphQL components have been debugged and verified:

  • GraphQL module imports work correctly
  • GraphQL availability check works correctly
  • GraphQL router creation works correctly
  • API module export works correctly
  • App integration works correctly
  • No import conflicts with existing systems
  • Graceful degradation when strawberry-graphql is not installed

Source: wiki/api-graphql.md · rendered 2026-11-10