mirror of
https://github.com/BradNut/graphbrainz
synced 2025-09-08 17:40:32 +00:00
* wip: Modernize dependencies, syntax, imports * Use final release of ava-nock v2 * Update Travis config * Remove Node 13 from test matrix * Replace errorClass with parseErrorMessage in subclasses * define exports, apply updated lint rules * Remove markdown eslint plugin * Update README * v9.0.0-beta.1 * Add gql tag to exports * v9.0.0-beta.2 * Bump ava-nock, add test * Update dataloader loadMany usage * Add modules note to README * Add retry option to got calls
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import GraphQL from 'graphql';
|
|
import GraphQLMarkdown from 'graphql-markdown';
|
|
import { baseSchema, createSchema } from '../src/schema.js';
|
|
|
|
const { graphql, getIntrospectionQuery } = GraphQL;
|
|
const { updateSchema, diffSchema } = GraphQLMarkdown;
|
|
|
|
async function getSchemaJSON(schema) {
|
|
const result = await graphql(schema, getIntrospectionQuery());
|
|
return result.data;
|
|
}
|
|
|
|
async function buildExtensionDocs(extensionModules) {
|
|
return Promise.all(
|
|
extensionModules.map(async (extensionName) => {
|
|
const extensionModule = await import(
|
|
`../src/extensions/${extensionName}/index.js`
|
|
);
|
|
const extension = extensionModule.default;
|
|
console.log(`Generating docs for “${extension.name}” extension...`);
|
|
const schema = createSchema(baseSchema, { extensions: [extension] });
|
|
const [baseSchemaJSON, schemaJSON] = await Promise.all([
|
|
getSchemaJSON(baseSchema),
|
|
getSchemaJSON(schema),
|
|
]);
|
|
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(
|
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
`../docs/extensions/${extensionName}.md`
|
|
);
|
|
return updateSchema(outputPath, outputSchema, {
|
|
unknownTypeURL: '../types.md',
|
|
headingLevel: 2,
|
|
});
|
|
})
|
|
);
|
|
}
|
|
|
|
buildExtensionDocs([
|
|
'cover-art-archive',
|
|
'fanart-tv',
|
|
'mediawiki',
|
|
'the-audio-db',
|
|
])
|
|
.then((extensions) => {
|
|
console.log(`Built docs for ${extensions.length} extension(s).`);
|
|
})
|
|
.catch((err) => {
|
|
console.log('Error:', err);
|
|
});
|