graphql-codegen-visitor-plugin-common
Advanced tools
Comparing version 0.19.0-alpha.c9a3343c to 0.19.0-alpha.d3a72027
@@ -83,7 +83,10 @@ "use strict"; | ||
if (name) { | ||
return this.convertName(node); | ||
return this.convertName(node, { | ||
useTypesPrefix: false | ||
}); | ||
} | ||
return this.convertName(this._unnamedCounter++ + '', { | ||
prefix: 'Unnamed_', | ||
suffix: '_' | ||
suffix: '_', | ||
useTypesPrefix: false | ||
}); | ||
@@ -90,0 +93,0 @@ }; |
@@ -38,2 +38,5 @@ import { ScalarsMap, NamingConvention, ConvertFn, ConvertOptions } from './types'; | ||
}; | ||
protected _collectedDirectiveResolvers: { | ||
[key: string]: string; | ||
}; | ||
protected _variablesTransfomer: OperationVariablesToObject; | ||
@@ -52,4 +55,5 @@ constructor(rawConfig: TRawConfig, additionalConfig: TPluginConfig, _schema: GraphQLSchema, defaultScalars?: ScalarsMap); | ||
setVariablesTransformer(variablesTransfomer: OperationVariablesToObject): void; | ||
readonly rootResolver: string; | ||
getRootResolver(): string; | ||
protected formatRootResolver(schemaTypeName: string, resolverType: string): string; | ||
getAllDirectiveResolvers(): string; | ||
Name(node: NameNode): string; | ||
@@ -65,3 +69,4 @@ ListType(node: ListTypeNode): string; | ||
InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode): string; | ||
SchemaDefinition(): any; | ||
} | ||
export {}; |
@@ -26,2 +26,3 @@ "use strict"; | ||
this._collectedResolvers = {}; | ||
this._collectedDirectiveResolvers = {}; | ||
this._parsedConfig = __assign({ scalars: __assign({}, (defaultScalars || scalars_1.DEFAULT_SCALARS), (rawConfig.scalars || {})), convert: naming_1.convertFactory(rawConfig), typesPrefix: rawConfig.typesPrefix || '', contextType: rawConfig.contextType || 'any', mappers: this.transformMappers(rawConfig.mappers || {}) }, (additionalConfig || {})); | ||
@@ -110,22 +111,31 @@ autoBind(this); | ||
}; | ||
Object.defineProperty(BaseResolversVisitor.prototype, "rootResolver", { | ||
get: function () { | ||
var _this = this; | ||
return new utils_1.DeclarationBlock(this._declarationBlockConfig) | ||
.export() | ||
.asKind('interface') | ||
.withName(this.convertName('ResolversRoot')) | ||
.withBlock(Object.keys(this._collectedResolvers) | ||
.map(function (schemaTypeName) { | ||
var resolverType = _this._collectedResolvers[schemaTypeName]; | ||
return utils_1.indent(_this.formatRootResolver(schemaTypeName, resolverType)); | ||
}) | ||
.join('\n')).string; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
BaseResolversVisitor.prototype.getRootResolver = function () { | ||
var _this = this; | ||
return new utils_1.DeclarationBlock(this._declarationBlockConfig) | ||
.export() | ||
.asKind('type') | ||
.withName(this.convertName('IResolvers'), "<Context = " + this.config.contextType + ">") | ||
.withBlock(Object.keys(this._collectedResolvers) | ||
.map(function (schemaTypeName) { | ||
var resolverType = _this._collectedResolvers[schemaTypeName]; | ||
return utils_1.indent(_this.formatRootResolver(schemaTypeName, resolverType)); | ||
}) | ||
.join('\n')).string; | ||
}; | ||
BaseResolversVisitor.prototype.formatRootResolver = function (schemaTypeName, resolverType) { | ||
return schemaTypeName + "?: " + resolverType + ","; | ||
}; | ||
BaseResolversVisitor.prototype.getAllDirectiveResolvers = function () { | ||
var _this = this; | ||
return new utils_1.DeclarationBlock(this._declarationBlockConfig) | ||
.export() | ||
.asKind('type') | ||
.withName(this.convertName('IDirectiveResolvers'), "<Context = " + this.config.contextType + ">") | ||
.withBlock(Object.keys(this._collectedDirectiveResolvers) | ||
.map(function (schemaTypeName) { | ||
var resolverType = _this._collectedDirectiveResolvers[schemaTypeName]; | ||
return utils_1.indent(_this.formatRootResolver(schemaTypeName, resolverType)); | ||
}) | ||
.join('\n')).string; | ||
}; | ||
BaseResolversVisitor.prototype.Name = function (node) { | ||
@@ -184,3 +194,3 @@ return node.value; | ||
.withBlock(node.fields.map(function (f) { return f(node.name); }).join('\n')); | ||
this._collectedResolvers[node.name] = name; | ||
this._collectedResolvers[node.name] = name + '<Context>'; | ||
return block.string; | ||
@@ -207,2 +217,3 @@ }; | ||
var baseName = this.convertName(node); | ||
this._collectedResolvers[node.name] = 'GraphQLScalarType'; | ||
return new utils_1.DeclarationBlock(this._declarationBlockConfig) | ||
@@ -224,7 +235,8 @@ .export() | ||
: ''; | ||
this._collectedDirectiveResolvers[node.name] = directiveName + '<any, any, Context>'; | ||
return new utils_1.DeclarationBlock(this._declarationBlockConfig) | ||
.export() | ||
.asKind('type') | ||
.withName(directiveName, '<Result>') | ||
.withContent("DirectiveResolverFn<Result, { " + directiveArgs + " }, " + this.config.contextType + ">").string; | ||
.withName(directiveName, "<Result, Parent, Context = " + this.config.contextType + ", Args = { " + directiveArgs + " }>") | ||
.withContent("DirectiveResolverFn<Result, Parent, Context, Args>").string; | ||
}; | ||
@@ -254,2 +266,5 @@ BaseResolversVisitor.prototype.InterfaceTypeDefinition = function (node) { | ||
}; | ||
BaseResolversVisitor.prototype.SchemaDefinition = function () { | ||
return null; | ||
}; | ||
return BaseResolversVisitor; | ||
@@ -256,0 +271,0 @@ }()); |
@@ -30,5 +30,7 @@ import { BaseVisitor, ParsedConfig, RawConfig } from './base-visitor'; | ||
DirectiveDefinition(node: DirectiveDefinitionNode): string; | ||
protected _getTypeForNode(node: NamedTypeNode): string; | ||
NamedType(node: NamedTypeNode): string; | ||
ListType(node: ListTypeNode): string; | ||
SchemaDefinition(): any; | ||
protected wrapWithListType(str: string): string; | ||
} |
@@ -136,5 +136,7 @@ "use strict"; | ||
}; | ||
BaseTypesVisitor.prototype._getTypeForNode = function (node) { | ||
return this.scalars[node.name] || this.convertName(node); | ||
}; | ||
BaseTypesVisitor.prototype.NamedType = function (node) { | ||
var type = this.scalars[node.name] || this.convertName(node); | ||
return type; | ||
return this._getTypeForNode(node); | ||
}; | ||
@@ -145,2 +147,5 @@ BaseTypesVisitor.prototype.ListType = function (node) { | ||
}; | ||
BaseTypesVisitor.prototype.SchemaDefinition = function () { | ||
return null; | ||
}; | ||
BaseTypesVisitor.prototype.wrapWithListType = function (str) { | ||
@@ -147,0 +152,0 @@ return "Array<" + str + ">"; |
@@ -23,3 +23,3 @@ import { ScalarsMap, NamingConvention, ConvertFn, ConvertOptions } from './types'; | ||
readonly scalars: ScalarsMap; | ||
convertName(node: ASTNode | string, options?: BaseVisitorConvertOptions & ConvertOptions): string; | ||
protected convertName(node: ASTNode | string, options?: BaseVisitorConvertOptions & ConvertOptions): string; | ||
} |
@@ -67,4 +67,2 @@ "use strict"; | ||
} | ||
var convertTypeName = resolveConventionName('typeNames'); | ||
var convertEnumValues = resolveConventionName('enumValues'); | ||
return function (node, opts) { | ||
@@ -75,6 +73,3 @@ var prefix = opts && opts.prefix; | ||
var str = [prefix || '', getName(node), suffix || ''].join(''); | ||
if (kind === 'enumValues') { | ||
return convertEnumValues(str); | ||
} | ||
return convertTypeName(str); | ||
return resolveConventionName(kind)(str); | ||
}; | ||
@@ -81,0 +76,0 @@ } |
{ | ||
"name": "graphql-codegen-visitor-plugin-common", | ||
"version": "0.19.0-alpha.c9a3343c", | ||
"version": "0.19.0-alpha.d3a72027", | ||
"license": "MIT", | ||
@@ -11,3 +11,3 @@ "scripts": { | ||
"dependency-graph": "0.8.0", | ||
"graphql-codegen-core": "0.19.0-alpha.c9a3343c", | ||
"graphql-codegen-core": "0.19.0-alpha.d3a72027", | ||
"graphql-tag": "2.10.1" | ||
@@ -14,0 +14,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
113560
1625
+ Addedgraphql-codegen-core@0.19.0-alpha.d3a72027(transitive)
- Removedgraphql-codegen-core@0.19.0-alpha.c9a3343c(transitive)