Skip to content

Commit 9890365

Browse files
committed
Fixed source gen issues
1 parent 5d0b836 commit 9890365

11 files changed

+55
-325
lines changed

src/HotChocolate/Core/src/Types/Types/Descriptors/TypeConfiguration.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,16 @@ internal void Apply<TDescriptor>(
7474
TDescriptor descriptor)
7575
where TDescriptor : IDescriptor
7676
{
77-
if (_configurations.TryGetValue(runtimeType, out var list))
77+
lock (_sync)
7878
{
79-
foreach (var item in list)
79+
if (_configurations.TryGetValue(runtimeType, out var list))
8080
{
81-
if (item is Func<Action<TDescriptor>> factory)
81+
foreach (var item in list)
8282
{
83-
factory()(descriptor);
83+
if (item is Func<Action<TDescriptor>> factory)
84+
{
85+
factory()(descriptor);
86+
}
8487
}
8588
}
8689
}
@@ -91,13 +94,16 @@ internal void Apply<TDescriptor>(
9194
TDescriptor descriptor)
9295
where TDescriptor : IDescriptor
9396
{
94-
if (_namedConfigurations.TryGetValue(typeName, out var list))
97+
lock (_sync)
9598
{
96-
foreach (var item in list)
99+
if (_namedConfigurations.TryGetValue(typeName, out var list))
97100
{
98-
if (item is Func<Action<TDescriptor>> factory)
101+
foreach (var item in list)
99102
{
100-
factory()(descriptor);
103+
if (item is Func<Action<TDescriptor>> factory)
104+
{
105+
factory()(descriptor);
106+
}
101107
}
102108
}
103109
}

src/HotChocolate/Core/src/Types/Types/ObjectType.Initialization.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected override ObjectTypeDefinition CreateDefinition(
3333

3434
if (!descriptor.Definition.NeedsNameCompletion)
3535
{
36-
context.DescriptorContext.TypeConfiguration.Apply(Name, descriptor);
36+
context.DescriptorContext.TypeConfiguration.Apply(descriptor.Definition.Name, descriptor);
3737
}
3838

3939
return descriptor.CreateDefinition();

src/HotChocolate/Core/test/Types.Analyzers.Tests/__snapshots__/ObjectTypeTests.GenerateSource_BatchDataLoader_MatchesSnapshot.md

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -101,43 +101,12 @@ namespace Microsoft.Extensions.DependencyInjection
101101
{
102102
public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder)
103103
{
104-
AddObjectTypeExtension_8734371<global::TestNamespace.Book>(builder, global::TestNamespace.BookNode.Initialize);
104+
builder.ConfigureDescriptorContext(ctx => ctx.TypeConfiguration.TryAdd<global::TestNamespace.Book>(
105+
"Tests::TestNamespace.BookNode",
106+
() => global::TestNamespace.BookNode.Initialize));
107+
builder.AddType<ObjectType<global::TestNamespace.Book>>();
105108
return builder;
106109
}
107-
108-
private static void AddObjectTypeExtension_8734371<T>(
109-
global::HotChocolate.Execution.Configuration.IRequestExecutorBuilder builder,
110-
Action<IObjectTypeDescriptor<T>> initialize)
111-
{
112-
builder.ConfigureSchema(sb =>
113-
{
114-
string typeName = typeof(T).FullName!;
115-
string typeKey = $"8734371_Type_ObjectType<{typeName}>";
116-
string hooksKey = $"8734371_Hooks_ObjectType<{typeName}>";
117-
118-
if (!sb.ContextData.ContainsKey(typeKey))
119-
{
120-
sb.AddObjectType<T>(
121-
descriptor =>
122-
{
123-
var hooks = (global::System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)descriptor.Extend().Context.ContextData[hooksKey]!;
124-
foreach (var configure in hooks)
125-
{
126-
configure(descriptor);
127-
};
128-
});
129-
sb.ContextData.Add(typeKey, null);
130-
}
131-
132-
if (!sb.ContextData.TryGetValue(hooksKey, out var value))
133-
{
134-
value = new System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>();
135-
sb.ContextData.Add(hooksKey, value);
136-
}
137-
138-
((System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)value!).Add(initialize);
139-
});
140-
}
141110
}
142111
}
143112

src/HotChocolate/Core/test/Types.Analyzers.Tests/__snapshots__/ResolverTests.GenerateSource_ResolverWithGlobalStateArgument_MatchesSnapshot.md

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -97,43 +97,12 @@ namespace Microsoft.Extensions.DependencyInjection
9797
{
9898
public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder)
9999
{
100-
AddObjectTypeExtension_8734371<global::TestNamespace.Test>(builder, global::TestNamespace.TestType.Initialize);
100+
builder.ConfigureDescriptorContext(ctx => ctx.TypeConfiguration.TryAdd<global::TestNamespace.Test>(
101+
"Tests::TestNamespace.TestType",
102+
() => global::TestNamespace.TestType.Initialize));
103+
builder.AddType<ObjectType<global::TestNamespace.Test>>();
101104
return builder;
102105
}
103-
104-
private static void AddObjectTypeExtension_8734371<T>(
105-
global::HotChocolate.Execution.Configuration.IRequestExecutorBuilder builder,
106-
Action<IObjectTypeDescriptor<T>> initialize)
107-
{
108-
builder.ConfigureSchema(sb =>
109-
{
110-
string typeName = typeof(T).FullName!;
111-
string typeKey = $"8734371_Type_ObjectType<{typeName}>";
112-
string hooksKey = $"8734371_Hooks_ObjectType<{typeName}>";
113-
114-
if (!sb.ContextData.ContainsKey(typeKey))
115-
{
116-
sb.AddObjectType<T>(
117-
descriptor =>
118-
{
119-
var hooks = (global::System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)descriptor.Extend().Context.ContextData[hooksKey]!;
120-
foreach (var configure in hooks)
121-
{
122-
configure(descriptor);
123-
};
124-
});
125-
sb.ContextData.Add(typeKey, null);
126-
}
127-
128-
if (!sb.ContextData.TryGetValue(hooksKey, out var value))
129-
{
130-
value = new System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>();
131-
sb.ContextData.Add(hooksKey, value);
132-
}
133-
134-
((System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)value!).Add(initialize);
135-
});
136-
}
137106
}
138107
}
139108

src/HotChocolate/Core/test/Types.Analyzers.Tests/__snapshots__/ResolverTests.GenerateSource_ResolverWithGlobalStateSetStateArgument_MatchesSnapshot.md

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -97,43 +97,12 @@ namespace Microsoft.Extensions.DependencyInjection
9797
{
9898
public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder)
9999
{
100-
AddObjectTypeExtension_8734371<global::TestNamespace.Test>(builder, global::TestNamespace.TestType.Initialize);
100+
builder.ConfigureDescriptorContext(ctx => ctx.TypeConfiguration.TryAdd<global::TestNamespace.Test>(
101+
"Tests::TestNamespace.TestType",
102+
() => global::TestNamespace.TestType.Initialize));
103+
builder.AddType<ObjectType<global::TestNamespace.Test>>();
101104
return builder;
102105
}
103-
104-
private static void AddObjectTypeExtension_8734371<T>(
105-
global::HotChocolate.Execution.Configuration.IRequestExecutorBuilder builder,
106-
Action<IObjectTypeDescriptor<T>> initialize)
107-
{
108-
builder.ConfigureSchema(sb =>
109-
{
110-
string typeName = typeof(T).FullName!;
111-
string typeKey = $"8734371_Type_ObjectType<{typeName}>";
112-
string hooksKey = $"8734371_Hooks_ObjectType<{typeName}>";
113-
114-
if (!sb.ContextData.ContainsKey(typeKey))
115-
{
116-
sb.AddObjectType<T>(
117-
descriptor =>
118-
{
119-
var hooks = (global::System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)descriptor.Extend().Context.ContextData[hooksKey]!;
120-
foreach (var configure in hooks)
121-
{
122-
configure(descriptor);
123-
};
124-
});
125-
sb.ContextData.Add(typeKey, null);
126-
}
127-
128-
if (!sb.ContextData.TryGetValue(hooksKey, out var value))
129-
{
130-
value = new System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>();
131-
sb.ContextData.Add(hooksKey, value);
132-
}
133-
134-
((System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)value!).Add(initialize);
135-
});
136-
}
137106
}
138107
}
139108

src/HotChocolate/Core/test/Types.Analyzers.Tests/__snapshots__/ResolverTests.GenerateSource_ResolverWithLocalStateArgument_MatchesSnapshot.md

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -97,43 +97,12 @@ namespace Microsoft.Extensions.DependencyInjection
9797
{
9898
public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder)
9999
{
100-
AddObjectTypeExtension_8734371<global::TestNamespace.Test>(builder, global::TestNamespace.TestType.Initialize);
100+
builder.ConfigureDescriptorContext(ctx => ctx.TypeConfiguration.TryAdd<global::TestNamespace.Test>(
101+
"Tests::TestNamespace.TestType",
102+
() => global::TestNamespace.TestType.Initialize));
103+
builder.AddType<ObjectType<global::TestNamespace.Test>>();
101104
return builder;
102105
}
103-
104-
private static void AddObjectTypeExtension_8734371<T>(
105-
global::HotChocolate.Execution.Configuration.IRequestExecutorBuilder builder,
106-
Action<IObjectTypeDescriptor<T>> initialize)
107-
{
108-
builder.ConfigureSchema(sb =>
109-
{
110-
string typeName = typeof(T).FullName!;
111-
string typeKey = $"8734371_Type_ObjectType<{typeName}>";
112-
string hooksKey = $"8734371_Hooks_ObjectType<{typeName}>";
113-
114-
if (!sb.ContextData.ContainsKey(typeKey))
115-
{
116-
sb.AddObjectType<T>(
117-
descriptor =>
118-
{
119-
var hooks = (global::System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)descriptor.Extend().Context.ContextData[hooksKey]!;
120-
foreach (var configure in hooks)
121-
{
122-
configure(descriptor);
123-
};
124-
});
125-
sb.ContextData.Add(typeKey, null);
126-
}
127-
128-
if (!sb.ContextData.TryGetValue(hooksKey, out var value))
129-
{
130-
value = new System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>();
131-
sb.ContextData.Add(hooksKey, value);
132-
}
133-
134-
((System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)value!).Add(initialize);
135-
});
136-
}
137106
}
138107
}
139108

src/HotChocolate/Core/test/Types.Analyzers.Tests/__snapshots__/ResolverTests.GenerateSource_ResolverWithLocalStateSetStateArgument_MatchesSnapshot.md

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -97,43 +97,12 @@ namespace Microsoft.Extensions.DependencyInjection
9797
{
9898
public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder)
9999
{
100-
AddObjectTypeExtension_8734371<global::TestNamespace.Test>(builder, global::TestNamespace.TestType.Initialize);
100+
builder.ConfigureDescriptorContext(ctx => ctx.TypeConfiguration.TryAdd<global::TestNamespace.Test>(
101+
"Tests::TestNamespace.TestType",
102+
() => global::TestNamespace.TestType.Initialize));
103+
builder.AddType<ObjectType<global::TestNamespace.Test>>();
101104
return builder;
102105
}
103-
104-
private static void AddObjectTypeExtension_8734371<T>(
105-
global::HotChocolate.Execution.Configuration.IRequestExecutorBuilder builder,
106-
Action<IObjectTypeDescriptor<T>> initialize)
107-
{
108-
builder.ConfigureSchema(sb =>
109-
{
110-
string typeName = typeof(T).FullName!;
111-
string typeKey = $"8734371_Type_ObjectType<{typeName}>";
112-
string hooksKey = $"8734371_Hooks_ObjectType<{typeName}>";
113-
114-
if (!sb.ContextData.ContainsKey(typeKey))
115-
{
116-
sb.AddObjectType<T>(
117-
descriptor =>
118-
{
119-
var hooks = (global::System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)descriptor.Extend().Context.ContextData[hooksKey]!;
120-
foreach (var configure in hooks)
121-
{
122-
configure(descriptor);
123-
};
124-
});
125-
sb.ContextData.Add(typeKey, null);
126-
}
127-
128-
if (!sb.ContextData.TryGetValue(hooksKey, out var value))
129-
{
130-
value = new System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>();
131-
sb.ContextData.Add(hooksKey, value);
132-
}
133-
134-
((System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)value!).Add(initialize);
135-
});
136-
}
137106
}
138107
}
139108

src/HotChocolate/Core/test/Types.Analyzers.Tests/__snapshots__/ResolverTests.GenerateSource_ResolverWithScopedStateArgument_MatchesSnapshot.md

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -97,43 +97,12 @@ namespace Microsoft.Extensions.DependencyInjection
9797
{
9898
public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder)
9999
{
100-
AddObjectTypeExtension_8734371<global::TestNamespace.Test>(builder, global::TestNamespace.TestType.Initialize);
100+
builder.ConfigureDescriptorContext(ctx => ctx.TypeConfiguration.TryAdd<global::TestNamespace.Test>(
101+
"Tests::TestNamespace.TestType",
102+
() => global::TestNamespace.TestType.Initialize));
103+
builder.AddType<ObjectType<global::TestNamespace.Test>>();
101104
return builder;
102105
}
103-
104-
private static void AddObjectTypeExtension_8734371<T>(
105-
global::HotChocolate.Execution.Configuration.IRequestExecutorBuilder builder,
106-
Action<IObjectTypeDescriptor<T>> initialize)
107-
{
108-
builder.ConfigureSchema(sb =>
109-
{
110-
string typeName = typeof(T).FullName!;
111-
string typeKey = $"8734371_Type_ObjectType<{typeName}>";
112-
string hooksKey = $"8734371_Hooks_ObjectType<{typeName}>";
113-
114-
if (!sb.ContextData.ContainsKey(typeKey))
115-
{
116-
sb.AddObjectType<T>(
117-
descriptor =>
118-
{
119-
var hooks = (global::System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)descriptor.Extend().Context.ContextData[hooksKey]!;
120-
foreach (var configure in hooks)
121-
{
122-
configure(descriptor);
123-
};
124-
});
125-
sb.ContextData.Add(typeKey, null);
126-
}
127-
128-
if (!sb.ContextData.TryGetValue(hooksKey, out var value))
129-
{
130-
value = new System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>();
131-
sb.ContextData.Add(hooksKey, value);
132-
}
133-
134-
((System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)value!).Add(initialize);
135-
});
136-
}
137106
}
138107
}
139108

src/HotChocolate/Core/test/Types.Analyzers.Tests/__snapshots__/ResolverTests.GenerateSource_ResolverWithScopedStateSetStateArgument_MatchesSnapshot.md

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -97,43 +97,12 @@ namespace Microsoft.Extensions.DependencyInjection
9797
{
9898
public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder)
9999
{
100-
AddObjectTypeExtension_8734371<global::TestNamespace.Test>(builder, global::TestNamespace.TestType.Initialize);
100+
builder.ConfigureDescriptorContext(ctx => ctx.TypeConfiguration.TryAdd<global::TestNamespace.Test>(
101+
"Tests::TestNamespace.TestType",
102+
() => global::TestNamespace.TestType.Initialize));
103+
builder.AddType<ObjectType<global::TestNamespace.Test>>();
101104
return builder;
102105
}
103-
104-
private static void AddObjectTypeExtension_8734371<T>(
105-
global::HotChocolate.Execution.Configuration.IRequestExecutorBuilder builder,
106-
Action<IObjectTypeDescriptor<T>> initialize)
107-
{
108-
builder.ConfigureSchema(sb =>
109-
{
110-
string typeName = typeof(T).FullName!;
111-
string typeKey = $"8734371_Type_ObjectType<{typeName}>";
112-
string hooksKey = $"8734371_Hooks_ObjectType<{typeName}>";
113-
114-
if (!sb.ContextData.ContainsKey(typeKey))
115-
{
116-
sb.AddObjectType<T>(
117-
descriptor =>
118-
{
119-
var hooks = (global::System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)descriptor.Extend().Context.ContextData[hooksKey]!;
120-
foreach (var configure in hooks)
121-
{
122-
configure(descriptor);
123-
};
124-
});
125-
sb.ContextData.Add(typeKey, null);
126-
}
127-
128-
if (!sb.ContextData.TryGetValue(hooksKey, out var value))
129-
{
130-
value = new System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>();
131-
sb.ContextData.Add(hooksKey, value);
132-
}
133-
134-
((System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)value!).Add(initialize);
135-
});
136-
}
137106
}
138107
}
139108

0 commit comments

Comments
 (0)