graphql-apollo-json-to-schema
v1.0.0
Published
recursively converts a JSON object to a Schema
Downloads
36
Readme
graphql-apollo-json-to-schema
recursively converts a JSON object to an Apollo Schema read more about schemas here
can be used directly with output from MongoDB
usage:
paramters: name (String)
JSON: Json Object,
skip: array *Optional
converter(name, JSON, skip)
example:
const converter = require('graphql-apollo-json-to-schema')
const input = {
name:'Dr Steve Brule',
profession:'Doctor',
quotes: ['Bringo!','Jackprot!'],
age:27,
password:'nohunks',
apperances: {
checkItOut: {
type:'tv show',
rating:'11/10',
date: new Date()
},
}
}
console.log(converter('User', input, ['password']))
//`
// OutOput:
// type User {
// name: String
// profession: String
// quotes: [String]
// age: Int
// apperances: UserApperances
// }
//
// type UserApperances {
// checkItOut: UserApperancesCheckitout
// }
//
// type UserApperancesCheckitout {
// type: String
// rating: String
// date: String
// }
// `
Note on Arrays containing Objects: The first item in an array will be picked and used, if subsequent items contains other items they will be lost.