Complete API reference for the GraphQL proxy server's endpoints and functionality.
GraphQL proxy endpoint
POST /graphql
Content-Type: application/json
Authorization: Bearer <token> (optional)
{
"query": "query { posts { id title } }",
"variables": {},
"operationName": null
}Response:
{
"data": {
"posts": [
{
"id": "1",
"title": "Post Title"
}
]
}
}Headers:
x-cache:"HIT"or"MISS"- cache statusx-cache-key: Cache key hashx-mode:"GETMODE","SETMODE", or"CRUDMODE"- current GraphQL modex-mutation:"executed"or"queued"- mutation status (for mutations)x-queue-id: Queue ID (for queued mutations)
Server health check
GET /health
Accept: application/jsonResponse:
{
"ok": true,
"port": 5001,
"mode": "GETMODE",
"upstream": "configured",
"authToken": "configured",
"cacheDir": "./data/graphql-cache",
"queueDir": "./data/mutation-queue",
"localDbPath": "./data/local-db.json",
"queuedMutations": 0,
"localData": {
"posts": 15,
"categories": 5,
"tags": 8,
"pages": 3,
"lastUpdated": "2024-01-01T10:00:00.000Z"
}
}Get local database contents
GET /local/data
Accept: application/jsonResponse:
{
"data": {
"posts": [],
"categories": [],
"tags": [],
"authors": [],
"pages": [],
"lastUpdated": "2024-01-01T10:00:00.000Z"
}
}Sync local database from upstream GraphQL
POST /local/sync
Accept: application/jsonResponse:
{
"message": "Local database synced from upstream",
"counts": {
"posts": 15,
"categories": 5,
"tags": 8,
"pages": 3
}
}Error Response:
{
"error": "UPSTREAM_GRAPHQL_ENDPOINT not configured"
}Flush mutation queue
POST /flush
Accept: application/jsonResponse:
{
"message": "Mutation queue flush complete",
"flushed": 3,
"failed": 0
}Error Response:
{
"error": "UPSTREAM_GRAPHQL_ENDPOINT not configured"
}Get queued mutations
GET /queue
Accept: application/jsonResponse:
{
"mutations": [
{
"id": "1640995200000-abc123def",
"payload": {
"query": "mutation { createPost(input: {...}) { post { id } } }",
"variables": {},
"operationName": null
},
"createdAt": "2024-01-01T10:00:00.000Z"
}
]
}- Queries: Forward to upstream, cache responses
- Mutations: Blocked with error
- Offline: Serve from cache
- Queries: Forward to upstream, cache responses
- Mutations: Execute if online, queue if offline, update local DB
- Offline: Queue mutations for later execution
- Queries: Forward to upstream, cache responses
- Mutations: Execute if online, fail if offline, update local DB
- Offline: Reject mutations with error
interface GraphQLRequest {
query?: string;
variables?: Record<string, any>;
operationName?: string | null;
}interface QueuedMutation {
id: string;
payload: GraphQLRequest;
createdAt: string;
}interface LocalData {
posts: any[];
categories: any[];
tags: any[];
authors: any[];
pages: any[];
site?: any;
menu?: any[];
lastUpdated?: string;
}{
"errors": [
{
"message": "Upstream GraphQL is unavailable and cache miss occurred for this query.",
"extensions": {
"code": "OFFLINE_CACHE_MISS",
"cacheKey": "abc123..."
}
}
]
}{
"errors": [
{
"message": "Mutations are disabled in GETMODE",
"extensions": {
"code": "MUTATION_BLOCKED"
}
}
]
}All endpoints support CORS with configurable origin:
- Default:
*(allow all) - Configurable via
CORS_ORIGINenvironment variable
Preflight Response:
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: content-type, authorization
Access-Control-Allow-Methods: GET, POST, OPTIONS