Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -11,11 +10,17 @@ public sealed class EdgeTypeFileBuilder(StringBuilder sb) : TypeFileBuilderBase(

public override void WriteBeginClass(IOutputTypeInfo type)
{
if (type is not EdgeTypeInfo edgeType)
{
throw new InvalidOperationException(
"The specified type is not an edge type.");
}

Writer.WriteIndentedLine(
"{0} partial class {1} : ObjectType<global::{2}>",
type.IsPublic ? "public" : "internal",
type.Name,
type.RuntimeTypeFullName);
edgeType.IsPublic ? "public" : "internal",
edgeType.Name,
edgeType.RuntimeTypeName.FullName);
Writer.WriteIndentedLine("{");
Writer.IncreaseIndent();
}
Expand All @@ -31,7 +36,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 +52,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 +110,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,6 @@ public override void WriteResolverConstructor(IOutputTypeInfo type, ILocalTypeLo
WriteResolverConstructor(
objectType,
typeLookup,
$"global::{objectType.SchemaTypeFullName}",
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 @@ -600,7 +600,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 @@ -609,7 +609,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 @@ -675,21 +675,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.");

WriteResolverConstructor(
type,
typeLookup,
resolverType.ToFullyQualified(),
type.Resolvers.Any(t => t.RequiresParameterBindings));
}

protected void WriteResolverConstructor(
IOutputTypeInfo type,
ILocalTypeLookup typeLookup,
string resolverTypeName,
bool requiresParameterBindings)
{
if (!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 @@ -685,6 +685,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 @@ -49,11 +49,7 @@ public ImmutableArray<SyntaxInfo> Transform(
{
if (syntaxInfo is IOutputTypeInfo { HasRuntimeType: true } typeInfo)
{
#if NET8_0_OR_GREATER
connectionTypeLookup[typeInfo.RuntimeTypeFullName] = typeInfo;
#else
connectionTypeLookup[typeInfo.RuntimeTypeFullName!] = typeInfo;
#endif
connectionTypeLookup[GetTypeLookupKey(typeInfo)] = typeInfo;
}
}

Expand Down Expand Up @@ -161,8 +157,8 @@ public ImmutableArray<SyntaxInfo> Transform(
connection.Name,
connection.NameFormat ?? connection.Name);

var connectionTypeName = "global::" + connectionTypeInfo.Namespace + "." + connectionTypeInfo.Name;
var edgeTypeName = "global::" + edgeTypeInfo.Namespace + "." + edgeTypeInfo.Name;
var connectionTypeName = GetTypeLookupKey(connectionTypeInfo);
var edgeTypeName = GetTypeLookupKey(edgeTypeInfo);

if (!connectionTypeLookup.ContainsKey(connectionTypeName))
{
Expand Down Expand Up @@ -240,8 +236,8 @@ public ImmutableArray<SyntaxInfo> Transform(
connectionName,
connectionName);

var connectionTypeName = "global::" + connectionTypeInfo.Namespace + "." + connectionTypeInfo.Name;
var edgeTypeName = "global::" + edgeTypeInfo.Namespace + "." + edgeTypeInfo.Name;
var connectionTypeName = GetTypeLookupKey(connectionTypeInfo);
var edgeTypeName = GetTypeLookupKey(edgeTypeInfo);

if (!connectionTypeLookup.ContainsKey(connectionTypeName))
{
Expand Down Expand Up @@ -307,6 +303,12 @@ private static INamedTypeSymbol GetConnectionType(
static void Throw() => throw new InvalidOperationException("Could not resolve connection base type.");
}

private static string GetTypeLookupKey(IOutputTypeInfo typeInfo)
=> GetTypeLookupKey(typeInfo.Namespace, typeInfo.Name);

private static string GetTypeLookupKey(string typeNamespace, string typeName)
=> $"global::{typeNamespace}.{typeName}";

private static GenericTypeInfo? CreateGenericTypeInfo(
INamedTypeSymbol genericType,
ISymbol resolver,
Expand Down
Loading
Loading