在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):pipedrive/graphql-schema-registry开源软件地址(OpenSource Url):https://github.com/pipedrive/graphql-schema-registry开源编程语言(OpenSource Language):TypeScript 57.2%开源软件介绍(OpenSource Introduction):graphql-schema-registryGraphql schema storage as dockerized on-premise service for federated graphql gateway server (based on apollo server) as alternative to Apollo studio Features
Roadmap(Pull requests are encouraged on these topics)
ConfigurationWe use environment variables for configuration. You can:
The following are the different environment variables that are looked up that allow configuring the schema registry in different ways.
For development we rely on docker network and use hostnames from InstallationWith default settings, UI should be accessible at http://localhost:6001 On bare host
Docker imageWe have docker image published for main node service.
It assumes you have mysql/redis running separately.
Use exact IP instead of
Docker-compose
Use casesValidating schema on deployOn pre-commit / deploy make a POST /schema/validate to see if its compatible with current schema. Schema registrationOn 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. Schema migrationIf service A contains schema that needs to be migrated to service B, we need to orchestrate schema & traffic change. Instead of juggling with schema status flags, we suggest the following scenario:
ArchitectureTech stack
Componentsgraphql-schema-registry service is one of the components for graphql federation, but it needs tight integration with gateway. Check out examples folder on how to implement it. Note however, that gateway is very simplified and does not have proper error handling, cost limits or fail-safe mechanisms. In gateway, you may also find useful our graphql-query-cost library too. Check it out DB structureMigrations are done using knex DevelopmentDockerized mode
Running in light modeTo have fast iteration of working on UI changes, you can avoid running node service in docker, and run only mysql & redis
DB migrationsTo create new DB migration, use: npm run new-db-migration If not using the default configuration of executing DB migrations on service startup, you can run the following npm run migrate-db The command can be prefixed with any environment variable necessary to configure DB connection (in case you ALTER DB with another user), such as: DB_HOST=my-db-host DB_PORT=6000 npm run migrate-db TestingUnit testsuse jest, coverage is quite low as most logic is in db or libraries.
Functional testsrequire docker, mostly blackbox type - real http requests are done against containers.
DB tables are truncated after every test from within
Performance testsuse k6 + dockerized setup similar to functional tests above + grafana and influxdb for reporting the load these tests are intended just to show/detect avg latencies of most important endpoints
Testing Dockerimage buildIf you change build process in Dockerfile or Dockerfile.CI, consider checking also testing it
Contribution
Authors and acknowledgmentCurrent maintainer - @tot-ra. Mention in PR, if it is stuck Original internal mission that resulted in this project going live: See main blog post Rest API documentationGET /schema/latestSimplified version of /schema/compose where latest versions from different services are composed. Some services prefer this to use this natural schema composition, as its natural and time-based. POST /schema/composeAdvanced version of schema composition, where you need to provide services & their versions. Used by graphql gateway to fetch schema based on currently running containers. The advantage over time-based composition is that versioned composition allows to automatically update federated schema when you deploy older version of the pod in case of some incident. If you deploy older pods they can ofc try to register old schema again, but as it already exists in schema-registry, it will not be considered as "latest". Request params (optional, raw body){
"services": [
{ "name": "service_a", "version": "ke9j34fuuei" },
{ "name": "service_b", "version": "e302fj38fj3" }
]
} Response example
{
"success": true,
"data": [
{
"id": 2,
"service_id": 3,
"version": "ke9j34fuuei",
"name": "service_a",
"url": "http://localhost:6111",
"added_time": "2020-12-11T11:59:40.000Z",
"type_defs": "\n\ttype Query {\n\t\thello: String\n\t}\n",
"is_active": 1
},
{
"id": 3,
"service_id": 4,
"version": "v1",
"name": "service_b",
"url": "http://localhost:6112",
"added_time": "2020-12-14T18:51:04.000Z",
"type_defs": "type Query {\n world: String\n}\n",
"is_active": 1
}
]
}
Request params
If POST /schema/pushValidates and registers new schema for a service. Request params (optional, raw body){
"name": "service_a",
"version": "ke9j34fuuei",
"type_defs": "\n\ttype Query {\n\t\thello: String\n\t}\n"
} URL is optional if you use urls from schema-registry as service discovery {
"name": "service_b",
"version": "jiaj51fu91k",
"type_defs": "\n\ttype Query {\n\t\tworld: String\n\t}\n",
"url": "http://service-b.develop.svc.cluster.local"
}
POST /schema/validateValidates schema, without adding to DB Request params (raw body)
POST /schema/diffCompares schemas and finds breaking or dangerous changes between provided and latest schemas.
DELETE /schema/:schemaIdDeletes specified schema Request params
DELETE /service/:nameDeletes specified service including all schemas registered for that service Request params
GET /persisted_queryLooks up persisted query from DB & caches it in redis if its found Request params (query)
POST /persisted_queryAdds persisted query to DB & redis cache Request params (raw body)
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论