Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 610 Bytes

README.md

File metadata and controls

24 lines (17 loc) · 610 Bytes

GraphQL Schema to JSON Schema converter

Playground

Installation

npm i @acomagu/graphql-to-json-schema

Usage

import * as graphql from 'graphql';
import { jsonSchemaFromGraphQlType } from '@acomagu/graphql-to-json-schema';

// Get type object to be converted to JSON Schema.
const graphqlSchema = graphql.buildSchema('...');
const type = graphqlSchema.getType('Query');
if (!graphql.isObjectType(type)) throw new Error('The type is not object type.');

// Convert it.
const jsonSchema = jsonSchemaFromGraphQlType(type);