@graphql-codegen/visitor-plugin-common
Advanced tools
Comparing version 1.0.8-alpha-87bc637b.10 to 1.0.8-alpha-928caade.5
@@ -37,10 +37,13 @@ "use strict"; | ||
let shouldApplyOmit = false; | ||
if (this.config.mappers[typeName] && this.config.mappers[typeName].type) { | ||
const isMapped = this.config.mappers[typeName]; | ||
const isScalar = this.config.scalars[typeName]; | ||
const hasDefaultMapper = !!(this.config.defaultMapper && this.config.defaultMapper.type); | ||
if (isMapped && this.config.mappers[typeName].type) { | ||
this.markMapperAsUsed(typeName); | ||
prev[typeName] = this.config.mappers[typeName].type; | ||
} | ||
else if (this.config.defaultMapper && this.config.defaultMapper.type && !this.config.defaultMapper.type.includes('{T}')) { | ||
else if (hasDefaultMapper && !hasPlaceholder(this.config.defaultMapper.type)) { | ||
prev[typeName] = this.config.defaultMapper.type; | ||
} | ||
else if (this.config.scalars[typeName]) { | ||
else if (isScalar) { | ||
prev[typeName] = this._getScalar(typeName); | ||
@@ -53,3 +56,3 @@ } | ||
const schemaType = allSchemaTypes[typeName]; | ||
if ((shouldApplyOmit && prev[typeName] !== 'any' && graphql_1.isObjectType(schemaType)) || graphql_1.isInterfaceType(schemaType)) { | ||
if ((shouldApplyOmit && prev[typeName] !== 'any' && graphql_1.isObjectType(schemaType)) || (graphql_1.isInterfaceType(schemaType) && !isMapped)) { | ||
const fields = schemaType.getFields(); | ||
@@ -73,5 +76,9 @@ const relevantFields = Object.keys(fields) | ||
} | ||
if (!this.config.scalars[typeName] && !this.config.mappers[typeName] && this.config.defaultMapper && this.config.defaultMapper.type.includes('{T}')) { | ||
prev[typeName] = this.config.defaultMapper.type.replace('{T}', prev[typeName]); | ||
if (isMapped && hasPlaceholder(prev[typeName])) { | ||
prev[typeName] = replacePlaceholder(prev[typeName], typeName); | ||
} | ||
if (!isMapped && hasDefaultMapper && hasPlaceholder(this.config.defaultMapper.type)) { | ||
const name = isScalar ? this._getScalar(typeName) : prev[typeName]; | ||
prev[typeName] = replacePlaceholder(this.config.defaultMapper.type, name); | ||
} | ||
return prev; | ||
@@ -365,2 +372,8 @@ }, {}); | ||
exports.BaseResolversVisitor = BaseResolversVisitor; | ||
function replacePlaceholder(pattern, typename) { | ||
return pattern.replace('{T}', typename); | ||
} | ||
function hasPlaceholder(pattern) { | ||
return pattern.includes('{T}'); | ||
} | ||
//# sourceMappingURL=base-resolvers-visitor.js.map |
@@ -35,10 +35,13 @@ import { BaseVisitor } from './base-visitor'; | ||
let shouldApplyOmit = false; | ||
if (this.config.mappers[typeName] && this.config.mappers[typeName].type) { | ||
const isMapped = this.config.mappers[typeName]; | ||
const isScalar = this.config.scalars[typeName]; | ||
const hasDefaultMapper = !!(this.config.defaultMapper && this.config.defaultMapper.type); | ||
if (isMapped && this.config.mappers[typeName].type) { | ||
this.markMapperAsUsed(typeName); | ||
prev[typeName] = this.config.mappers[typeName].type; | ||
} | ||
else if (this.config.defaultMapper && this.config.defaultMapper.type && !this.config.defaultMapper.type.includes('{T}')) { | ||
else if (hasDefaultMapper && !hasPlaceholder(this.config.defaultMapper.type)) { | ||
prev[typeName] = this.config.defaultMapper.type; | ||
} | ||
else if (this.config.scalars[typeName]) { | ||
else if (isScalar) { | ||
prev[typeName] = this._getScalar(typeName); | ||
@@ -51,3 +54,3 @@ } | ||
const schemaType = allSchemaTypes[typeName]; | ||
if ((shouldApplyOmit && prev[typeName] !== 'any' && isObjectType(schemaType)) || isInterfaceType(schemaType)) { | ||
if ((shouldApplyOmit && prev[typeName] !== 'any' && isObjectType(schemaType)) || (isInterfaceType(schemaType) && !isMapped)) { | ||
const fields = schemaType.getFields(); | ||
@@ -71,5 +74,9 @@ const relevantFields = Object.keys(fields) | ||
} | ||
if (!this.config.scalars[typeName] && !this.config.mappers[typeName] && this.config.defaultMapper && this.config.defaultMapper.type.includes('{T}')) { | ||
prev[typeName] = this.config.defaultMapper.type.replace('{T}', prev[typeName]); | ||
if (isMapped && hasPlaceholder(prev[typeName])) { | ||
prev[typeName] = replacePlaceholder(prev[typeName], typeName); | ||
} | ||
if (!isMapped && hasDefaultMapper && hasPlaceholder(this.config.defaultMapper.type)) { | ||
const name = isScalar ? this._getScalar(typeName) : prev[typeName]; | ||
prev[typeName] = replacePlaceholder(this.config.defaultMapper.type, name); | ||
} | ||
return prev; | ||
@@ -362,2 +369,8 @@ }, {}); | ||
} | ||
function replacePlaceholder(pattern, typename) { | ||
return pattern.replace('{T}', typename); | ||
} | ||
function hasPlaceholder(pattern) { | ||
return pattern.includes('{T}'); | ||
} | ||
//# sourceMappingURL=base-resolvers-visitor.js.map |
{ | ||
"name": "@graphql-codegen/visitor-plugin-common", | ||
"version": "1.0.8-alpha-87bc637b.10+87bc637b", | ||
"version": "1.0.8-alpha-928caade.5+928caade", | ||
"license": "MIT", | ||
@@ -10,3 +10,3 @@ "scripts": { | ||
"dependencies": { | ||
"@graphql-codegen/plugin-helpers": "1.0.8-alpha-87bc637b.10+87bc637b", | ||
"@graphql-codegen/plugin-helpers": "1.0.8-alpha-928caade.5+928caade", | ||
"auto-bind": "2.0.0", | ||
@@ -21,3 +21,3 @@ "dependency-graph": "0.8.0", | ||
"devDependencies": { | ||
"@graphql-codegen/testing": "1.0.8-alpha-87bc637b.10+87bc637b", | ||
"@graphql-codegen/testing": "1.0.8-alpha-928caade.5+928caade", | ||
"@types/graphql": "14.2.0", | ||
@@ -28,3 +28,3 @@ "@types/jest": "24.0.11", | ||
"ts-jest": "24.0.2", | ||
"typescript": "3.4.2" | ||
"typescript": "3.4.3" | ||
}, | ||
@@ -41,3 +41,3 @@ "sideEffects": false, | ||
}, | ||
"gitHead": "87bc637bb236f7266bcb726a0e28aec479eafcbd" | ||
"gitHead": "928caade21bec22680188a281775b28ad5d87c3e" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
276537
4036