@graphql-markdown/utils
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"license": "MIT", | ||
@@ -11,0 +11,0 @@ "main": "src/index.js", |
const { | ||
getDirectiveValues, | ||
getNamedType, | ||
GraphQLBoolean, | ||
GraphQLEnumType, | ||
GraphQLUnionType, | ||
GraphQLScalarType, | ||
isListType, | ||
GraphQLBoolean, | ||
GraphQLInt, | ||
GraphQLFloat, | ||
GraphQLID, | ||
GraphQLInputObjectType, | ||
GraphQLInt, | ||
GraphQLInterfaceType, | ||
GraphQLObjectType, | ||
GraphQLScalarType, | ||
GraphQLSchema, | ||
GraphQLString, | ||
GraphQLObjectType, | ||
GraphQLInterfaceType, | ||
GraphQLInputObjectType, | ||
GraphQLUnionType, | ||
isDirective: isDirectiveType, | ||
getNamedType, | ||
isScalarType, | ||
isEnumType, | ||
isUnionType, | ||
isInputObjectType: isInputType, | ||
isInterfaceType, | ||
isLeafType, | ||
isListType, | ||
isNonNullType, | ||
isObjectType, | ||
isInputObjectType: isInputType, | ||
isNonNullType, | ||
isLeafType, | ||
isScalarType, | ||
isUnionType, | ||
OperationTypeNode, | ||
printSchema, | ||
GraphQLSchema, | ||
OperationTypeNode, | ||
} = require("graphql"); | ||
@@ -31,3 +32,3 @@ const { loadSchema: asyncLoadSchema } = require("@graphql-tools/load"); | ||
const { convertArrayToObject } = require("./array"); | ||
const { hasMethod, hasProperty } = require("./object"); | ||
const { hasMethod, hasProperty, isEmpty } = require("./object"); | ||
@@ -179,2 +180,56 @@ const OperationTypeNodes = [ | ||
function getDirective(type, directives) { | ||
if ( | ||
typeof type.astNode === "undefined" || | ||
type.astNode == null || | ||
typeof directives === "undefined" || | ||
!Array.isArray(type.astNode.directives) | ||
) { | ||
return []; | ||
} | ||
const directiveList = Array.isArray(directives) ? directives : [directives]; // backward_compatibility | ||
return type.astNode.directives.filter((directive) => | ||
directiveList.includes(directive.name.value), | ||
); | ||
} | ||
function getConstDirectiveMap( | ||
type, | ||
{ customDirectives } = { customDirectives: undefined }, | ||
) { | ||
if (isEmpty(customDirectives)) { | ||
return undefined; | ||
} | ||
const constDirectives = getDirective(type, Object.keys(customDirectives)); | ||
if (constDirectives.length === 0) { | ||
return undefined; | ||
} | ||
return constDirectives.reduce((directiveMap, constDirective) => { | ||
const name = constDirective.name.value; | ||
directiveMap[name] = customDirectives[name]; | ||
return directiveMap; | ||
}, {}); | ||
} | ||
function getTypeDirectiveArgValue(directiveType, astNode, argName) { | ||
const args = getTypeDirectiveValues(directiveType, astNode); | ||
if (typeof args === "undefined" || typeof args[argName] === "undefined") { | ||
throw new Error(`Directive argument '${argName}' not found!`); | ||
} | ||
return args[argName]; | ||
} | ||
function getTypeDirectiveValues(directiveType, type) { | ||
if (hasProperty(type, "astNode")) { | ||
return getDirectiveValues(directiveType, type.astNode); | ||
} | ||
return getDirectiveValues(directiveType, type); | ||
} | ||
function getIntrospectionFieldsList(queryType) { | ||
@@ -372,31 +427,35 @@ if ( | ||
module.exports = { | ||
loadSchema, | ||
getConstDirectiveMap, | ||
getDefaultValue, | ||
getDirective, | ||
getTypeDirectiveArgValue, | ||
getDocumentLoaders, | ||
isDirectiveType, | ||
isObjectType, | ||
getFields, | ||
getIntrospectionFieldsList, | ||
getNamedType, | ||
isScalarType, | ||
isEnumType, | ||
isUnionType, | ||
getRelationOfField, | ||
getRelationOfImplementation, | ||
getRelationOfInterface, | ||
getRelationOfReturn, | ||
getRelationOfUnion, | ||
getSchemaMap, | ||
getTypeDirectiveValues, | ||
getTypeFromSchema, | ||
getTypeName, | ||
isParametrizedField, | ||
getFields, | ||
getDefaultValue, | ||
hasDirective, | ||
isOperation, | ||
isDeprecated, | ||
isDirectiveType, | ||
isEnumType, | ||
isInputType, | ||
isInterfaceType, | ||
isInputType, | ||
isNonNullType, | ||
isLeafType, | ||
isListType, | ||
isDeprecated, | ||
isNonNullType, | ||
isObjectType, | ||
isOperation, | ||
isParametrizedField, | ||
isScalarType, | ||
isUnionType, | ||
loadSchema, | ||
printSchema, | ||
getIntrospectionFieldsList, | ||
getTypeFromSchema, | ||
getRelationOfReturn, | ||
getRelationOfField, | ||
getRelationOfUnion, | ||
getRelationOfInterface, | ||
getRelationOfImplementation, | ||
}; |
@@ -10,2 +10,4 @@ module.exports = { | ||
group: require("./group"), | ||
directive: require("./directive"), | ||
helper: require("./helper"), | ||
}; |
@@ -16,2 +16,15 @@ /** | ||
module.exports = { hasMethod, hasProperty }; | ||
function isEmpty(obj) { | ||
return typeof obj !== "object" || Object.keys(obj).length === 0; | ||
} | ||
// get the specified property or nested property of an object | ||
function getObjPath(path, obj, fallback = "") { | ||
if (typeof obj !== "object" || typeof path !== "string") { | ||
return fallback; | ||
} | ||
return path.split(".").reduce((res, key) => res[key] || fallback, obj); | ||
} | ||
module.exports = { hasMethod, hasProperty, isEmpty, getObjPath }; |
@@ -5,2 +5,4 @@ /** | ||
const { getObjPath } = require("./object"); | ||
function stringCaseBuilder(str, transformation, separator) { | ||
@@ -76,2 +78,11 @@ const hasTransformation = typeof transformation === "function"; | ||
function interpolate(template, variables, fallback) { | ||
const regex = /\${[^{]+}/g; | ||
return template.replace(regex, (match) => { | ||
const objPath = match.slice(2, -1).trim(); | ||
return getObjPath(objPath, variables, fallback); | ||
}); | ||
} | ||
module.exports = { | ||
@@ -81,2 +92,3 @@ capitalize, | ||
firstUppercase, | ||
interpolate, | ||
kebabCase, | ||
@@ -83,0 +95,0 @@ prune, |
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
21294
14
657