Minimal one-file GraphQL server built on Node.js, Elysia, and graphql-js, with an embedded GraphiQL UI.
- Uses Elysia as the HTTP framework, originally designed for Bun, but adapted for Node.js via
@elysiajs/nodeadapter - graphql-js handles GraphQL schema and execution
- @elysiajs/html middleware enables easy serving of HTML (GraphiQL)
- No Apollo, Yoga, Mercurius, or other GraphQL abstractions
- Manual GraphQL request handling through Elysia routes
- Fully written in TypeScript for type safety and modern features
- Install dependencies:
npm install
- Run the server:
npm run dev
- Open GraphiQL:
| Path | Method | Description |
|---|---|---|
/graphql |
POST | Main GraphQL endpoint |
/ |
GET | GraphiQL UI for interactive use |
{
hello
}
{
users {
id
name
email
}
}
{
user(id: "2") {
id
name
email
}
}
mutation {
sendMessage(message: "Hello world!") {
message
timestamp
}
}
curl -X POST http://localhost:8080/graphql \
-H "Content-Type: application/json" \
-d "{\"query\":\"{ hello }\"}"
curl -X POST http://localhost:8080/graphql \
-H "Content-Type: application/json" \
-d "{\"query\":\"{ users { id name email } }\"}"
curl -X POST http://localhost:8080/graphql \
-H "Content-Type: application/json" \
-d "{\"query\":\"{ user(id: \\\"2\\\") { id name email } }\"}"
curl -X POST http://localhost:8080/graphql \
-H "Content-Type: application/json" \
-d "{\"query\":\"mutation { sendMessage(message: \\\"Hello from curl\\\") { message timestamp } }\"}"
- GraphQL Queries:
hello,users,user(id: ID) - GraphQL Mutation:
sendMessage(message: String) - Embedded GraphiQL UI for interactive query testing
- HTTP server powered by Elysia
- Node.js adapter allows running Elysia on Node.js runtime
- Fully written in TypeScript
- Suitable for learning, experimentation, and pet projects
- Fully deployable on Render.com
- Node.js >=22 – JavaScript runtime
- Elysia 1.4.x – Lightweight HTTP framework originally for Bun
- @elysiajs/node – Adapter for Node.js runtime
- @elysiajs/html – Middleware for serving HTML (GraphiQL UI)
- graphql 16.12.x – Official GraphQL execution engine
- GraphiQL 2.x – Embedded in-browser IDE
- TypeScript 5.9.x – Static typing and modern language features
- Render.com – Simple deployment platform
- The server demonstrates how to run Elysia in Node.js using the official Node adapter.
- GraphiQL is embedded via the HTML middleware, so no separate front-end setup is required.
- This setup keeps the code minimal, one-file, and fully functional while remaining extendable with additional middleware, routes, or GraphQL features.