@slub/json-schema-to-graphql
v0.1.4
Published
create graphql queries and mutations based on a given JSON-Schema
Downloads
2
Readme
create graphql queries and mutations based on a given JSON-Schema
Prerequisites
- node >=10
Install
yarn add @slub/json-schema-to-graphql
Usage
given the following json schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.com/person.schema.json",
"$defs": {
"person": {
"type": "object",
"title": "Person",
"description": "A human being",
"required": [
"name",
"knows"
],
"properties": {
"name": {
"type": "string"
},
"knows": {
"type": "array",
"items": {
"$ref": "#/$defs/person"
}
}
}
}
},
"type": "object",
"title": "Person",
"description": "A human being",
"required": [
"name",
"knows"
],
"properties": {
"name": {
"type": "string"
},
"knows": {
"type": "array",
"items": {
"$ref": "#/$defs/person"
}
}
}
}
you can create a graphql query and mutation like this
jsonSchemaToGraphQLQuery('Person', schema, { maxRecursion: 3 })
to get the following query
query getPerson( $pk: ID! ) {
getPerson(pk: $pk) {
name
knows {
name
knows {
name
knows {
name
id
}
id
}
id
}
id
}
}
Run tests
npm run test
Author
👤 Sebastian Tilsch
- Github: @bastiion
Show your support
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator