@graphql-markdown/printer-legacy
Advanced tools
Comparing version 1.1.7 to 1.2.0
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "1.1.7", | ||
"version": "1.2.0", | ||
"license": "MIT", | ||
@@ -26,3 +26,3 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"@graphql-markdown/utils": "^1.1.4" | ||
"@graphql-markdown/utils": "^1.2.0" | ||
}, | ||
@@ -29,0 +29,0 @@ "directories": { |
const { | ||
object: { hasProperty }, | ||
graphql: { isNonNullType, isListType, getNamedType }, | ||
graphql: { isNonNullType, isListType, isDeprecated, getNamedType }, | ||
} = require("@graphql-markdown/utils"); | ||
@@ -14,11 +14,11 @@ | ||
if (hasProperty(type, "isDeprecated") && type.isDeprecated) { | ||
if (isDeprecated(type) === true) { | ||
badges.push("deprecated"); | ||
} | ||
if (isNonNullType(rootType)) { | ||
if (isNonNullType(rootType) === true) { | ||
badges.push("non-null"); | ||
} | ||
if (isListType(rootType)) { | ||
if (isListType(rootType) === true) { | ||
badges.push("list"); | ||
@@ -25,0 +25,0 @@ } |
const { | ||
string: { escapeMDX }, | ||
object: { hasProperty }, | ||
graphql: { isDeprecated }, | ||
} = require("@graphql-markdown/utils"); | ||
@@ -9,6 +10,3 @@ | ||
const printDeprecation = (type) => { | ||
if ( | ||
hasProperty(type, "isDeprecated") === false || | ||
type.isDeprecated === false | ||
) { | ||
if (isDeprecated(type) === false) { | ||
return ""; | ||
@@ -15,0 +13,0 @@ } |
@@ -7,2 +7,24 @@ module.exports = ` | ||
export const Badge = (props) => <><span className={'badge badge--' + props.class}>{props.text}</span></> | ||
import { useState } from 'react'; | ||
export const Details = ({ dataOpen, dataClose, children, startOpen = false }) => { | ||
const [open, setOpen] = useState(startOpen); | ||
return ( | ||
<details {...(open ? { open: true } : {})} className="details" style={{ border:'none', boxShadow:'none', background:'var(--ifm-background-color)' }}> | ||
<summary | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
setOpen((open) => !open); | ||
}} | ||
style={{ listStyle:'none' }} | ||
> | ||
{open ? dataOpen : dataClose} | ||
</summary> | ||
{open && children} | ||
</details> | ||
); | ||
}; | ||
`; |
@@ -25,2 +25,4 @@ const ROOT_TYPE_LOCALE = { | ||
const DEPRECATED = "deprecated"; | ||
module.exports = { | ||
@@ -37,2 +39,3 @@ ROOT_TYPE_LOCALE, | ||
FRONT_MATTER, | ||
DEPRECATED, | ||
}; |
const { | ||
object: { hasProperty }, | ||
graphql: { getTypeName }, | ||
} = require("@graphql-markdown/utils"); | ||
const { printSection } = require("../section"); | ||
const { printMetadataSection } = require("../section"); | ||
const { printCodeArguments } = require("../code"); | ||
@@ -28,6 +29,7 @@ | ||
const printDirectiveMetadata = (type, options) => { | ||
return printSection(type.args, "Arguments", { | ||
...options, | ||
parentType: type.name, | ||
}); | ||
if (hasProperty(type, "args") === false) { | ||
return ""; | ||
} | ||
return printMetadataSection(type, type.args, "Arguments", options); | ||
}; | ||
@@ -34,0 +36,0 @@ |
@@ -6,10 +6,6 @@ const { | ||
const { MARKDOWN_EOL } = require("../const/strings"); | ||
const { printMetadataSection } = require("../section"); | ||
const { printSection } = require("../section"); | ||
const printEnumMetadata = (type, options) => { | ||
return printSection(type.getValues(), "Values", { | ||
...options, | ||
parentType: type.name, | ||
}); | ||
return printMetadataSection(type, type.getValues(), "Values", options); | ||
}; | ||
@@ -16,0 +12,0 @@ |
@@ -6,17 +6,26 @@ const { | ||
const { printSection } = require("../section"); | ||
const { printSection, printMetadataSection } = require("../section"); | ||
const { printCodeField } = require("../code"); | ||
const { MARKDOWN_EOL } = require("../const/strings"); | ||
const printObjectMetadata = (type, options) => { | ||
let metadata = printSection(getFields(type), "Fields", { | ||
...options, | ||
parentType: type.name, | ||
}); | ||
if (hasMethod(type, "getInterfaces")) { | ||
metadata += printSection(type.getInterfaces(), "Interfaces", options); | ||
const printInterfaceMetadata = (type, options) => { | ||
if (hasMethod(type, "getInterfaces") === false) { | ||
return ""; | ||
} | ||
return metadata; | ||
return printSection(type.getInterfaces(), "Interfaces", options); | ||
}; | ||
const printObjectMetadata = (type, options) => { | ||
const interfaceMeta = printInterfaceMetadata(type, options); | ||
const metadata = printMetadataSection( | ||
type, | ||
getFields(type), | ||
"Fields", | ||
options, | ||
); | ||
return `${metadata}${interfaceMeta}`; | ||
}; | ||
const printCodeType = (type, entity) => { | ||
@@ -23,0 +32,0 @@ const name = getTypeName(type); |
@@ -5,19 +5,18 @@ const { | ||
const { printSection } = require("../section"); | ||
const { printSection, printMetadataSection } = require("../section"); | ||
const { printCodeField } = require("../code"); | ||
const printOperationMetadata = (type, options) => { | ||
let metadata = printSection(type.args, "Arguments", { | ||
...options, | ||
parentType: type.name, | ||
parentTypePrefix: true, | ||
}); | ||
const printOperationType = (type, options) => { | ||
const queryType = getTypeName(type.type).replace(/[![\]]*/g, ""); | ||
metadata += printSection([options.schema.getType(queryType)], "Type", { | ||
return printSection([options.schema.getType(queryType)], "Type", { | ||
...options, | ||
parentTypePrefix: false, | ||
}); | ||
}; | ||
return metadata; | ||
const printOperationMetadata = (type, options) => { | ||
const response = printOperationType(type, options); | ||
const metadata = printMetadataSection(type, type.args, "Arguments", options); | ||
return `${metadata}${response}`; | ||
}; | ||
@@ -24,0 +23,0 @@ |
@@ -20,2 +20,3 @@ const { | ||
isLeafType, | ||
isDeprecated, | ||
}, | ||
@@ -25,3 +26,4 @@ } = require("@graphql-markdown/utils"); | ||
const { getGroup } = require("./group"); | ||
const { ROOT_TYPE_LOCALE } = require("./const/strings"); | ||
const { ROOT_TYPE_LOCALE, DEPRECATED } = require("./const/strings"); | ||
const { OPTION_DEPRECATED } = require("./const/options"); | ||
@@ -79,3 +81,3 @@ class Link { | ||
// special case for support relation map | ||
// special case for relation map | ||
if (category === ROOT_TYPE_LOCALE.OPERATION) { | ||
@@ -89,5 +91,14 @@ if (typeof operation === "undefined") { | ||
const text = graphLQLNamedType.name || graphLQLNamedType; | ||
const group = getGroup(type, options.groups); | ||
const deprecated = | ||
hasProperty(options, "printDeprecated") && | ||
options.printDeprecated === OPTION_DEPRECATED.GROUP && | ||
isDeprecated(type) | ||
? DEPRECATED | ||
: ""; | ||
const group = hasProperty(options, "groups") | ||
? getGroup(type, options.groups) | ||
: ""; | ||
const url = pathUrl.join( | ||
options.basePath, | ||
deprecated, | ||
group, | ||
@@ -94,0 +105,0 @@ category.plural, |
@@ -49,11 +49,3 @@ const { | ||
const DEFAULT_OPTIONS = { | ||
schema: undefined, | ||
basePath: "/", | ||
groups: {}, | ||
parentTypePrefix: true, | ||
relatedTypeSection: true, | ||
typeBadges: true, | ||
skipDocDirective: undefined, | ||
}; | ||
const { DEFAULT_OPTIONS, OPTION_DEPRECATED } = require("./const/options"); | ||
@@ -86,2 +78,4 @@ class Printer { | ||
skipDocDirective: skipDocDirective ?? undefined, | ||
printDeprecated: | ||
printTypeOptions?.deprecated ?? OPTION_DEPRECATED.DEFAULT, | ||
}; | ||
@@ -88,0 +82,0 @@ }; |
const { | ||
graphql: { isParametrizedField, hasDirective }, | ||
graphql: { isParametrizedField, hasDirective, isDeprecated }, | ||
} = require("@graphql-markdown/utils"); | ||
@@ -16,2 +16,3 @@ const { hasProperty } = require("@graphql-markdown/utils/src/object"); | ||
const { printLink, printParentLink } = require("./link"); | ||
const { OPTION_DEPRECATED } = require("./const/options"); | ||
@@ -24,2 +25,42 @@ const sectionLevels = [ | ||
const SHOW_DEPRECATED = `<><span className="deprecated">Show deprecated</span></>`; | ||
const HIDE_DEPRECATED = `<><span className="deprecated">Hide deprecated</span></>`; | ||
const printMetadataSection = (type, values, section, options) => { | ||
switch (options.printDeprecated) { | ||
case OPTION_DEPRECATED.GROUP: { | ||
const { fields, deprecated } = values.reduce( | ||
(res, arg) => { | ||
isDeprecated(arg) ? res.deprecated.push(arg) : res.fields.push(arg); | ||
return res; | ||
}, | ||
{ fields: [], deprecated: [] }, | ||
); | ||
const meta = printSection(fields, section, { | ||
...options, | ||
parentType: type.name, | ||
}); | ||
const deprecatedMeta = printSection(deprecated, "", { | ||
...options, | ||
parentType: type.name, | ||
level: "", | ||
collapsible: { | ||
dataOpen: HIDE_DEPRECATED, | ||
dataClose: SHOW_DEPRECATED, | ||
}, | ||
}); | ||
return `${meta}${deprecatedMeta}`; | ||
} | ||
case OPTION_DEPRECATED.DEFAULT: | ||
default: | ||
return printSection(values, section, { | ||
...options, | ||
parentType: type.name, | ||
}); | ||
} | ||
}; | ||
const printSection = (values, section, options) => { | ||
@@ -38,11 +79,28 @@ const level = | ||
const levelPosition = sectionLevels.indexOf(level); | ||
let subLevel = undefined; | ||
if (levelPosition > -1) { | ||
subLevel = sectionLevels[levelPosition + 1]; | ||
const [openSection, closeSection] = (() => { | ||
if ( | ||
hasProperty(options, "collapsible") && | ||
hasProperty(options.collapsible, "dataOpen") && | ||
hasProperty(options.collapsible, "dataClose") | ||
) { | ||
return [ | ||
`${MARKDOWN_EOP}<Details dataOpen={${options.collapsible.dataOpen}} dataClose={${options.collapsible.dataClose}}>${MARKDOWN_EOP}`, | ||
`${MARKDOWN_EOP}</Details>${MARKDOWN_EOP}`, | ||
]; | ||
} | ||
return [MARKDOWN_EOP, MARKDOWN_EOP]; | ||
})(); | ||
const items = printSectionItems(values, { | ||
...options, | ||
collapsible: undefined, // do not propagate collapsible | ||
level: levelPosition > -1 ? sectionLevels[levelPosition + 1] : undefined, | ||
}); | ||
if (items === "") { | ||
return ""; // do not print section is no items printed | ||
} | ||
return `${level} ${section}${MARKDOWN_EOP}${printSectionItems(values, { | ||
...options, | ||
level: subLevel, | ||
})}${MARKDOWN_EOP}`; | ||
return `${level} ${section}${openSection}${items}${closeSection}`; | ||
}; | ||
@@ -85,3 +143,4 @@ | ||
type === null || | ||
hasDirective(type, options.skipDocDirective) | ||
(hasProperty(options, "skipDocDirective") && | ||
hasDirective(type, options.skipDocDirective) === true) | ||
) { | ||
@@ -92,3 +151,6 @@ return ""; | ||
const typeNameLink = printLink(type, { ...options, withAttributes: false }); | ||
const description = printDescription(type, ""); | ||
const description = printDescription(type, "").replaceAll( | ||
"\n", | ||
`${MARKDOWN_EOL}> `, | ||
); | ||
const badges = printBadges(type, options); | ||
@@ -116,2 +178,5 @@ const parentTypeLink = printParentLink(type, options); | ||
printSectionItems, | ||
printMetadataSection, | ||
SHOW_DEPRECATED, | ||
HIDE_DEPRECATED, | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
31370
24
962
0