https://github.com/charlypoly/json-schema-to-graphql
JSON Schema to GraphQL lib (JS/TS)
https://github.com/charlypoly/json-schema-to-graphql
Last synced: 10 months ago
JSON representation
JSON Schema to GraphQL lib (JS/TS)
- Host: GitHub
- URL: https://github.com/charlypoly/json-schema-to-graphql
- Owner: charlypoly
- License: mit
- Created: 2021-08-18T12:36:55.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-08-07T00:14:06.000Z (10 months ago)
- Last Synced: 2025-08-09T00:24:49.912Z (10 months ago)
- Language: TypeScript
- Size: 205 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON Schema to GraphQL
## Install
```bash
npm install @wittydeveloper/json-schema-to-graphql
```
## Usage
```ts
import { convert } from '@wittydeveloper/json-schema-2-graphql'
const schema: JSONSchema6 = {
$schema: 'http://json-schema.org/draft-06/schema#',
$ref: '#/definitions/Product',
definitions: {
Product: {
type: 'object',
additionalProperties: false,
properties: {
collection_ids: {
type: 'array',
items: {
type: 'string',
},
},
collections: {
type: 'array',
items: {
type: 'null',
},
},
title: {
type: 'string',
},
salePrice: {
type: 'integer',
},
objectID: {
type: 'string',
},
shipping: {
type: 'string',
},
},
required: ['collection_ids', 'collections', 'objectID', 'salePrice', 'title'],
title: 'Product',
},
},
}
const result = convert(schema, {
fallbackTypes: {
'collections[]': 'string',
},
})
// =>
// type Product {
// collection_ids: [String!]!
// collections: [String!]!
// title: String!
// salePrice: Int!
// objectID: String!
// shipping: String
// }
```