GraphQL 方案注册表
Graphql schema storage as dockerized on-premise service for federated graphql gateway server (based on apollo server) as alternative to Apollo studio, The Guild's Hive, WunderGraph
https://user-images.githubusercontent.com/445122/194967021-8e5d1750-db39-4809-8485-55d2b1b19429.mp4
With default settings, UI should be accessible at http://localhost:6001
git clone https://github.com/tot-ra/graphql-schema-registry.git && cd graphql-schema-registry
cp example.env .env && nano .env
npm install && npm run build
node app/schema-registry.jsWe have docker image published for main node service. It assumes you have postgres/redis running separately. Use exact IP instead of localhost. Use exact docker image tag to avoid breaking changes.
docker pull artjomkurapov/graphql-schema-registry:5.5.1
docker run -e DB_CLIENT=pg -e DB_HOST=localhost -e DB_USERNAME=postgres -e DB_SECRET=postgres -e DB_PORT=5432 -e DB_NAME=schema_registry -p 6001:3000 artjomkurapov/graphql-schema-registrygit clone https://github.com/tot-ra/graphql-schema-registry.git && cd graphql-schema-registry
docker-compose -f docker-compose.base.yml -f docker-compose.prod.yml up…| Name | Role | Description |
|---|---|---|
| federated gateway | Required | Apollo server running in federated mode. You should have your own. Check examples folder how to configure it. Note however, that gateway is very simplified and does not have proper error handling, query cost limit checks or fail-safe mechanisms. |
| schema registry | Required | Main service that we provide |
| postgres | Required | Main data storage of schemas and other derivative data |
| query analyzer | Optional | Processes queries in async mode, required for usage tracking. Main code in /src/worker folder |
| redis | Required | Shared cache and pub/sub layer used for APQ cache, schema update notifications, and query usage event ingestion |
Frontend (/client folder) |
Backend (/src folder) |
|---|---|
| react | nodejs 25.x |
| apollo client | express, hapi/joi |
| styled-components | apollo-server-express, dataloader |
| redis 8 | |
| knex | |
| postgres 18 |
Migrations are done using knex
…We use environment variables for configuration. You can:
docker-compose.yml or DockerfileThe following are the different environment variables that are looked up that allow configuring the schema registry in different ways.
| Variable Name | Description | Default |
|---|---|---|
| DB_CLIENT | DB driver used by knex | pg |
| DB_HOST | Host name of the Postgres server | gql-schema-registry-db |
| DB_USERNAME | Username to connect to Postgres | postgres |
| DB_SECRET | Password used to connect to Postgres | postgres |
| DB_PORT | Port used when connecting to Postgres | 5432 |
| DB_NAME | Name of the Postgres database to connect to | schema_registry |
| DB_ADMIN_DATABASE | Admin DB used for existence checks/creation before migrations | postgres |
| DB_SSL | Enables TLS for Postgres connections | false |
| DB_SSL_REJECT_UNAUTHORIZED | Controls server cert validation when DB_SSL=true | true |
| DB_SSL_CA | Optional CA certificate content for TLS (supports \\n escaped newlines) |
Empty |
| DB_EXECUTE_MIGRATIONS | Controls whether DB migrations are executed upon registry startup or not | true |
| ASSETS_URL | Controls the url that web assets are served from | localhost:6001 |
| NODE_ENV | Specifies the environment. Use production to load js/css from dist/assets |
Empty |
| ASYNC_SCHEMA_UPDATES | Specifies if async achema updates is enabled | false |
| REDIS_SCHEMA_UPDATES_CHANNEL | Redis pub/sub channel used for schema update notifications | graphql-schema-updates |
| REDIS_QUERIES_CHANNEL | Redis pub/sub channel used by gateway request logging and query analyzer | graphql-queries |
| LOG_LEVEL | Minimum level of logs to output | info |
| LOG_TYPE | Output log type, supports pretty or json. | pretty |
| LOG_STREAMING_ENABLED | Controls whether logs are streamed over Redis to be presented in UI | true |
| REDIS_HOST | Host name of the Redis server | gql-schema-registry-redis |
| REDIS_PORT | Port used when connecting to Redis | 6379 |
| REDIS_SECRET | Password used to connect to Redis | Empty |
| REDIS_DB | Index of the logical redis database | 2 |
For development we rely on docker network and use hostnames from docker-compose.yml.
Node service uses it to connect to postgres & redis and change it if you install it with your own setup.
For dynamic service discovery (if you need multiple hosts for scaling), override app/config.js and diplomat.js
On service start-up (runtime), make POST to /schema/push to register schema (see API reference for details). Make sure to handle failure.
See example for nodejs/ESM.
If you have a dedicated websocket/event service (for example event-stream-filter) that exposes GraphQL Subscription operations, register that SDL separately with:
POST /subscriptions/pushThis subscription catalog is intentionally separate from federated supergraph composition:
POST /schema/push is for federated gateway service schemasPOST /subscriptions/push is for event-stream subscription visibility in UI and analyticsMinimal runtime payload example:
{
"name": "event-stream-filter",
"version": "latest",
"ws_url": "ws://event-stream-filter:8350/graphql",
"type_defs": "type Subscription { onApiaryUpdated: ApiaryEvent } type ApiaryEvent { id: String name: String } type Query { hello: String }"
}Usually in production, POST /schema/push requires unique version that should be unique git or docker hash.
But, if you are developing a service and you run schema-registry locally, you can set version: "latest" to skip this version check.
is_active flag in DB that you can manually toggle via UI.On pre-commit / deploy make a POST /schema/validate to see if its compatible with current schema. If you have multiple regions or environments (test), makes sense to check all.
If service A contains schema that needs to be migrated to service B with close to 0 downtime, you will need to orchestrate schema & traffic change. Instead of juggling with schema status flags, we suggest the following scenario:
sequenceDiagram
participant service_A
participant service_B
participant schemaRegistry
loop Every 5 sec
service_B->>+schemaRegistry: register schema B + A1
s暂无开放 Issues,或尚未同步最近议题。