import marked from 'marked' const schema = require('../schema.json').data.__schema // Ideally, we could just spit out the existing description Markdown everywhere // and leave it to be rendered by whatever processes the output. But some // Markdown renderers, including GitHub's, don't process Markdown if it's within // an HTML tag. So in some places (like descriptions of the types themselves) we // just output the raw description. In other places, like table cells, we need // to output pre-rendered Markdown, otherwise GitHub won't interpret it. marked.setOptions({ breaks: false }) function markdown (markup) { return marked(markup || '') .replace(/<\/p>\s*
/g, '
')
.replace(/<\/?p>/g, '')
.trim()
}
function sortBy (arr, property) {
arr.sort((a, b) => {
const aValue = a[property]
const bValue = b[property]
if (aValue > bValue) return 1
if (bValue > aValue) return -1
return 0
})
}
function renderType (type) {
if (type.kind === 'NON_NULL') {
return renderType(type.ofType) + '!'
}
if (type.kind === 'LIST') {
return `[${renderType(type.ofType)}]`
}
return `[${type.name}](#${type.name.toLowerCase()})`
}
function renderObject (type, { skipTitle = false } = {}) {
if (!skipTitle) {
console.log(`\n### ${type.name}\n`)
}
if (type.description) {
console.log(`${type.description}\n`)
}
console.log('
| Field | '); console.log('Argument | ') console.log('Type | ') console.log('Description | ') console.log('
|---|---|---|---|
| ${field.name} ${field.isDeprecated ? '⚠️' : ''} | `) console.log(`${markdown(renderType(field.type))} | `) console.log(``)
console.log(` ${markdown(field.description)}`)
if (field.isDeprecated) {
console.log(' ⚠️ DEPRECATED ') console.log(`${markdown(field.deprecationReason)}`) } console.log(' | ')
console.log(' |
| ${arg.name} | `) console.log(`${markdown(renderType(arg.type))} | `) console.log(`${markdown(arg.description)} | `) console.log('|
| Value | ') console.log('Description | ') console.log('') type.enumValues.forEach(value => { console.log('
|---|---|
| ${value.name}${value.isDeprecated ? ' ⚠️' : ''} | `) console.log('')
console.log(` ${markdown(value.description)}`)
if (value.isDeprecated) {
console.log(' ⚠️ DEPRECATED ') console.log(`${markdown(value.deprecationReason)}`) } console.log(' | ')
console.log('