@graphql-markdown/printer-legacy
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"license": "MIT", | ||
@@ -11,0 +11,0 @@ "main": "src/index.js", |
const { | ||
object: { hasProperty }, | ||
graphql: { getDefaultValue, getTypeName }, | ||
graphql: { getDefaultValue, getTypeName, isDeprecated, hasDirective }, | ||
} = require("@graphql-markdown/utils"); | ||
const { MARKDOWN_EOL } = require("./const/strings"); | ||
const { MARKDOWN_EOL, DEPRECATED } = require("./const/strings"); | ||
const { OPTION_DEPRECATED } = require("./const/options"); | ||
const printCodeField = (type) => { | ||
const printCodeField = (type, options = {}) => { | ||
const skipDirective = | ||
hasProperty(options, "skipDocDirective") && | ||
hasDirective(type, options.skipDocDirective) === true; | ||
const skipDeprecated = | ||
hasProperty(options, "printDeprecated") && | ||
options.printDeprecated === OPTION_DEPRECATED.SKIP && | ||
isDeprecated(type) === true; | ||
if (skipDirective === true || skipDeprecated === true) { | ||
return ""; | ||
} | ||
let code = `${getTypeName(type)}`; | ||
code += printCodeArguments(type); | ||
code += `: ${getTypeName(type.type)}${MARKDOWN_EOL}`; | ||
code += `: ${getTypeName(type.type)}`; | ||
code += isDeprecated(type) ? ` @${DEPRECATED}` : ""; | ||
code += MARKDOWN_EOL; | ||
@@ -13,0 +27,0 @@ return code; |
const OPTION_DEPRECATED = { | ||
DEFAULT: "default", | ||
GROUP: "group", | ||
SKIP: "skip", | ||
}; | ||
@@ -5,0 +6,0 @@ |
const { | ||
graphql: { isEnumType, getTypeName }, | ||
object: { hasProperty }, | ||
graphql: { isEnumType, getTypeName, isDeprecated, hasDirective }, | ||
} = require("@graphql-markdown/utils"); | ||
const { MARKDOWN_EOL } = require("../const/strings"); | ||
const { MARKDOWN_EOL, DEPRECATED } = require("../const/strings"); | ||
const { OPTION_DEPRECATED } = require("../const/options"); | ||
const { printMetadataSection } = require("../section"); | ||
@@ -12,3 +14,3 @@ | ||
const printCodeEnum = (type) => { | ||
const printCodeEnum = (type, options) => { | ||
if (!isEnumType(type)) { | ||
@@ -21,3 +23,18 @@ return ""; | ||
.getValues() | ||
.map((v) => ` ${getTypeName(v)}`) | ||
.map((value) => { | ||
const skipDirective = | ||
hasProperty(options, "skipDocDirective") && | ||
hasDirective(value, options.skipDocDirective) === true; | ||
const skipDeprecated = | ||
hasProperty(options, "printDeprecated") && | ||
options.printDeprecated === OPTION_DEPRECATED.SKIP && | ||
isDeprecated(value) === true; | ||
if (skipDirective === true || skipDeprecated === true) { | ||
return ""; | ||
} | ||
const v = getTypeName(value); | ||
const d = isDeprecated(value) === true ? ` @${DEPRECATED}` : ""; | ||
return ` ${v}${d}`; | ||
}) | ||
.filter((value) => value.length > 0) | ||
.join(MARKDOWN_EOL); | ||
@@ -24,0 +41,0 @@ code += `${MARKDOWN_EOL}}`; |
@@ -5,3 +5,3 @@ const { printObjectMetadata, printCodeType } = require("./object"); | ||
const printCodeInput = (type) => printCodeType(type, "input"); | ||
const printCodeInput = (type, options) => printCodeType(type, "input", options); | ||
@@ -8,0 +8,0 @@ module.exports = { |
@@ -30,3 +30,3 @@ const { | ||
const printCodeType = (type, entity) => { | ||
const printCodeType = (type, entity, options) => { | ||
const name = getTypeName(type); | ||
@@ -41,3 +41,7 @@ const extendsInterface = | ||
const typeFields = getFields(type) | ||
.map((v) => ` ${printCodeField(v)}`) | ||
.map((field) => { | ||
const f = printCodeField(field, options); | ||
return f.length > 0 ? ` ${f}` : ""; | ||
}) | ||
.filter((field) => field.length > 0) | ||
.join(""); | ||
@@ -48,3 +52,3 @@ | ||
const printCodeObject = (type) => printCodeType(type, "type"); | ||
const printCodeObject = (type, options) => printCodeType(type, "type", options); | ||
@@ -51,0 +55,0 @@ module.exports = { |
@@ -106,3 +106,3 @@ const { | ||
static printCode = (type) => { | ||
static printCode = (type, options) => { | ||
let code = ""; | ||
@@ -112,24 +112,24 @@ | ||
case isOperation(type): | ||
code += printCodeOperation(type); | ||
code += printCodeOperation(type, options); | ||
break; | ||
case isEnumType(type): | ||
code += printCodeEnum(type); | ||
code += printCodeEnum(type, options); | ||
break; | ||
case isUnionType(type): | ||
code += printCodeUnion(type); | ||
case isUnionType(type, options): | ||
code += printCodeUnion(type, options); | ||
break; | ||
case isInterfaceType(type): | ||
code += printCodeInterface(type); | ||
case isInterfaceType(type, options): | ||
code += printCodeInterface(type, options); | ||
break; | ||
case isObjectType(type): | ||
code += printCodeObject(type); | ||
code += printCodeObject(type, options); | ||
break; | ||
case isInputType(type): | ||
code += printCodeInput(type); | ||
code += printCodeInput(type, options); | ||
break; | ||
case isScalarType(type): | ||
code += printCodeScalar(type); | ||
code += printCodeScalar(type, options); | ||
break; | ||
case isDirectiveType(type): | ||
code += printCodeDirective(type); | ||
code += printCodeDirective(type, options); | ||
break; | ||
@@ -197,3 +197,3 @@ default: | ||
const description = Printer.printDescription(type); | ||
const code = Printer.printCode(type); | ||
const code = Printer.printCode(type, printTypeOptions); | ||
const metadata = Printer.printTypeMetadata(type, printTypeOptions); | ||
@@ -200,0 +200,0 @@ const relations = Printer.printRelations(type, printTypeOptions); |
@@ -137,7 +137,15 @@ const { | ||
const skipDirective = | ||
hasProperty(options, "skipDocDirective") && | ||
hasDirective(type, options.skipDocDirective) === true; | ||
const skipDeprecated = | ||
hasProperty(options, "printDeprecated") && | ||
options.printDeprecated === OPTION_DEPRECATED.SKIP && | ||
isDeprecated(type) === true; | ||
if ( | ||
typeof type === "undefined" || | ||
type === null || | ||
(hasProperty(options, "skipDocDirective") && | ||
hasDirective(type, options.skipDocDirective) === true) | ||
skipDirective === true || | ||
skipDeprecated === true | ||
) { | ||
@@ -144,0 +152,0 @@ return ""; |
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
33173
1004