Skip to content

A simple in-memory GraphQL server in Python using FastAPI and pure graphql-core. Comes with a fully custom GraphiQL UI and example queries/mutations. No database required; ready for local development or deployment.

Notifications You must be signed in to change notification settings

smart-developer1791/python-graphql-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python GraphQL Server

Python FastAPI GraphQL-core Uvicorn Render

A simple GraphQL server written in Python using pure graphql-core with FastAPI and a fully custom GraphiQL UI.
Everything runs in-memory; no database is required.


Run Locally

  1. Install dependencies:
pip install -r requirements.txt
  1. Start the server:
uvicorn main:app --reload

or alternatively:

python -m uvicorn main:app --reload
  1. Open GraphiQL UI in your browser:

http://localhost:8000/


Endpoints

Path Method Description
"/graphql" POST GraphQL API endpoint
"/" GET Interactive GraphiQL UI

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:8000/graphql \
  -H "Content-Type: application/json" \
  -d "{\"query\":\"{ hello }\"}"

Query All Users

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

Query Single User

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

Mutation: Send Message

curl -X POST http://localhost:8000/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 FastAPI (async Python)
  • Fully deployable on any Python-compatible host

Tech Stack

  • Python 3.12 — programming language
  • FastAPI — lightweight, fast HTTP framework
  • graphql-core — pure Python GraphQL implementation (port of GraphQL.js)
  • Uvicorn — ASGI server
  • GraphiQL — in-browser GraphQL IDE served manually

Deploy in 10 seconds

Deploy to Render

About

A simple in-memory GraphQL server in Python using FastAPI and pure graphql-core. Comes with a fully custom GraphiQL UI and example queries/mutations. No database required; ready for local development or deployment.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages