Skip to content

A simple library to build graphql schema from json files.

Notifications You must be signed in to change notification settings

rtalwar26/graphql-json-schema

Repository files navigation

Install

npm install @cuterajat26/graphql-json-schema --save

Usage

const graphql = require("graphql");
import { schemaConfigBuilder } from '@cuterajat26/graphql-json-schema';
const schemaConfigBuilder = require("@cuterajat26/graphql-json-schema").schemaConfigBuilder;

let schemaConfig = schemaConfigBuilder(require.resolve('./relative-path-to-config-dir/config.json'));
let schema = new graphql.GraphQLSchema(schemaConfig);

Config.json format

{
    "dependencies": [
        {
            "name": "query_operation_1",
            "path": "./query_operation_1.json",
            "type": "Query"
        },
        {
            "name": "mutation_operation_1",
            "path": "./gql/mutation_operation_1.json",
            "type": "Mutation"
        }
    ]
    }
        

Operation json format

Example query_operation_1.json

{
    "request": {
        "type": "object",
        "properties": {
            "example_boolean_field": {
                "description": "lorem ipsum detor laga tiki taka",
                "type": "boolean"
            },
            "example_float_field": {
                "description": "lorem ipsum detor laga tiki taka",
                "type": "float"
            },
            
            "example_string_field": {
                "description": "lorem ipsum detor laga tiki taka",
                "type": "string"
            }
            
        },        
        "description": "lorem ipsum detor laga tiki taka"
    },
    "response": {
        "type": "array",
        "items": {
            "type": "object",
            "properties": {
            "example_boolean_field": {
                "description": "lorem ipsum detor laga tiki taka",
                "type": "boolean"
            },
            "example_float_field": {
                "description": "lorem ipsum detor laga tiki taka",
                "type": "float"
            },
            
            "example_string_field": {
                "description": "lorem ipsum detor laga tiki taka",
                "type": "string"
            }
            }
        }
    }
    
}

Example mutation_operation_1.json

{
    "request": {
        "type": "object",
        "properties": {
            "example_boolean_field": {
                "description": "lorem ipsum detor laga tiki taka",
                "type": "boolean"
            },
            "example_float_field": {
                "description": "lorem ipsum detor laga tiki taka",
                "type": "float"
            },
            
            "example_string_field": {
                "description": "lorem ipsum detor laga tiki taka",
                "type": "string"
            }
            
        },        
        "description": "lorem ipsum detor laga tiki taka"
    },
      "response": {
        "type": "object",
        "properties": {
           "example_boolean_field": {
                "description": "lorem ipsum detor laga tiki taka",
                "type": "boolean"
            },
            "example_float_field": {
                "description": "lorem ipsum detor laga tiki taka",
                "type": "float"
            },
            
            "example_string_field": {
                "description": "lorem ipsum detor laga tiki taka",
                "type": "string"
            },
            "_id":{
                "description":" newly created object _id",
                "type":"string"
            }
        }
    }
    
}

About

A simple library to build graphql schema from json files.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published