Skip to content

smart-developer1791/nodejs-graphql-server-connect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js GraphQL Server (Connect Version)

Node.js GraphQL Connect GraphiQL Render

Minimal one-file GraphQL server built on pure Node.js, Connect, and graphql-js, with an embedded GraphiQL UI.

  • Uses Connect as a lightweight middleware layer
  • graphql-js as the execution engine
  • No external body parsers or routers
  • Easy to extend with auth, logging, or REST endpoints

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)
  • Interactive GraphiQL UI at /
  • Runs on pure Node.js HTTP with Connect middleware
  • Fully written in TypeScript
  • Fully deployable on Render.com

Technology Stack

  • Node.js >=22 – JavaScript runtime
  • Connect 3.7 – Low-level middleware framework
  • graphql 16.x – Official GraphQL execution engine
  • GraphiQL – Embedded interactive IDE
  • TypeScript – Strict typing and compile-time safety
  • Render.com – Zero-config deployment

Deploy in 10 seconds

Deploy to Render

Releases

No releases published

Packages

No packages published