Skip to content

Minimal Node.js GraphQL server built with Elysia framework, using @elysiajs/node adapter for Node.js and embedded GraphiQL UI. Fully written in TypeScript.

Notifications You must be signed in to change notification settings

smart-developer1791/nodejs-graphql-server-elysia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js GraphQL Server (Elysia Version)

Node.js GraphQL Elysia GraphiQL Render

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/node adapter
  • 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

Run Locally

  1. Install dependencies:
npm install
  1. Run the server:
npm run dev
  1. Open GraphiQL:

http://localhost:8080/


Endpoints

Path Method Description
/graphql POST Main GraphQL endpoint
/ GET GraphiQL UI for interactive use

GraphQL Queries (Examples)

1. Hello query

{
  hello
}

2. Get all users

{
  users {
    id
    name
    email
  }
}

3. Get a single user by ID

{
  user(id: "2") {
    id
    name
    email
  }
}

GraphQL Mutation

Send a message

mutation {
  sendMessage(message: "Hello world!") {
    message
    timestamp
  }
}

Curl Examples

Query Hello

curl -X POST http://localhost:8080/graphql \
  -H "Content-Type: application/json" \
  -d "{\"query\":\"{ hello }\"}"

Query All Users

curl -X POST http://localhost:8080/graphql \
  -H "Content-Type: application/json" \
  -d "{\"query\":\"{ users { id name email } }\"}"

Query Single User

curl -X POST http://localhost:8080/graphql \
  -H "Content-Type: application/json" \
  -d "{\"query\":\"{ user(id: \\\"2\\\") { id name email } }\"}"

Mutation: Send Message

curl -X POST http://localhost:8080/graphql \
  -H "Content-Type: application/json" \
  -d "{\"query\":\"mutation { sendMessage(message: \\\"Hello from curl\\\") { message timestamp } }\"}"

Features

  • 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

Technology Stack

  • 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

Notes

  • 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.

Deploy in 10 seconds

Deploy to Render

About

Minimal Node.js GraphQL server built with Elysia framework, using @elysiajs/node adapter for Node.js and embedded GraphiQL UI. Fully written in TypeScript.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published