graphql-codegen-visitor-plugin-common
Advanced tools
Comparing version 0.19.0-alpha.658f2fa9 to 0.19.0-alpha.6863e55f
@@ -1,9 +0,10 @@ | ||
import { ScalarsMap } from './types'; | ||
import { ScalarsMap, NamingConvention, ConvertFn, ConvertOptions } from './types'; | ||
import { DeclarationBlockConfig } from './utils'; | ||
import { GraphQLSchema, FragmentDefinitionNode, OperationDefinitionNode } from 'graphql'; | ||
import { GraphQLSchema, FragmentDefinitionNode, OperationDefinitionNode, ASTNode } from 'graphql'; | ||
import { SelectionSetToObject } from './selection-set-to-object'; | ||
import { OperationVariablesToObject } from './variables-to-object'; | ||
import { BaseVisitorConvertOptions } from './base-visitor'; | ||
export interface ParsedDocumentsConfig { | ||
scalars: ScalarsMap; | ||
convert: (str: string) => string; | ||
convert: ConvertFn<ConvertOptions>; | ||
typesPrefix: string; | ||
@@ -14,3 +15,3 @@ addTypename: boolean; | ||
scalars?: ScalarsMap; | ||
namingConvention?: string; | ||
namingConvention?: NamingConvention; | ||
typesPrefix?: string; | ||
@@ -30,3 +31,3 @@ skipTypename?: boolean; | ||
setVariablesTransformer(variablesTransfomer: OperationVariablesToObject): void; | ||
convertName(name: any, addPrefix?: boolean): string; | ||
convertName(node: ASTNode | string, options?: ConvertOptions & BaseVisitorConvertOptions): string; | ||
readonly config: TPluginConfig; | ||
@@ -33,0 +34,0 @@ readonly schema: GraphQLSchema; |
@@ -15,6 +15,6 @@ "use strict"; | ||
var autoBind = require("auto-bind"); | ||
var graphql_codegen_plugin_helpers_1 = require("graphql-codegen-plugin-helpers"); | ||
var scalars_1 = require("./scalars"); | ||
var utils_1 = require("./utils"); | ||
var variables_to_object_1 = require("./variables-to-object"); | ||
var naming_1 = require("./naming"); | ||
function getRootType(operation, schema) { | ||
@@ -36,3 +36,3 @@ switch (operation) { | ||
this._unnamedCounter = 1; | ||
this._parsedConfig = __assign({ addTypename: !rawConfig.skipTypename, scalars: __assign({}, (defaultScalars || scalars_1.DEFAULT_SCALARS), (rawConfig.scalars || {})), convert: rawConfig.namingConvention ? graphql_codegen_plugin_helpers_1.resolveExternalModuleAndFn(rawConfig.namingConvention) : utils_1.toPascalCase, typesPrefix: rawConfig.typesPrefix || '' }, (additionalConfig || {})); | ||
this._parsedConfig = __assign({ addTypename: !rawConfig.skipTypename, scalars: __assign({}, (defaultScalars || scalars_1.DEFAULT_SCALARS), (rawConfig.scalars || {})), convert: naming_1.convertFactory(rawConfig), typesPrefix: rawConfig.typesPrefix || '' }, (additionalConfig || {})); | ||
autoBind(this); | ||
@@ -50,5 +50,5 @@ this._variablesTransfomer = new variables_to_object_1.OperationVariablesToObject(this.scalars, this.convertName); | ||
}; | ||
BaseDocumentsVisitor.prototype.convertName = function (name, addPrefix) { | ||
if (addPrefix === void 0) { addPrefix = true; } | ||
return (addPrefix ? this._parsedConfig.typesPrefix : '') + this._parsedConfig.convert(name); | ||
BaseDocumentsVisitor.prototype.convertName = function (node, options) { | ||
var useTypesPrefix = options && typeof options.useTypesPrefix === 'boolean' ? options.useTypesPrefix : true; | ||
return (useTypesPrefix ? this._parsedConfig.typesPrefix : '') + this._parsedConfig.convert(node, options); | ||
}; | ||
@@ -83,7 +83,14 @@ Object.defineProperty(BaseDocumentsVisitor.prototype, "config", { | ||
}); | ||
BaseDocumentsVisitor.prototype.handleAnonymouseOperation = function (name) { | ||
BaseDocumentsVisitor.prototype.handleAnonymouseOperation = function (node) { | ||
var name = node.name && node.name.value; | ||
if (name) { | ||
return this.convertName(name); | ||
return this.convertName(node, { | ||
useTypesPrefix: false | ||
}); | ||
} | ||
return this.convertName("Unnamed_" + this._unnamedCounter++ + "_"); | ||
return this.convertName(this._unnamedCounter++ + '', { | ||
prefix: 'Unnamed_', | ||
suffix: '_', | ||
useTypesPrefix: false | ||
}); | ||
}; | ||
@@ -96,7 +103,10 @@ BaseDocumentsVisitor.prototype.FragmentDefinition = function (node) { | ||
.asKind('type') | ||
.withName(this.convertName(node.name.value + 'Fragment', true)) | ||
.withName(this.convertName(node, { | ||
useTypesPrefix: true, | ||
suffix: 'Fragment' | ||
})) | ||
.withContent(selectionSet.string).string; | ||
}; | ||
BaseDocumentsVisitor.prototype.OperationDefinition = function (node) { | ||
var name = this.handleAnonymouseOperation(node.name && node.name.value ? node.name.value : null); | ||
var name = this.handleAnonymouseOperation(node); | ||
var operationRootType = getRootType(node.operation, this._schema); | ||
@@ -108,3 +118,5 @@ var selectionSet = this._selectionSetToObject.createNext(operationRootType, node.selectionSet); | ||
.asKind('type') | ||
.withName(this.convertName(name + utils_1.toPascalCase(node.operation))) | ||
.withName(this.convertName(name, { | ||
suffix: utils_1.toPascalCase(node.operation) | ||
})) | ||
.withContent(selectionSet.string).string; | ||
@@ -114,3 +126,5 @@ var operationVariables = new utils_1.DeclarationBlock(this._declarationBlockConfig) | ||
.asKind('type') | ||
.withName(this.convertName(name + utils_1.toPascalCase(node.operation) + 'Variables')) | ||
.withName(this.convertName(name, { | ||
suffix: utils_1.toPascalCase(node.operation) + 'Variables' | ||
})) | ||
.withBlock(visitedOperationVariables).string; | ||
@@ -117,0 +131,0 @@ return [operationVariables, operationResult].filter(function (r) { return r; }).join('\n\n'); |
@@ -1,2 +0,2 @@ | ||
import { ScalarsMap } from './types'; | ||
import { ScalarsMap, NamingConvention, ConvertFn, ConvertOptions } from './types'; | ||
import { DeclarationBlockConfig } from './utils'; | ||
@@ -7,2 +7,3 @@ import { NameNode, ListTypeNode, NamedTypeNode, FieldDefinitionNode, ObjectTypeDefinitionNode, GraphQLSchema } from 'graphql'; | ||
import { OperationVariablesToObject } from './variables-to-object'; | ||
import { BaseVisitorConvertOptions } from './base-visitor'; | ||
interface ParsedMapper { | ||
@@ -15,3 +16,3 @@ isExternal: boolean; | ||
scalars: ScalarsMap; | ||
convert: (str: string) => string; | ||
convert: ConvertFn; | ||
typesPrefix: string; | ||
@@ -29,3 +30,3 @@ contextType: string; | ||
scalars?: ScalarsMap; | ||
namingConvention?: string; | ||
namingConvention?: NamingConvention; | ||
typesPrefix?: string; | ||
@@ -40,2 +41,5 @@ } | ||
}; | ||
protected _collectedDirectiveResolvers: { | ||
[key: string]: string; | ||
}; | ||
protected _variablesTransfomer: OperationVariablesToObject; | ||
@@ -51,7 +55,8 @@ constructor(rawConfig: TRawConfig, additionalConfig: TPluginConfig, _schema: GraphQLSchema, defaultScalars?: ScalarsMap); | ||
protected buildMapperImport(source: string, types: string[]): string; | ||
convertName(name: any, addPrefix?: boolean): string; | ||
convertName(name: any, options?: ConvertOptions & BaseVisitorConvertOptions): string; | ||
setDeclarationBlockConfig(config: DeclarationBlockConfig): void; | ||
setVariablesTransformer(variablesTransfomer: OperationVariablesToObject): void; | ||
readonly rootResolver: string; | ||
getRootResolver(): string; | ||
protected formatRootResolver(schemaTypeName: string, resolverType: string): string; | ||
getAllDirectiveResolvers(): string; | ||
Name(node: NameNode): string; | ||
@@ -61,3 +66,3 @@ ListType(node: ListTypeNode): string; | ||
NonNullType(node: NonNullTypeNode): string; | ||
FieldDefinition(node: FieldDefinitionNode, key: string | number, parent: any): (parentName: any) => string; | ||
FieldDefinition(node: FieldDefinitionNode, key: string | number, parent: any): (parentName: string) => string; | ||
ObjectTypeDefinition(node: ObjectTypeDefinitionNode): string; | ||
@@ -64,0 +69,0 @@ UnionTypeDefinition(node: UnionTypeDefinitionNode, key: string | number, parent: any): string; |
@@ -14,3 +14,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var graphql_codegen_plugin_helpers_1 = require("graphql-codegen-plugin-helpers"); | ||
var autoBind = require("auto-bind"); | ||
@@ -21,2 +20,3 @@ var scalars_1 = require("./scalars"); | ||
var variables_to_object_1 = require("./variables-to-object"); | ||
var naming_1 = require("./naming"); | ||
var BaseResolversVisitor = /** @class */ (function () { | ||
@@ -28,3 +28,4 @@ function BaseResolversVisitor(rawConfig, additionalConfig, _schema, defaultScalars) { | ||
this._collectedResolvers = {}; | ||
this._parsedConfig = __assign({ scalars: __assign({}, (defaultScalars || scalars_1.DEFAULT_SCALARS), (rawConfig.scalars || {})), convert: rawConfig.namingConvention ? graphql_codegen_plugin_helpers_1.resolveExternalModuleAndFn(rawConfig.namingConvention) : utils_1.toPascalCase, typesPrefix: rawConfig.typesPrefix || '', contextType: rawConfig.contextType || 'any', mappers: this.transformMappers(rawConfig.mappers || {}) }, (additionalConfig || {})); | ||
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 || {})); | ||
autoBind(this); | ||
@@ -102,5 +103,5 @@ this._variablesTransfomer = new variables_to_object_1.OperationVariablesToObject(this.scalars, this.convertName); | ||
}; | ||
BaseResolversVisitor.prototype.convertName = function (name, addPrefix) { | ||
if (addPrefix === void 0) { addPrefix = true; } | ||
return (addPrefix ? this.config.typesPrefix : '') + this.config.convert(name); | ||
BaseResolversVisitor.prototype.convertName = function (name, options) { | ||
var useTypesPrefix = options && typeof options.useTypesPrefix === 'boolean' ? options.useTypesPrefix : true; | ||
return (useTypesPrefix ? this.config.typesPrefix : '') + this.config.convert(name, options); | ||
}; | ||
@@ -113,22 +114,31 @@ BaseResolversVisitor.prototype.setDeclarationBlockConfig = function (config) { | ||
}; | ||
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) { | ||
@@ -142,4 +152,3 @@ return node.value; | ||
BaseResolversVisitor.prototype.NamedType = function (node) { | ||
var asString = node.name; | ||
var type = this.config.scalars[asString] || this.convertName(asString); | ||
var type = this.config.scalars[node.name] || this.convertName(node); | ||
return "" + type; | ||
@@ -162,7 +171,17 @@ }; | ||
var isSubscriptionType = subscriptionType && subscriptionType.name === parentName; | ||
return utils_1.indent(node.name + "?: " + (isSubscriptionType ? 'SubscriptionResolver' : 'Resolver') + "<" + mappedType + ", ParentType, Context" + (hasArguments ? ", " + (_this.convertName(parentName, true) + _this.convertName(node.name, false) + 'Args') : '') + ">,"); | ||
return utils_1.indent(node.name + "?: " + (isSubscriptionType ? 'SubscriptionResolver' : 'Resolver') + "<" + mappedType + ", ParentType, Context" + (hasArguments | ||
? ", " + (_this.convertName(parentName, { | ||
useTypesPrefix: true | ||
}) + | ||
_this.convertName(node.name, { | ||
useTypesPrefix: false | ||
}) + | ||
'Args') | ||
: '') + ">,"); | ||
}; | ||
}; | ||
BaseResolversVisitor.prototype.ObjectTypeDefinition = function (node) { | ||
var name = this.convertName(node.name + 'Resolvers'); | ||
var name = this.convertName(node, { | ||
suffix: 'Resolvers' | ||
}); | ||
var type = null; | ||
@@ -173,3 +192,3 @@ if (this.config.mappers[node.name]) { | ||
else { | ||
type = this.config.scalars[node.name] || this.convertName(node.name); | ||
type = this.config.scalars[node.name] || this.convertName(node); | ||
} | ||
@@ -181,3 +200,3 @@ var block = new utils_1.DeclarationBlock(this._declarationBlockConfig) | ||
.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; | ||
@@ -187,6 +206,8 @@ }; | ||
var _this = this; | ||
var name = this.convertName(node.name + 'Resolvers'); | ||
var name = this.convertName(node, { | ||
suffix: 'Resolvers' | ||
}); | ||
var originalNode = parent[key]; | ||
var possibleTypes = originalNode.types | ||
.map(function (node) { return _this.convertName(node.name.value); }) | ||
.map(function (node) { return _this.convertName(node); }) | ||
.map(function (f) { return "'" + f + "'"; }) | ||
@@ -202,11 +223,16 @@ .join(' | '); | ||
BaseResolversVisitor.prototype.ScalarTypeDefinition = function (node) { | ||
var baseName = this.convertName(node.name); | ||
var baseName = this.convertName(node); | ||
this._collectedResolvers[node.name] = 'GraphQLScalarType'; | ||
return new utils_1.DeclarationBlock(this._declarationBlockConfig) | ||
.export() | ||
.asKind('interface') | ||
.withName(this.convertName(node.name + 'ScalarConfig'), " extends GraphQLScalarTypeConfig<" + baseName + ", any>") | ||
.withName(this.convertName(node, { | ||
suffix: 'ScalarConfig' | ||
}), " extends GraphQLScalarTypeConfig<" + baseName + ", any>") | ||
.withBlock(utils_1.indent("name: '" + node.name + "'")).string; | ||
}; | ||
BaseResolversVisitor.prototype.DirectiveDefinition = function (node) { | ||
var directiveName = this.convertName(node.name + 'DirectiveResolver'); | ||
var directiveName = this.convertName(node, { | ||
suffix: 'DirectiveResolver' | ||
}); | ||
var hasArguments = node.arguments && node.arguments.length > 0; | ||
@@ -216,10 +242,13 @@ var directiveArgs = hasArguments | ||
: ''; | ||
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; | ||
}; | ||
BaseResolversVisitor.prototype.InterfaceTypeDefinition = function (node) { | ||
var name = this.convertName(node.name + 'Resolvers'); | ||
var name = this.convertName(node, { | ||
suffix: 'Resolvers' | ||
}); | ||
var allTypesMap = this._schema.getTypeMap(); | ||
@@ -226,0 +255,0 @@ var implementingTypes = []; |
@@ -53,3 +53,3 @@ "use strict"; | ||
.asKind('type') | ||
.withName(this.convertName(node.name)) | ||
.withName(this.convertName(node)) | ||
.withBlock(node.fields.join('\n')).string; | ||
@@ -70,7 +70,7 @@ }; | ||
var originalNode = parent[key]; | ||
var possibleTypes = originalNode.types.map(function (t) { return _this.convertName(t.name.value); }).join(' | '); | ||
var possibleTypes = originalNode.types.map(function (t) { return _this.convertName(t); }).join(' | '); | ||
return new utils_1.DeclarationBlock(this._declarationBlockConfig) | ||
.export() | ||
.asKind('type') | ||
.withName(this.convertName(node.name)) | ||
.withName(this.convertName(node)) | ||
.withContent(possibleTypes).string; | ||
@@ -82,3 +82,3 @@ }; | ||
var interfaces = originalNode.interfaces && node.interfaces.length > 0 | ||
? originalNode.interfaces.map(function (i) { return _this.convertName(i.name.value); }).join(' & ') + ' & ' | ||
? originalNode.interfaces.map(function (i) { return _this.convertName(i); }).join(' & ') + ' & ' | ||
: ''; | ||
@@ -88,3 +88,3 @@ var typeDefinition = new utils_1.DeclarationBlock(this._declarationBlockConfig) | ||
.asKind('type') | ||
.withName(this.convertName(node.name)) | ||
.withName(this.convertName(node)) | ||
.withContent(interfaces) | ||
@@ -95,3 +95,7 @@ .withBlock(node.fields.join('\n')).string; | ||
var fieldsArguments = fieldsWithArguments.map(function (field) { | ||
var name = original.name.value + _this.convertName(field.name.value, false) + 'Args'; | ||
var name = original.name.value + | ||
_this.convertName(field, { | ||
useTypesPrefix: false | ||
}) + | ||
'Args'; | ||
return new utils_1.DeclarationBlock(_this._declarationBlockConfig) | ||
@@ -109,3 +113,3 @@ .export() | ||
.asKind('type') | ||
.withName(this.convertName(node.name)) | ||
.withName(this.convertName(node)) | ||
.withBlock(node.fields.join('\n')).string; | ||
@@ -117,3 +121,3 @@ }; | ||
.asKind('type') | ||
.withName(this.convertName(node.name)) | ||
.withName(this.convertName(node)) | ||
.withContent(this.config.scalars[node.name] || 'any').string; | ||
@@ -125,3 +129,3 @@ }; | ||
.asKind('enum') | ||
.withName(this.convertName(node.name)) | ||
.withName(this.convertName(node)) | ||
.withBlock(this.buildEnumValuesBlock(node.values)).string; | ||
@@ -133,3 +137,3 @@ }; | ||
.map(function (enumOption) { | ||
return utils_1.indent("" + _this.convertName(enumOption.name) + _this._declarationBlockConfig.enumNameValueSeparator + " " + utils_1.wrapWithSingleQuotes(_this.config.enumValues[enumOption.name] || enumOption.name)); | ||
return utils_1.indent("" + _this.convertName(enumOption) + _this._declarationBlockConfig.enumNameValueSeparator + " " + utils_1.wrapWithSingleQuotes(_this.config.enumValues[enumOption.name] || enumOption.name)); | ||
}) | ||
@@ -142,4 +146,3 @@ .join(', \n'); | ||
BaseTypesVisitor.prototype.NamedType = function (node) { | ||
var asString = node.name; | ||
var type = this.scalars[asString] || this.convertName(asString); | ||
var type = this.scalars[node.name] || this.convertName(node); | ||
return type; | ||
@@ -146,0 +149,0 @@ }; |
@@ -1,6 +0,10 @@ | ||
import { ScalarsMap } from './types'; | ||
import { ScalarsMap, NamingConvention, ConvertFn, ConvertOptions } from './types'; | ||
import { DeclarationBlockConfig } from './utils'; | ||
import { ASTNode } from 'graphql'; | ||
export interface BaseVisitorConvertOptions { | ||
useTypesPrefix?: boolean; | ||
} | ||
export interface ParsedConfig { | ||
scalars: ScalarsMap; | ||
convert: (str: string) => string; | ||
convert: ConvertFn; | ||
typesPrefix: string; | ||
@@ -10,3 +14,3 @@ } | ||
scalars?: ScalarsMap; | ||
namingConvention?: string; | ||
namingConvention?: NamingConvention; | ||
typesPrefix?: string; | ||
@@ -20,3 +24,3 @@ } | ||
readonly scalars: ScalarsMap; | ||
convertName(name: any, addPrefix?: boolean): string; | ||
convertName(node: ASTNode | string, options?: BaseVisitorConvertOptions & ConvertOptions): string; | ||
} |
@@ -14,6 +14,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var utils_1 = require("./utils"); | ||
var graphql_codegen_plugin_helpers_1 = require("graphql-codegen-plugin-helpers"); | ||
var autoBind = require("auto-bind"); | ||
var scalars_1 = require("./scalars"); | ||
var naming_1 = require("./naming"); | ||
var BaseVisitor = /** @class */ (function () { | ||
@@ -23,3 +22,3 @@ function BaseVisitor(rawConfig, additionalConfig, defaultScalars) { | ||
this._declarationBlockConfig = {}; | ||
this._parsedConfig = __assign({ scalars: __assign({}, (defaultScalars || scalars_1.DEFAULT_SCALARS), (rawConfig.scalars || {})), convert: rawConfig.namingConvention ? graphql_codegen_plugin_helpers_1.resolveExternalModuleAndFn(rawConfig.namingConvention) : utils_1.toPascalCase, typesPrefix: rawConfig.typesPrefix || '' }, (additionalConfig || {})); | ||
this._parsedConfig = __assign({ scalars: __assign({}, (defaultScalars || scalars_1.DEFAULT_SCALARS), (rawConfig.scalars || {})), convert: naming_1.convertFactory(rawConfig), typesPrefix: rawConfig.typesPrefix || '' }, (additionalConfig || {})); | ||
autoBind(this); | ||
@@ -41,5 +40,5 @@ } | ||
}); | ||
BaseVisitor.prototype.convertName = function (name, addPrefix) { | ||
if (addPrefix === void 0) { addPrefix = true; } | ||
return (addPrefix ? this.config.typesPrefix : '') + this.config.convert(name); | ||
BaseVisitor.prototype.convertName = function (node, options) { | ||
var useTypesPrefix = typeof (options && options.useTypesPrefix) === 'boolean' ? options.useTypesPrefix : true; | ||
return (useTypesPrefix ? this.config.typesPrefix : '') + this.config.convert(node, options); | ||
}; | ||
@@ -46,0 +45,0 @@ return BaseVisitor; |
@@ -134,7 +134,13 @@ "use strict"; | ||
} | ||
var documentVariableName = this.convertName(node.name.value + 'Document'); | ||
var documentVariableName = this.convertName(node, { | ||
suffix: 'Document' | ||
}); | ||
var documentString = "export const " + documentVariableName + (this.config.noGraphQLTag ? ': DocumentNode' : '') + " = " + this._gql(node) + ";"; | ||
var operationType = graphql_codegen_core_1.toPascalCase(node.operation); | ||
var operationResultType = this.convertName(node.name.value + operationType); | ||
var operationVariablesTypes = this.convertName(node.name.value + operationType + 'Variables'); | ||
var operationResultType = this.convertName(node, { | ||
suffix: operationType | ||
}); | ||
var operationVariablesTypes = this.convertName(node, { | ||
suffix: operationType + 'Variables' | ||
}); | ||
var additional = this.buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes); | ||
@@ -141,0 +147,0 @@ return [documentString, additional].filter(function (a) { return a; }).join('\n'); |
import { SelectionSetNode, FieldNode, FragmentSpreadNode, InlineFragmentNode, GraphQLNamedType, GraphQLSchema } from 'graphql'; | ||
import { ScalarsMap, ConvertNameFn } from './types'; | ||
import { GraphQLObjectType, GraphQLNonNull, GraphQLList } from 'graphql'; | ||
import { BaseVisitorConvertOptions } from './base-visitor'; | ||
export declare type PrimitiveField = string; | ||
@@ -22,3 +23,3 @@ export declare type PrimitiveAliasedFields = { | ||
protected _schema: GraphQLSchema; | ||
protected _convertName: ConvertNameFn; | ||
protected _convertName: ConvertNameFn<BaseVisitorConvertOptions>; | ||
protected _addTypename: boolean; | ||
@@ -33,3 +34,3 @@ protected _parentSchemaType?: GraphQLNamedType; | ||
protected _queriedForTypename: boolean; | ||
constructor(_scalars: ScalarsMap, _schema: GraphQLSchema, _convertName: ConvertNameFn, _addTypename: boolean, _parentSchemaType?: GraphQLNamedType, _selectionSet?: SelectionSetNode); | ||
constructor(_scalars: ScalarsMap, _schema: GraphQLSchema, _convertName: ConvertNameFn<BaseVisitorConvertOptions>, _addTypename: boolean, _parentSchemaType?: GraphQLNamedType, _selectionSet?: SelectionSetNode); | ||
createNext(parentSchemaType: GraphQLNamedType, selectionSet: SelectionSetNode): SelectionSetToObject; | ||
@@ -36,0 +37,0 @@ protected wrapTypeWithModifiers(baseType: string, type: GraphQLObjectType | GraphQLNonNull<GraphQLObjectType> | GraphQLList<GraphQLObjectType>): string; |
@@ -108,3 +108,5 @@ "use strict"; | ||
} | ||
var parentName = this._convertName(this._parentSchemaType.name, true); | ||
var parentName = this._convertName(this._parentSchemaType.name, { | ||
useTypesPrefix: true | ||
}); | ||
var typeName = this._addTypename || this._queriedForTypename ? this.buildTypeNameField() : null; | ||
@@ -173,3 +175,8 @@ var baseFields = this.buildPrimitiveFields(parentName, this._primitiveFields); | ||
} | ||
return utils_1.quoteIfNeeded(fragmentsSpread.map(function (fragmentName) { return _this._convertName(fragmentName + 'Fragment', true); }), ' & '); | ||
return utils_1.quoteIfNeeded(fragmentsSpread.map(function (fragmentName) { | ||
return _this._convertName(fragmentName, { | ||
suffix: 'Fragment', | ||
useTypesPrefix: true | ||
}); | ||
}), ' & '); | ||
}; | ||
@@ -176,0 +183,0 @@ return SelectionSetToObject; |
@@ -0,1 +1,2 @@ | ||
import { ASTNode } from 'graphql'; | ||
export declare type ScalarsMap = { | ||
@@ -7,2 +8,13 @@ [name: string]: string; | ||
}; | ||
export declare type ConvertNameFn = (name: any, addPrefix: boolean) => string; | ||
export declare type ConvertNameFn<T = {}> = ConvertFn<T>; | ||
export interface ConvertOptions { | ||
prefix?: string; | ||
suffix?: string; | ||
} | ||
export declare type ConvertFn<T = {}> = (node: ASTNode | string, options?: ConvertOptions & T) => string; | ||
export declare type NamingConventionResolvePath = string; | ||
export declare type NamingConvention = string | NamingConventionMap; | ||
export interface NamingConventionMap { | ||
enumValues?: 'keep' | NamingConventionResolvePath | Function; | ||
typeNames?: 'keep' | NamingConventionResolvePath | Function; | ||
} |
import { TypeNode, VariableNode, NameNode, ValueNode } from 'graphql'; | ||
import { ScalarsMap, ConvertNameFn } from './types'; | ||
import { BaseVisitorConvertOptions } from './base-visitor'; | ||
export interface InterfaceOrVariable { | ||
@@ -11,4 +12,4 @@ name?: NameNode; | ||
protected _scalars: ScalarsMap; | ||
protected _convertName: ConvertNameFn; | ||
constructor(_scalars: ScalarsMap, _convertName: ConvertNameFn); | ||
protected _convertName: ConvertNameFn<BaseVisitorConvertOptions>; | ||
constructor(_scalars: ScalarsMap, _convertName: ConvertNameFn<BaseVisitorConvertOptions>); | ||
getName<TDefinitionType extends InterfaceOrVariable>(node: TDefinitionType): string; | ||
@@ -15,0 +16,0 @@ transform<TDefinitionType extends InterfaceOrVariable>(variablesNode: ReadonlyArray<TDefinitionType>): string; |
@@ -34,3 +34,6 @@ "use strict"; | ||
var typeName = typeof baseType === 'string' ? baseType : baseType.name.value; | ||
var typeValue = this._scalars[typeName] ? this._scalars[typeName] : this._convertName(typeName, true); | ||
var typeValue = this._scalars[typeName] || | ||
this._convertName(baseType, { | ||
useTypesPrefix: true | ||
}); | ||
var fieldName = this.getName(variable); | ||
@@ -37,0 +40,0 @@ var fieldType = this.wrapAstTypeWithModifiers(typeValue, variable.type); |
{ | ||
"name": "graphql-codegen-visitor-plugin-common", | ||
"version": "0.19.0-alpha.658f2fa9", | ||
"version": "0.19.0-alpha.6863e55f", | ||
"license": "MIT", | ||
@@ -11,3 +11,3 @@ "scripts": { | ||
"dependency-graph": "0.8.0", | ||
"graphql-codegen-core": "0.19.0-alpha.658f2fa9", | ||
"graphql-codegen-core": "0.19.0-alpha.6863e55f", | ||
"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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
112998
38
1614
+ Addedgraphql-codegen-core@0.19.0-alpha.6863e55f(transitive)
- Removedgraphql-codegen-core@0.19.0-alpha.658f2fa9(transitive)