Schema Documentation
This is an example of documentation grouping with GraphQL directive using the groupByDirective
option (see documentation):
- Docusaurus (JS/TS)
- GraphQL Config (JS/TS)
- CLI
{
schema: "data/schema_with_grouping.graphql",
baseURL: ".",
linkRoot: "/examples/group-by",
homepage: "data/groups.md",
loaders: {
GraphQLFileLoader: "@graphql-tools/graphql-file-loader",
},
groupByDirective: {
directive: "doc",
field: "category",
fallback: "Common"
},
docOptions: {
index: true,
},
printTypeOptions: {
deprecated: "group",
exampleSection: true,
parentTypePrefix: false,
relatedTypeSection: false,
typeBadges: true,
hierarchy: "entity",
},
skipDocDirective: ["@noDoc"],
customDirective: {
auth: {
descriptor: (directive, type) =>
directiveDescriptor(
directive,
type,
"This requires the current user to be in `${requires}` role.",
),
},
beta: {
tag: (directive) => ({
text: directive?.name?.toUpperCase(),
classname: "badge--danger",
}),
},
complexity: {
descriptor: (directive, type) => {
const { value, multipliers } = getTypeDirectiveValues(directive, type);
const multiplierDescription = multipliers
? ` per ${multipliers.map((v) => `\`${v}\``).join(", ")}`
: "";
return `This has an additional cost of \`${value}\` points${multiplierDescription}.`;
},
},
},
}
{
schema: "data/schema_with_grouping.graphql",
extensions: {
"graphql-markdown": {
baseURL: ".",
linkRoot: "/examples/group-by",
homepage: "data/groups.md",
loaders: {
GraphQLFileLoader: "@graphql-tools/graphql-file-loader",
},
groupByDirective: {
directive: "doc",
field: "category",
fallback: "Common"
},
docOptions: {
index: true,
},
printTypeOptions: {
deprecated: "group",
exampleSection: true,
parentTypePrefix: false,
relatedTypeSection: false,
typeBadges: true,
hierarchy: "entity",
},
skipDocDirective: ["@noDoc"],
customDirective: {
auth: {
descriptor: (directive, type) =>
directiveDescriptor(
directive,
type,
"This requires the current user to be in `${requires}` role.",
),
},
beta: {
tag: (directive) => ({
text: directive?.name?.toUpperCase(),
classname: "badge--danger",
}),
},
complexity: {
descriptor: (directive, type) => {
const { value, multipliers } = getTypeDirectiveValues(directive, type);
const multiplierDescription = multipliers
? ` per ${multipliers.map((v) => `\`${v}\``).join(", ")}`
: "";
return `This has an additional cost of \`${value}\` points${multiplierDescription}.`;
},
},
},
},
},
}
npx docusaurus graphql-to-doc \
--homepage data/groups.md \
--schema data/schema_with_grouping.graphql \
--groupByDirective @doc(category|=Common) \
--base . \
--link /examples/group-by \
--skip @noDoc \
--index \
--noParentType \
--noRelatedType \
--deprecated group \
--hierarchy entity