Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override void WriteBeginClass(IOutputTypeInfo type)
"{0} partial class {1} : ObjectType<global::{2}>",
type.IsPublic ? "public" : "internal",
type.Name,
type.RuntimeTypeFullName);
type.RuntimeTypeName?.FullName);
Writer.WriteIndentedLine("{");
Writer.IncreaseIndent();
}
Expand All @@ -32,7 +32,7 @@ public override void WriteInitializeMethod(IOutputTypeInfo type, ILocalTypeLooku
Writer.WriteIndentedLine(
"protected override void Configure(global::{0}<global::{1}> descriptor)",
WellKnownTypes.IObjectTypeDescriptor,
connectionType.RuntimeTypeFullName);
connectionType.RuntimeTypeName.FullName);

Writer.WriteIndentedLine("{");

Expand All @@ -48,7 +48,7 @@ public override void WriteInitializeMethod(IOutputTypeInfo type, ILocalTypeLooku
{
Writer.WriteIndentedLine(
"var thisType = typeof(global::{0});",
connectionType.RuntimeTypeFullName);
connectionType.RuntimeTypeName.FullName);
Writer.WriteIndentedLine(
"var bindingResolver = extension.Context.ParameterBindingResolver;");
Writer.WriteIndentedLine(
Expand Down Expand Up @@ -106,15 +106,14 @@ public override void WriteInitializeMethod(IOutputTypeInfo type, ILocalTypeLooku
}
}

if (connectionType.RuntimeType.IsGenericType
if (connectionType.NodeFullyQualifiedName is not null
&& !string.IsNullOrEmpty(connectionType.NameFormat)
&& connectionType.NameFormat!.Contains("{0}"))
{
var nodeTypeName = connectionType.RuntimeType.TypeArguments[0].ToFullyQualified();
Writer.WriteLine();
Writer.WriteIndentedLine(
"var nodeTypeRef = extension.Context.TypeInspector.GetTypeRef(typeof({0}));",
nodeTypeName);
connectionType.NodeFullyQualifiedName);
Writer.WriteIndentedLine("descriptor");
using (Writer.IncreaseIndent())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Text;
using HotChocolate.Types.Analyzers.Generators;
using HotChocolate.Types.Analyzers.Helpers;
using HotChocolate.Types.Analyzers.Models;

namespace HotChocolate.Types.Analyzers.FileBuilders;
Expand All @@ -15,7 +14,7 @@ public override void WriteBeginClass(IOutputTypeInfo type)
"{0} partial class {1} : ObjectType<global::{2}>",
type.IsPublic ? "public" : "internal",
type.Name,
type.RuntimeTypeFullName);
type.RuntimeTypeName?.FullName);
Comment thread
glen-84 marked this conversation as resolved.
Outdated
Writer.WriteIndentedLine("{");
Writer.IncreaseIndent();
}
Expand All @@ -31,7 +30,7 @@ public override void WriteInitializeMethod(IOutputTypeInfo type, ILocalTypeLooku
Writer.WriteIndentedLine(
"protected override void Configure(global::{0}<global::{1}> descriptor)",
WellKnownTypes.IObjectTypeDescriptor,
edgeType.RuntimeTypeFullName);
edgeType.RuntimeTypeName.FullName);

Writer.WriteIndentedLine("{");

Expand All @@ -47,7 +46,7 @@ public override void WriteInitializeMethod(IOutputTypeInfo type, ILocalTypeLooku
{
Writer.WriteIndentedLine(
"var thisType = typeof(global::{0});",
edgeType.RuntimeTypeFullName);
edgeType.RuntimeTypeName.FullName);
Writer.WriteIndentedLine(
"var bindingResolver = extension.Context.ParameterBindingResolver;");
Writer.WriteIndentedLine(
Expand Down Expand Up @@ -105,15 +104,14 @@ public override void WriteInitializeMethod(IOutputTypeInfo type, ILocalTypeLooku
}
}

if (edgeType.RuntimeType.IsGenericType
if (edgeType.NodeFullyQualifiedName is not null
&& !string.IsNullOrEmpty(edgeType.NameFormat)
&& edgeType.NameFormat!.Contains("{0}"))
{
var nodeTypeName = edgeType.RuntimeType.TypeArguments[0].ToFullyQualified();
Writer.WriteLine();
Writer.WriteIndentedLine(
"var nodeTypeRef = extension.Context.TypeInspector.GetTypeRef(typeof({0}));",
nodeTypeName);
edgeType.NodeFullyQualifiedName);
Writer.WriteIndentedLine("descriptor");
using (Writer.IncreaseIndent())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public override void WriteInitializeMethod(IOutputTypeInfo type, ILocalTypeLooku
Writer.WriteIndentedLine(
"internal static void Initialize(global::{0}<global::{1}> descriptor)",
WellKnownTypes.IInterfaceTypeDescriptor,
interfaceType.RuntimeTypeFullName);
interfaceType.RuntimeTypeName.FullName);

Writer.WriteIndentedLine("{");

using (Writer.IncreaseIndent())
{
WriteInitializationBase(
interfaceType.SchemaTypeFullName,
interfaceType.SchemaTypeName.FullName,
interfaceType.Resolvers.Length > 0,
interfaceType.Resolvers.Any(t => t.RequiresParameterBindings),
interfaceType.DescriptorAttributes,
Expand All @@ -53,7 +53,7 @@ public override void WriteConfigureMethod(IOutputTypeInfo type)
Writer.WriteIndentedLine(
"static partial void Configure(global::{0}<global::{1}> descriptor);",
WellKnownTypes.IInterfaceTypeDescriptor,
interfaceType.RuntimeTypeFullName);
interfaceType.RuntimeTypeName.FullName);
Writer.WriteLine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public override void WriteInitializeMethod(IOutputTypeInfo type, ILocalTypeLooku
Writer.WriteIndentedLine(
"internal static void Initialize(global::{0}<global::{1}> descriptor)",
WellKnownTypes.IObjectTypeDescriptor,
objectType.RuntimeTypeFullName);
objectType.RuntimeTypeName.FullName);

Writer.WriteIndentedLine("{");

using (Writer.IncreaseIndent())
{
WriteInitializationBase(
objectType.SchemaTypeFullName,
objectType.SchemaTypeName.FullName,
objectType.Resolvers.Length > 0 || objectType.NodeResolver is not null,
objectType.Resolvers.Any(t => t.RequiresParameterBindings)
|| (objectType.NodeResolver?.RequiresParameterBindings ?? false),
Expand Down Expand Up @@ -92,7 +92,7 @@ public override void WriteResolverConstructor(IOutputTypeInfo type, ILocalTypeLo
WriteResolverConstructor(
objectType,
typeLookup,
$"global::{objectType.SchemaTypeFullName}",
$"global::{objectType.SchemaTypeName.FullName}",
type.Resolvers.Any(t => t.RequiresParameterBindings)
|| (objectType.NodeResolver?.RequiresParameterBindings ?? false));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Text;
using HotChocolate.Types.Analyzers.Generators;
using HotChocolate.Types.Analyzers.Helpers;
using HotChocolate.Types.Analyzers.Models;

namespace HotChocolate.Types.Analyzers.FileBuilders;
Expand All @@ -26,7 +25,7 @@ public override void WriteInitializeMethod(IOutputTypeInfo type, ILocalTypeLooku
using (Writer.IncreaseIndent())
{
WriteInitializationBase(
rootType.SchemaSchemaType.ToFullyQualified(),
rootType.SchemaTypeName.FullyQualifiedName,
rootType.Resolvers.Length > 0,
rootType.Resolvers.Any(t => t.RequiresParameterBindings),
rootType.DescriptorAttributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ protected void WriteFieldFlags(Resolver resolver)

public virtual void WriteConfigureMethod(IOutputTypeInfo type)
{
if (type.RuntimeType is null)
if (type.RuntimeTypeName is null)
{
Writer.WriteIndentedLine(
"static partial void Configure(global::HotChocolate.Types.IObjectTypeDescriptor descriptor);");
Expand All @@ -545,7 +545,7 @@ public virtual void WriteConfigureMethod(IOutputTypeInfo type)
{
Writer.WriteIndentedLine(
"static partial void Configure(global::HotChocolate.Types.IObjectTypeDescriptor<{0}> descriptor);",
type.RuntimeType.ToFullyQualified());
type.RuntimeTypeName.FullyQualifiedName);
}

Writer.WriteLine();
Expand Down Expand Up @@ -595,14 +595,15 @@ protected void WriteResolverField(Resolver resolver)

public virtual void WriteResolverConstructor(IOutputTypeInfo type, ILocalTypeLookup typeLookup)
{
var resolverType =
type.SchemaSchemaType ??
type.RuntimeType ?? throw new InvalidOperationException("Schema type and runtime type are null.");
var resolverTypeName =
type.SchemaTypeName?.FullyQualifiedName
?? type.RuntimeTypeName?.FullyQualifiedName
?? throw new InvalidOperationException("Schema type and runtime type are null.");

WriteResolverConstructor(
type,
typeLookup,
resolverType.ToFullyQualified(),
resolverTypeName,

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolverTypeName is computed and passed into WriteResolverConstructor(...), but the resolverTypeName parameter is never used inside TypeFileBuilderBase (only referenced at the call site and in the signature). This adds noise and risks future divergence. Either remove the parameter entirely (and the computation), or use it inside the constructor generation logic if it’s intended to influence output.

Copilot uses AI. Check for mistakes.
type.Resolvers.Any(t => t.RequiresParameterBindings));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ private static void WriteConfiguration(
&& objectTypeExtension.Diagnostics.Length == 0)
{
objectTypeExtensions ??= [];
objectTypeExtensions.Add(objectTypeExtension.RuntimeType.ToFullyQualified());
objectTypeExtensions.Add(objectTypeExtension.RuntimeTypeName.FullyQualifiedName);

generator.WriteRegisterTypeExtension(
GetAssemblyQualifiedName(objectTypeExtension.SchemaSchemaType),
objectTypeExtension.RuntimeType.ToFullyQualified(),
objectTypeExtension.SchemaSchemaType.ToFullyQualified());
objectTypeExtension.RegistrationKey,
objectTypeExtension.RuntimeTypeName.FullyQualifiedName,
objectTypeExtension.SchemaTypeName.FullyQualifiedName);
hasConfigurations = true;
}

Expand Down Expand Up @@ -185,12 +185,12 @@ private static void WriteConfiguration(
&& interfaceType.Diagnostics.Length == 0)
{
interfaceTypeExtensions ??= [];
interfaceTypeExtensions.Add(interfaceType.RuntimeType.ToFullyQualified());
interfaceTypeExtensions.Add(interfaceType.RuntimeTypeName.FullyQualifiedName);

generator.WriteRegisterTypeExtension(
GetAssemblyQualifiedName(interfaceType.SchemaSchemaType),
interfaceType.RuntimeType.ToFullyQualified(),
interfaceType.SchemaSchemaType.ToFullyQualified());
interfaceType.RegistrationKey,
interfaceType.RuntimeTypeName.FullyQualifiedName,
interfaceType.SchemaTypeName.FullyQualifiedName);
hasConfigurations = true;
}

Expand All @@ -203,9 +203,9 @@ private static void WriteConfiguration(
var operationType = rootType.OperationType;

generator.WriteRegisterRootTypeExtension(
GetAssemblyQualifiedName(rootType.SchemaSchemaType),
rootType.RegistrationKey,
operationType,
rootType.SchemaSchemaType.ToFullyQualified());
rootType.SchemaTypeName.FullyQualifiedName);
hasConfigurations = true;

if (operationType is not OperationType.No && (operations & operationType) != operationType)
Expand Down Expand Up @@ -311,11 +311,4 @@ private static void WriteOperationTypes(

addSource(WellKnownFileNames.RootTypesFile, generator.ToString());
}

public static string GetAssemblyQualifiedName(ITypeSymbol typeSymbol)
{
var assemblyName = typeSymbol.ContainingAssembly?.Name ?? "UnknownAssembly";
var typeFullName = typeSymbol.ToDisplayString();
return $"{assemblyName}::{typeFullName}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,13 @@ public static bool IsNullableValueType(this ITypeSymbol typeSymbol)
public static string PrintNullRefQualifier(this ITypeSymbol typeSymbol)
=> typeSymbol.IsNullableRefType() ? "?" : string.Empty;

public static string ToAssemblyQualified(this ITypeSymbol typeSymbol)
{
var assemblyName = typeSymbol.ContainingAssembly?.Name ?? "UnknownAssembly";
var typeFullName = typeSymbol.ToDisplayString();
return $"{assemblyName}::{typeFullName}";
}

public static string ToFullyQualified(this ITypeSymbol typeSymbol)
=> typeSymbol.ToDisplayString(FullyQualifiedFormat);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public ImmutableArray<SyntaxInfo> Transform(
if (syntaxInfo is IOutputTypeInfo { HasRuntimeType: true } typeInfo)
{
#if NET8_0_OR_GREATER
connectionTypeLookup[typeInfo.RuntimeTypeFullName] = typeInfo;
connectionTypeLookup[typeInfo.RuntimeTypeName.FullName] = typeInfo;
#else
connectionTypeLookup[typeInfo.RuntimeTypeFullName!] = typeInfo;
connectionTypeLookup[typeInfo.RuntimeTypeName!.FullName] = typeInfo;
#endif

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connectionTypeLookup is seeded with RuntimeTypeName.FullName, but later lookups/additions use keys prefixed with "global::" (e.g., connectionTypeName). This inconsistency means existing types won't be found and can lead to duplicate generated connection/edge types (potentially causing duplicate AddSource hint names / generator failures). Use a consistent key representation—likely RuntimeTypeName.FullyQualifiedName (and drop manual "global::" concatenation or keep it consistent everywhere).

Copilot uses AI. Check for mistakes.
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,29 @@ private ConnectionTypeInfo(
ImmutableArray<AttributeData> attributes)
{
Name = name;
RuntimeTypeName = TypeNameInfo.Create(runtimeType);
NodeFullyQualifiedName = runtimeType.IsGenericType ? runtimeType.TypeArguments[0].ToFullyQualified() : null;
NameFormat = nameFormat;
EdgeTypeName = edgeTypeName;
RuntimeTypeFullName = runtimeType.ToDisplayString();
RuntimeType = runtimeType;
Namespace = runtimeType.ContainingNamespace.ToDisplayString();
IsPublic = runtimeType.DeclaredAccessibility == Accessibility.Public;
ClassDeclaration = classDeclaration;
Resolvers = resolvers;
Attributes = attributes;
Shareable = attributes.GetShareableScope();
Inaccessible = attributes.GetInaccessibleScope();
DescriptorAttributes = attributes.GetUserAttributes();
}

public string Name { get; }

public TypeNameInfo? SchemaTypeName => null;

public TypeNameInfo RuntimeTypeName { get; }

public string? NodeFullyQualifiedName { get; }

public string? RegistrationKey => null;

public string? NameFormat { get; }

public string EdgeTypeName { get; }
Expand All @@ -43,32 +51,22 @@ private ConnectionTypeInfo(

public string? Description => null;

public bool IsPublic => RuntimeType.DeclaredAccessibility == Accessibility.Public;

public INamedTypeSymbol? SchemaSchemaType => null;

public string? SchemaTypeFullName => null;
public bool IsPublic { get; }

public bool HasSchemaType => false;

public INamedTypeSymbol RuntimeType { get; }

public string RuntimeTypeFullName { get; }

public bool HasRuntimeType => true;

public ClassDeclarationSyntax? ClassDeclaration { get; }

public ImmutableArray<Resolver> Resolvers { get; private set; }

public override string OrderByKey => RuntimeTypeFullName;
public override string OrderByKey => RuntimeTypeName.FullName;

public DirectiveScope Shareable { get; }

public DirectiveScope Inaccessible { get; }

public ImmutableArray<AttributeData> Attributes { get; }

public ImmutableArray<AttributeData> DescriptorAttributes { get; }

public void ReplaceResolver(Resolver current, Resolver replacement)
Expand Down
Loading
Loading