GCL is intended to be a type-safe alternative to JSON, YAML (...) based on the input
type syntax of GraphQL
- Autocompletion & validation for configuration files
- Out-of-the-box documentation for config DSLs
- Easy schema definition through SDL for tooling authors
- Leverages available GraphQL tooling (parsers etc) for cross-language adoption
Example (Demo)
This example shows a configuration DSL for Docker images
Config files have the .gcl
file extension
image: "node:6.10"
ports: ["80"]
networks: ["frontend"]
deploy: {
replicas: 2
update_config: {
parallelism: 2
}
restart_policy: {
condition: OnFailure
}
}
The schema is specified by input
types. The Root
type is the "root" of the configuration schema.
input Root {
image: String
ports: [String!]
networks: [String!]
depends_on: [String!]
volumes: [String!]
deploy: Deploy
}
input Deploy {
replicas: Int
update_config: DeployUpdateConfig
restart_policy: DeployRestartPolicy
}
input DeployUpdateConfig {
parallelism: Int
}
enum DeployRestartPolicyCondition {
OnFailure
}
input DeployRestartPolicy {
condition: DeployRestartPolicyCondition
}
- Decide on "Add back top level curly brackets #1"
- PoC based on GraphiQL for auto-completion (removing the top-level query)
- Integrate with graphql-language-service
- Multi-line strings (PR)
import fs from 'fs'
import gclToJson from 'gcl-lib'
async function run() {
const schema = fs.readFileSync('schema.graphql', 'utf-8')
const config = fs.readFileSync('config.gcl', 'utf-8')
const json = await gclToJson(config, schema)
console.log(JSON.stringify(json, null, 2))
}
run()
$ npm install -g gcl-lib
$ gcl-json -s schema.graphql -c config.gcl