Interactive Ruby GraphQL server with queries and mutations
A simple GraphQL server built with Ruby and Sinatra.
Features queries for users, mutations for sending messages, and GraphiQL UI.
- Install dependencies (skip production gems like thin):
bundle install --without production
- Run the server:
ruby app.rb
- Open in your browser:
Note: The server can run with either webrick (development) or thin (production).
| Path | Method | Description |
|---|---|---|
/graphql |
POST | Main GraphQL endpoint for queries and mutations |
/ |
GET | GraphiQL UI for interactive queries |
{
hello
}
{
users {
id
name
email
}
}
{
user(id: 2) {
id
name
email
}
}
mutation {
sendMessage(message: "Hello world!") {
message
timestamp
}
}
curl -X POST http://localhost:4567/graphql \
-H "Content-Type: application/json" \
-d "{\"query\":\"{ hello }\"}"
curl -X POST http://localhost:4567/graphql \
-H "Content-Type: application/json" \
-d "{\"query\":\"{ users { id name email } }\"}"
curl -X POST http://localhost:4567/graphql \
-H "Content-Type: application/json" \
-d "{\"query\":\"{ user(id: 2) { id name email } }\"}"
For non-ASCII text (Cyrillic):
curl -X POST http://localhost:4567/graphql \
-H "Content-Type: application/json" \
-d "{\"query\":\"mutation { sendMessage(message: \\\"\\u041F\\u0440\\u0438\\u0432\\u0435\\u0442 \\u043C\\u0438\\u0440\\\") { message timestamp } }\"}"
For ASCII text (English):
curl -X POST http://localhost:4567/graphql \
-H "Content-Type: application/json" \
-d $'{"query":"mutation { sendMessage(message: \\"Hello world!\\") { message timestamp } }"}'
- GraphQL Queries:
hello,users,user(id: ID) - GraphQL Mutation:
sendMessage(message: String) - Interactive GraphiQL UI at
/ - Runs on Sinatra with
webrick(dev) orthin(prod) - Fully deployed on Render.com
- Ruby 3.2.9 – dynamic programming language
- Sinatra 2.2 – lightweight web framework
- Sinatra-contrib – helpers for JSON, reloader, and more
- GraphQL 2.5 – GraphQL implementation for Ruby
- WEBrick – development server (Windows default)
- Thin – production server
- Render.com – zero-config deployment