2017-10-19 08:00:21 +00:00
|
|
|
import path from 'path'
|
|
|
|
|
import { graphql, introspectionQuery } from 'graphql'
|
2017-11-02 05:40:52 +00:00
|
|
|
import { updateSchema, diffSchema } from 'graphql-markdown'
|
2017-10-19 08:00:21 +00:00
|
|
|
import baseSchema, { createSchema } from '../src/schema'
|
|
|
|
|
|
|
|
|
|
const extensionModules = [
|
|
|
|
|
'cover-art-archive',
|
|
|
|
|
'fanart-tv',
|
|
|
|
|
'mediawiki',
|
|
|
|
|
'the-audio-db'
|
|
|
|
|
]
|
|
|
|
|
|
2017-11-07 05:54:56 +00:00
|
|
|
function getSchemaJSON(schema) {
|
2017-10-19 08:00:21 +00:00
|
|
|
return graphql(schema, introspectionQuery).then(result => result.data)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 05:54:56 +00:00
|
|
|
Promise.all(
|
|
|
|
|
extensionModules.map(extensionModule => {
|
|
|
|
|
const extension = require(`../src/extensions/${extensionModule}`).default
|
|
|
|
|
console.log(`Generating docs for “${extension.name}” extension...`)
|
|
|
|
|
const schema = createSchema(baseSchema, { extensions: [extension] })
|
|
|
|
|
return Promise.all([getSchemaJSON(baseSchema), getSchemaJSON(schema)]).then(
|
|
|
|
|
([baseSchemaJSON, schemaJSON]) => {
|
|
|
|
|
const outputSchema = diffSchema(baseSchemaJSON, schemaJSON, {
|
|
|
|
|
processTypeDiff(type) {
|
|
|
|
|
if (type.description === undefined) {
|
|
|
|
|
type.description =
|
|
|
|
|
':small_blue_diamond: *This type has been extended. See the ' +
|
|
|
|
|
'[base schema](../types.md)\nfor a description and additional ' +
|
|
|
|
|
'fields.*'
|
|
|
|
|
}
|
|
|
|
|
return type
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
const outputPath = path.resolve(
|
|
|
|
|
__dirname,
|
|
|
|
|
`../docs/extensions/${extensionModule}.md`
|
|
|
|
|
)
|
|
|
|
|
return updateSchema(outputPath, outputSchema, {
|
|
|
|
|
unknownTypeURL: '../types.md',
|
|
|
|
|
headingLevel: 2
|
|
|
|
|
})
|
2017-10-19 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
2017-11-07 05:54:56 +00:00
|
|
|
)
|
|
|
|
|
.then(extensions => {
|
|
|
|
|
console.log(`Built docs for ${extensions.length} extension(s).`)
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
console.log('Error:', err)
|
|
|
|
|
})
|