All Projects → pipedrive → Graphql Schema Registry

pipedrive / Graphql Schema Registry

Licence: mit
GraphQL schema registry

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Graphql Schema Registry

Coolqlcool
Nextjs server to query websites with GraphQL
Stars: ✭ 623 (+402.42%)
Mutual labels:  graphql, schema
Joi2gql
Conversion of Joi schemas into GraphQL data types
Stars: ✭ 11 (-91.13%)
Mutual labels:  graphql, schema
Type Graphql
Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
Stars: ✭ 6,864 (+5435.48%)
Mutual labels:  graphql, schema
Graphback
Graphback - Out of the box GraphQL server and client
Stars: ✭ 323 (+160.48%)
Mutual labels:  graphql, schema
Graphql Scalars
A library of custom GraphQL Scalars for creating precise type-safe GraphQL schemas.
Stars: ✭ 1,023 (+725%)
Mutual labels:  graphql, schema
Typegql
Create GraphQL schema with TypeScript classes.
Stars: ✭ 415 (+234.68%)
Mutual labels:  graphql, schema
Merge Graphql Schemas
A utility library to facilitate merging of modularized GraphQL schemas and resolver objects.
Stars: ✭ 935 (+654.03%)
Mutual labels:  graphql, schema
Mongoke
Instant Graphql for MongoDb (active branch is golang, rewrite in process)
Stars: ✭ 203 (+63.71%)
Mutual labels:  graphql, schema
Graphql Factory
A toolkit for building GraphQL
Stars: ✭ 44 (-64.52%)
Mutual labels:  graphql, schema
Rdbms To Graphql
A Java CLI program that generates a GraphQL schema from a JDBC data source.
Stars: ✭ 44 (-64.52%)
Mutual labels:  graphql, schema
Babel Plugin Import Graphql
Enables import syntax for .graphql and .gql files
Stars: ✭ 284 (+129.03%)
Mutual labels:  graphql, schema
Shapeshifter
🐺 Generate relational schemas, PropTypes, Flow aliases, and TypeScript interfaces from JSON or GraphQL schematic files.
Stars: ✭ 105 (-15.32%)
Mutual labels:  graphql, schema
Graphql For Vscode
GraphQL syntax highlighting, linting, auto-complete, and more!
Stars: ✭ 265 (+113.71%)
Mutual labels:  graphql, schema
Tuql
Automatically create a GraphQL server from a SQLite database or a SQL file
Stars: ✭ 526 (+324.19%)
Mutual labels:  graphql, schema
Graphql Rover
🚀 GraphQL + Vue.js + D3.js schema viewer, powered by introspection.
Stars: ✭ 239 (+92.74%)
Mutual labels:  graphql, schema
Graphql Code Generator
A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
Stars: ✭ 7,993 (+6345.97%)
Mutual labels:  graphql, schema
Conventions
GraphQL Conventions Library for .NET
Stars: ✭ 198 (+59.68%)
Mutual labels:  graphql, schema
Graphql Parser
A graphql query language and schema definition language parser and formatter for rust
Stars: ✭ 203 (+63.71%)
Mutual labels:  graphql, schema
Graphql Compose
Toolkit for generating complex GraphQL Schemas on Node.js
Stars: ✭ 947 (+663.71%)
Mutual labels:  graphql, schema
Neo4j Graphql
An optimized neo4j query resolver for Facebook's GraphQL
Stars: ✭ 60 (-51.61%)
Mutual labels:  graphql, schema

graphql-schema-registry

Graphql schema storage as dockerized on-premise service for federated graphql gateway server (based on apollo server) as alternative to Apollo studio

Features

  • Stores versioned schema for graphql-federated services
  • Serves schema for graphql gateway based on provided services & their versions
  • Validates new schema to be compatible with other running services
  • Provides UI for developers to see stored schema & its history diff
  • Stores & shows in UI persisted queries passed by the gateway for debugging
Screenshot 2020-08-31 at 15 40 43

Roadmap

  • client tracking (for breaking changes)
  • schema usage tracking (for breaking changes)
  • separate APQs (use cache only) from backend-registered persisted queries (use DB only)

Installation

Assuming you have nvm & docker installed:

nvm use
npm install
npm run build
docker-compose up --build

Open http://localhost:6001

Configuration

We rely on docker network and uses hostnames from docker-compose.yml. Check app/config.js to see credentials that node service uses to connect to mysql & redis and change it if you install it with own setup. If you use dynamic service discovery (consul/etcd), edit diplomat.js

The following are the different environment variables that are looked up that allow configuring the schema registry in different ways.

Variable Name Description Default
DB_HOST Host name of the MySQL server gql-schema-registry-db
DB_USERNAME Username to connect to MySQL root
DB_SECRET Password used to connect to MySQL root
DB_PORT Port used when connecting to MySQL 3306
DB_NAME Name of the MySQL database to connect to schema-registry
DB_EXECUTE_MIGRATIONS Controls whether DB migrations are executed upon registry startup or not 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 MySQL Empty
ASSETS_URL Controls the url that web assets are served from localhost:6001
NODE_ENV Specifies the environment. Use production for production like deployment Empty

Note about NODE_ENV: setting the NODE_ENV environment variable to production will tell the registry to serve web assets (js, css) from their compiled versions in the dist/assets directory.

Use cases

Validating schema on deploy

On pre-commit / deploy make a POST /schema/validate to see if its compatible with current schema.

Schema registration

On service start-up (runtime), make POST to /schema/push to register schema (see API reference for details). Make sure to handle failure.

Architecture

Tech stack

Frontend (/client folder) Backend (/app folder)
react nodejs 14
apollo client express, hapi/joi
styled-components apollo-server-express, dataloader
redis 6
knex
mysql 8

Components

graphql-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.

DB structure

Migrations are done using knex

Development

DB migrations

To 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 command prior to starting the registry:

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

Contribution

  • Before making PR, make sure to run npm run version & fill CHANGELOG

Honorable mentions

Original internal mission that resulted in this project consisted of (in alphabetical order):

Rest API documentation

GET /schema/latest

Simplified version of /schema/compose where latest versions from different services is composed. Needed mostly for debugging

POST /schema/compose

Lists schema based on passed services & their versions. Used by graphql gateway to fetch schema based on current containers

Request params (optional, raw body)

{
  "services": [
    {"name": "service_a", "version": "ke9j34fuuei"},
    {"name": "service_b", "version": "e302fj38fj3"},
  ]
}

Response example

  • ✅ 200
{
    "success": true,
    "data": [
        {
            "id": 2,
            "service_id": 3,
            "version": "ke9j34fuuei",
            "name": "service_a",
            "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",
            "added_time": "2020-12-14T18:51:04.000Z",
            "type_defs": "type Query {\n  world: String\n}\n",
            "is_active": 1
        }
    ]
}
  • ❌ 400 "services[0].version" must be a string
  • ❌ 500 Internal error (DB is down)

Request params

  • services{ name, version}

If services is not passed, schema-registry tries to find most recent versions. Logic behind the scenes is that schema with highest added_time OR updated_time is picked as latest. If time is the same, schema.id is used.

POST /schema/push

Validates 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"
}

POST /schema/validate

Validates schema, without adding to DB

Request params (raw body)
  • name
  • version
  • type_defs

POST /schema/diff

Compares schemas and finds breaking or dangerous changes between provided and latest schemas.

  • name
  • version
  • type_defs

DELETE /schema/delete/:schemaId

Deletes specified schema

Request params
Property Type Comments
schemaId number ID of sechema

GET /persisted_query

Looks up persisted query from DB & caches it in redis if its found

Request params (query)
Property Type Comments
key string hash of APQ (with apq: prefix)

POST /persisted_query

Adds persisted query to DB & redis cache

Request params (raw body)
Property Type Comments
key string hash of APQ (with apq: prefix)
value string Graphql query
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].