0.1.4 • Published 10 months ago

@slub/json-schema-to-graphql v0.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

0.1.4

10 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago