Scaffold is a JavaScript library that is used to generate objects using templates inspired from GraphQL.
npm install --save @js-ql/scaffold
const { scaffold } = require('@js-ql/scaffold')
const queryString = `
{
name
age
}`
console.log(scaffold(queryString))
/*
{
name: null,
age: null
}
*/
const { scaffold } = require('@js-ql/scaffold')
const queryString = `
{
name: String
friends: Array
}
`
console.log(scaffold(queryString))
/*
{
name: '',
friends: [],
}
*/
const { Registry } = require('@js-ql/scaffold')
const queryString = `
define Person {
name: String
friends: Array
}
`
// Initial Registration
Registry.register(queryString)
.
.
.
// When you need it
console.log(Registry.scaffold('Person'))
/*
{
name: '',
friends: [],
}
*/
const { Registry } = require('@js-ql/scaffold')
const queryString = `
define Friend {
name
age
}
define Person {
name: String
friends: Array
bestFriend: Friend
}`
Registry.register(queryString)
.
.
.
console.log(Registry.scaffold('Person'))
/*
{
name: '',
friends: [],
bestFriend: {
name: null,
age: null
}
}
*/
Note: Make sure that schemas that you want to use inside another schema are defined before you use it.