Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alapini/graphql-to-jsonschema
Converts GraphQL Schema Definition to JSONSchema
https://github.com/alapini/graphql-to-jsonschema
graphql jsonschema
Last synced: 8 days ago
JSON representation
Converts GraphQL Schema Definition to JSONSchema
- Host: GitHub
- URL: https://github.com/alapini/graphql-to-jsonschema
- Owner: alapini
- License: mit
- Created: 2017-12-24T11:53:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-08-12T12:35:00.000Z (over 3 years ago)
- Last Synced: 2024-10-31T09:50:24.023Z (15 days ago)
- Topics: graphql, jsonschema
- Language: JavaScript
- Size: 25.4 KB
- Stars: 30
- Watchers: 3
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# graphql-to-jsonschema
[![](https://travis-ci.org/alapini/graphql-to-jsonschema.svg?branch=master)](https://travis-ci.org/alapini/graphql-to-jsonschema)Converts GraphQL Schema Definition to JSONSchema
This repo is a fork of [jakubfiala/graphql-json-schema](https://github.com/jakubfiala/graphql-json-schema) but [mozilla-services/react-jsonschema-form](https://github.com/mozilla-services/react-jsonschema-form) compatible.
## Installation```shell
npm install graphql-to-json-schema
```## Usage
```js
const transform = require('graphql-to-json-schema');const schema = transform(`
scalar Foounion MyUnion = Foo | String | Float
enum MyEnum {
FIRST_ITEM
SECOND_ITEM
THIRD_ITEM
}type Stuff {
my_field: Int
req_field: String!
recursion: MoreStuff
custom_scalar: Foo
enum: MyEnum
}type MoreStuff {
first: [Float]
identifier: [ID]!
reference: Stuff!
bool: Boolean!
union: MyUnion
with_params(param1: Int, param2: [Float]): Int
}
`);console.log(schema);
```The code above returns the following JSON as a plain JS object:
```json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"Foo": {
"title": "Foo",
"type": "GRAPHQL_SCALAR"
},
"MyUnion": {
"title": "MyUnion",
"type": "GRAPHQL_UNION",
"oneOf": [
{
"$ref": "#/definitions/Foo"
},
{
"type": "string",
"required": false
},
{
"type": "number",
"required": false
}
]
},
"MyEnum": {
"title": "MyEnum",
"type": "GRAPHQL_ENUM",
"enum": [
"FIRST_ITEM",
"SECOND_ITEM",
"THIRD_ITEM"
]
},
"Stuff": {
"title": "Stuff",
"type": "object",
"properties": {
"my_field": {
"type": "integer",
"required": false,
"title": "my_field",
"arguments": []
},
"req_field": {
"type": "string",
"required": true,
"title": "req_field",
"arguments": []
},
"recursion": {
"$ref": "#/definitions/MoreStuff",
"title": "recursion",
"arguments": []
},
"custom_scalar": {
"$ref": "#/definitions/Foo",
"title": "custom_scalar",
"arguments": []
},
"enum": {
"$ref": "#/definitions/MyEnum",
"title": "enum",
"arguments": []
}
},
"required": [
"req_field"
]
},
"MoreStuff": {
"title": "MoreStuff",
"type": "object",
"properties": {
"first": {
"type": "array",
"items": {
"type": {
"type": "number",
"required": false
}
},
"title": "first",
"arguments": []
},
"identifier": {
"type": "array",
"items": {
"type": {
"type": "string",
"required": false
}
},
"required": true,
"title": "identifier",
"arguments": []
},
"reference": {
"$ref": "#/definitions/Stuff",
"required": true,
"title": "reference",
"arguments": []
},
"bool": {
"type": "boolean",
"required": true,
"title": "bool",
"arguments": []
},
"union": {
"$ref": "#/definitions/MyUnion",
"title": "union",
"arguments": []
},
"with_params": {
"type": "integer",
"required": false,
"title": "with_params",
"arguments": [
{
"title": "param1",
"type": {
"type": "integer",
"required": false
},
"defaultValue": null
},
{
"title": "param2",
"type": {
"type": "array",
"items": {
"type": {
"type": "number",
"required": false
}
}
},
"defaultValue": null
}
]
}
},
"required": [
"identifier",
"reference",
"bool"
]
}
}
}
```