Quick start guide for the GraphQL proxy server.
This GraphQL proxy server acts as an intermediary between your applications and upstream GraphQL APIs. It provides caching, offline mutation queuing, and local data synchronization capabilities.
- Node.js 18+ or Bun
- Access to an upstream GraphQL API
# Using npm
npm install
# Using bun (recommended)
bun installCreate a .env file:
# Required: Your upstream GraphQL endpoint
UPSTREAM_GRAPHQL_ENDPOINT=https://api.example.com/graphql
# Optional: Authentication token
AUTH_TOKEN=your-auth-token
# Optional: Custom port (default: 5001)
PORT=5001
# Optional: GraphQL mode (default: GETMODE)
GRAPHQL_MODE=SETMODE# Development mode
bun run dev
# Production mode
bun run startThe server will start on http://localhost:5001.
Verify the server is running:
curl http://localhost:5001/healthResponse:
{
"ok": true,
"port": 5001,
"mode": "SETMODE",
"upstream": "configured"
}Send GraphQL queries to the proxy:
curl -X POST http://localhost:5001/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "query { posts { id title } }"
}'In SETMODE, mutations are executed when online and queued when offline:
curl -X POST http://localhost:5001/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "mutation { createPost(input: { title: \"Hello\" }) { post { id } } }"
}'UPSTREAM_GRAPHQL_ENDPOINT=https://api.example.com/graphql
GRAPHQL_MODE=GETMODE- ✅ Queries: Cached proxy to upstream
- ❌ Mutations: Blocked
UPSTREAM_GRAPHQL_ENDPOINT=https://api.example.com/graphql
AUTH_TOKEN=your-token
GRAPHQL_MODE=SETMODE- ✅ Queries: Cached proxy to upstream
- ✅ Mutations: Execute online, queue offline
- ✅ Local DB: Syncs with mutations
# .env.development
UPSTREAM_GRAPHQL_ENDPOINT=http://localhost:4000/graphql
PORT=5001
GRAPHQL_MODE=SETMODE
DEBUG=true# Simple introspection query
curl -X POST http://localhost:5001/graphql \
-H "Content-Type: application/json" \
-d '{"query": "{ __typename }"}'# First request (cache miss)
curl -X POST http://localhost:5001/graphql \
-H "Content-Type: application/json" \
-d '{"query": "query { posts { id } }"}' \
-v
# Second request (cache hit)
curl -X POST http://localhost:5001/graphql \
-H "Content-Type: application/json" \
-d '{"query": "query { posts { id } }"}' \
-vLook for x-cache: HIT in the response headers.
# Sync local database from upstream
curl -X POST http://localhost:5001/local/sync
# View local data
curl http://localhost:5001/local/dataFor production deployment, use Docker:
# Build image
docker build -t graphql-proxy .
# Run container
docker run -d \
--name graphql-proxy \
-p 5001:5001 \
-e UPSTREAM_GRAPHQL_ENDPOINT=https://api.example.com/graphql \
-e GRAPHQL_MODE=SETMODE \
graphql-proxy- Server API Reference - Complete API documentation
- Environment Variables - All configuration options
- Docker Deployment - Production deployment guide
- Troubleshooting - Common issues and solutions