A simple Express server that wraps the Ollama REST API (localhost:11434) with GraphQL. Supports both streaming and non-streaming for the generate endpoint.
- Node.js 18+
- Ollama running locally (
ollama serve)
npm installDevelopment (with hot reload):
npm run devProduction:
npm run build
npm startThe server runs at http://localhost:4000/graphql by default. GraphiQL Playground is available for testing.
OLLAMA_BASE_URL- Ollama API base URL (default:http://localhost:11434)PORT- Server port (default:4000)
query {
listModels {
models {
name
size
digest
details {
family
parameter_size
}
}
}
}mutation {
generate(input: {
model: "gemma3"
prompt: "Why is the sky blue?"
stream: false
}) {
model
response
done
eval_count
}
}subscription {
generateStream(input: {
model: "gemma3"
prompt: "Why is the sky blue?"
}) {
... on GenerateChunk {
response
done
}
... on GenerateError {
error
}
}
}Run a script that hits all endpoints using model phi3:
# Ensure the server is running (npm run dev) and Ollama has phi3 (ollama pull phi3)
npm run sanity-checkUses GRAPHQL_URL env var (default: http://localhost:4000/graphql).
| GraphQL | REST Equivalent |
|---|---|
query listModels |
GET /api/tags |
mutation generate |
POST /api/generate with stream: false |
subscription generateStream |
POST /api/generate (default stream) |