Skip to content

Commit f1b9da5

Browse files
committed
Colocate Edge and Connection Type (#8152)
1 parent d3cb1e2 commit f1b9da5

5 files changed

+31
-15
lines changed

src/HotChocolate/Core/src/Types.Analyzers/Inspectors/ConnectionTypeTransformer.cs

+14-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public ImmutableArray<SyntaxInfo> Transform(
116116
edgeTypeInfo = EdgeTypeInfo.CreateEdge(
117117
compilation,
118118
connectionType,
119-
null);
119+
null,
120+
connectionType.ContainingNamespace.ToDisplayString());
120121
edgeTypeInfo.AddDiagnosticRange(diagnostics);
121122
connectionTypeInfos ??= [];
122123
connectionTypeInfos.Add(edgeTypeInfo);
@@ -129,12 +130,14 @@ public ImmutableArray<SyntaxInfo> Transform(
129130
compilation,
130131
edge.Type,
131132
edgeClass.ClassDeclarations,
133+
connectionType.ContainingNamespace.ToDisplayString(),
132134
edge.Name,
133135
edge.NameFormat ?? edge.Name)
134136
: EdgeTypeInfo.CreateEdge(
135137
compilation,
136138
edge.Type,
137139
null,
140+
connectionType.ContainingNamespace.ToDisplayString(),
138141
edge.Name,
139142
edge.NameFormat ?? edge.Name);
140143

@@ -180,7 +183,7 @@ public ImmutableArray<SyntaxInfo> Transform(
180183
continue;
181184
}
182185

183-
string connectionFullTypeName = connectionType.ToFullyQualified();
186+
var connectionFullTypeName = connectionType.ToFullyQualified();
184187
string? connectionName = null;
185188
string? edgeName = null;
186189

@@ -205,8 +208,15 @@ public ImmutableArray<SyntaxInfo> Transform(
205208

206209
edgeTypeInfo =
207210
connectionClassLookup.TryGetValue(edgeType.ToFullyQualified(), out edgeClass)
208-
? EdgeTypeInfo.CreateEdgeFrom(edgeClass, edgeName, edgeName)
209-
: EdgeTypeInfo.CreateEdge(compilation, edgeType, null, edgeName, edgeName);
211+
? EdgeTypeInfo.CreateEdgeFrom(
212+
edgeClass,
213+
connectionType.ContainingNamespace.ToDisplayString(),
214+
edgeName,
215+
edgeName)
216+
: EdgeTypeInfo.CreateEdge(compilation, edgeType, null,
217+
connectionType.ContainingNamespace.ToDisplayString(),
218+
edgeName,
219+
edgeName);
210220

211221
connectionTypeInfo =
212222
connectionClassLookup.TryGetValue(connectionFullTypeName, out connectionClass)

src/HotChocolate/Core/src/Types.Analyzers/Models/EdgeTypeInfo.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public sealed class EdgeTypeInfo
1313
private EdgeTypeInfo(
1414
string name,
1515
string? nameFormat,
16+
string @namespace,
1617
INamedTypeSymbol runtimeType,
1718
ClassDeclarationSyntax? classDeclaration,
1819
ImmutableArray<Resolver> resolvers)
@@ -21,7 +22,7 @@ private EdgeTypeInfo(
2122
NameFormat = nameFormat;
2223
RuntimeTypeFullName = runtimeType.ToDisplayString();
2324
RuntimeType = runtimeType;
24-
Namespace = runtimeType.ContainingNamespace.ToDisplayString();
25+
Namespace = @namespace;
2526
ClassDeclaration = classDeclaration;
2627
Resolvers = resolvers;
2728
}
@@ -87,12 +88,14 @@ public override int GetHashCode()
8788

8889
public static EdgeTypeInfo CreateEdgeFrom(
8990
ConnectionClassInfo connectionClass,
91+
string @namespace,
9092
string? name = null,
9193
string? nameFormat = null)
9294
{
9395
return new EdgeTypeInfo(
9496
(name ?? connectionClass.RuntimeType.Name) + "Type",
9597
nameFormat,
98+
@namespace,
9699
connectionClass.RuntimeType,
97100
connectionClass.ClassDeclarations,
98101
connectionClass.Resolvers);
@@ -102,14 +105,16 @@ public static EdgeTypeInfo CreateEdge(
102105
Compilation compilation,
103106
INamedTypeSymbol runtimeType,
104107
ClassDeclarationSyntax? classDeclaration,
108+
string @namespace,
105109
string? name = null,
106110
string? nameFormat = null)
107-
=> Create(compilation, runtimeType, classDeclaration, name, nameFormat);
111+
=> Create(compilation, runtimeType, classDeclaration, @namespace, name, nameFormat);
108112

109113
private static EdgeTypeInfo Create(
110114
Compilation compilation,
111115
INamedTypeSymbol runtimeType,
112116
ClassDeclarationSyntax? classDeclaration,
117+
string @namespace,
113118
string? name = null,
114119
string? nameFormat = null)
115120
{
@@ -141,6 +146,7 @@ private static EdgeTypeInfo Create(
141146
return new EdgeTypeInfo(
142147
edgeName,
143148
nameFormat,
149+
@namespace,
144150
runtimeType,
145151
classDeclaration,
146152
resolvers.ToImmutable());

src/HotChocolate/Core/test/Types.Analyzers.Tests/__snapshots__/PagingTests.GenerateSource_Inherit_From_ConnectionBase_Reuse_PageEdge.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace TestNamespace
114114

115115
```
116116

117-
## AuthorEdgeType.GMN8-ZMy56jZWutjKaKAXQ.hc.g.cs
117+
## AuthorEdgeType.WaAdMHmlGJHjtEI4nqY7WA.hc.g.cs
118118

119119
```csharp
120120
// <auto-generated/>
@@ -130,7 +130,7 @@ using HotChocolate.Execution.Configuration;
130130
using Microsoft.Extensions.DependencyInjection;
131131
using HotChocolate.Internal;
132132

133-
namespace HotChocolate.Types.Pagination
133+
namespace TestNamespace
134134
{
135135
public partial class AuthorEdgeType : ObjectType<global::HotChocolate.Types.Pagination.PageEdge<TestNamespace.Author>>
136136
{
@@ -305,7 +305,7 @@ namespace Microsoft.Extensions.DependencyInjection
305305
{
306306
public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder)
307307
{
308-
builder.AddType<global::HotChocolate.Types.Pagination.AuthorEdgeType>();
308+
builder.AddType<global::TestNamespace.AuthorEdgeType>();
309309
builder.AddType<global::TestNamespace.AuthorConnectionType>();
310310
builder.ConfigureDescriptorContext(ctx => ctx.TypeConfiguration.TryAdd(
311311
"Tests::TestNamespace.Types.Root.AuthorQueries",

src/HotChocolate/Core/test/Types.Analyzers.Tests/__snapshots__/PagingTests.GenerateSource_Inherit_From_ConnectionBase_Reuse_PageEdge_Generic.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ namespace TestNamespace
117117

118118
```
119119

120-
## AuthorEdgeType.GMN8-ZMy56jZWutjKaKAXQ.hc.g.cs
120+
## AuthorEdgeType.WaAdMHmlGJHjtEI4nqY7WA.hc.g.cs
121121

122122
```csharp
123123
// <auto-generated/>
@@ -133,7 +133,7 @@ using HotChocolate.Execution.Configuration;
133133
using Microsoft.Extensions.DependencyInjection;
134134
using HotChocolate.Internal;
135135

136-
namespace HotChocolate.Types.Pagination
136+
namespace TestNamespace
137137
{
138138
public partial class AuthorEdgeType : ObjectType<global::HotChocolate.Types.Pagination.PageEdge<TestNamespace.Author>>
139139
{
@@ -311,7 +311,7 @@ namespace Microsoft.Extensions.DependencyInjection
311311
{
312312
public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder)
313313
{
314-
builder.AddType<global::HotChocolate.Types.Pagination.AuthorEdgeType>();
314+
builder.AddType<global::TestNamespace.AuthorEdgeType>();
315315
builder.AddType<global::TestNamespace.AuthorCustomConnectionType>();
316316
builder.ConfigureDescriptorContext(ctx => ctx.TypeConfiguration.TryAdd(
317317
"Tests::TestNamespace.Types.Root.AuthorQueries",

src/HotChocolate/Core/test/Types.Analyzers.Tests/__snapshots__/PagingTests.GenerateSource_Inherit_From_PageConnection.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ namespace TestNamespace
134134

135135
```
136136

137-
## AuthorEdgeType.GMN8-ZMy56jZWutjKaKAXQ.hc.g.cs
137+
## AuthorEdgeType.WaAdMHmlGJHjtEI4nqY7WA.hc.g.cs
138138

139139
```csharp
140140
// <auto-generated/>
@@ -150,7 +150,7 @@ using HotChocolate.Execution.Configuration;
150150
using Microsoft.Extensions.DependencyInjection;
151151
using HotChocolate.Internal;
152152

153-
namespace HotChocolate.Types.Pagination
153+
namespace TestNamespace
154154
{
155155
public partial class AuthorEdgeType : ObjectType<global::HotChocolate.Types.Pagination.PageEdge<TestNamespace.Author>>
156156
{
@@ -325,7 +325,7 @@ namespace Microsoft.Extensions.DependencyInjection
325325
{
326326
public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder)
327327
{
328-
builder.AddType<global::HotChocolate.Types.Pagination.AuthorEdgeType>();
328+
builder.AddType<global::TestNamespace.AuthorEdgeType>();
329329
builder.AddType<global::TestNamespace.AuthorConnectionType>();
330330
builder.ConfigureDescriptorContext(ctx => ctx.TypeConfiguration.TryAdd(
331331
"Tests::TestNamespace.Types.Root.AuthorQueries",

0 commit comments

Comments
 (0)