|
| 1 | +# GenerateSource_ResolverWithGlobalStateArgument_MatchesSnapshot |
| 2 | + |
| 3 | +## HotChocolateResolvers.735550c.g.cs |
| 4 | + |
| 5 | +```csharp |
| 6 | +// <auto-generated/> |
| 7 | +
|
| 8 | +#nullable enable |
| 9 | +#pragma warning disable |
| 10 | + |
| 11 | +using System; |
| 12 | +using System.Runtime.CompilerServices; |
| 13 | +using HotChocolate; |
| 14 | +using HotChocolate.Types; |
| 15 | +using HotChocolate.Execution.Configuration; |
| 16 | +using HotChocolate.Internal; |
| 17 | + |
| 18 | +namespace TestNamespace |
| 19 | +{ |
| 20 | + internal static class TestTypeResolvers |
| 21 | + { |
| 22 | + private static bool _bindingsInitialized; |
| 23 | + private readonly static global::HotChocolate.Internal.IParameterBinding[] _args_TestType_GetTest = new global::HotChocolate.Internal.IParameterBinding[1]; |
| 24 | + |
| 25 | + public static void InitializeBindings(global::HotChocolate.Internal.IParameterBindingResolver bindingResolver) |
| 26 | + { |
| 27 | + if (_bindingsInitialized) |
| 28 | + { |
| 29 | + return; |
| 30 | + } |
| 31 | + _bindingsInitialized = true; |
| 32 | + |
| 33 | + const global::System.Reflection.BindingFlags bindingFlags = |
| 34 | + global::System.Reflection.BindingFlags.Public |
| 35 | + | global::System.Reflection.BindingFlags.NonPublic |
| 36 | + | global::System.Reflection.BindingFlags.Static; |
| 37 | + |
| 38 | + var type = typeof(global::TestNamespace.TestType); |
| 39 | + global::System.Reflection.MethodInfo resolver = default!; |
| 40 | + global::System.Reflection.ParameterInfo[] parameters = default!; |
| 41 | + |
| 42 | + resolver = type.GetMethod( |
| 43 | + "GetTest", |
| 44 | + bindingFlags, |
| 45 | + new global::System.Type[] |
| 46 | + { |
| 47 | + typeof(int) |
| 48 | + })!; |
| 49 | + parameters = resolver.GetParameters(); |
| 50 | + _args_TestType_GetTest[0] = bindingResolver.GetBinding(parameters[0]); |
| 51 | + } |
| 52 | + |
| 53 | + public static HotChocolate.Resolvers.FieldResolverDelegates TestType_GetTest() |
| 54 | + { |
| 55 | + if(!_bindingsInitialized) |
| 56 | + { |
| 57 | + throw new global::System.InvalidOperationException("The bindings must be initialized before the resolvers can be created."); |
| 58 | + } |
| 59 | + return new global::HotChocolate.Resolvers.FieldResolverDelegates(pureResolver: TestType_GetTest_Resolver); |
| 60 | + } |
| 61 | + |
| 62 | + private static global::System.Object? TestType_GetTest_Resolver(global::HotChocolate.Resolvers.IResolverContext context) |
| 63 | + { |
| 64 | + var args0 = context.GetGlobalState<int>("Test"); |
| 65 | + var result = global::TestNamespace.TestType.GetTest(args0); |
| 66 | + return result; |
| 67 | + } |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | + |
| 72 | +``` |
| 73 | + |
| 74 | +## HotChocolateTypeModule.735550c.g.cs |
| 75 | + |
| 76 | +```csharp |
| 77 | +// <auto-generated/> |
| 78 | +
|
| 79 | +#nullable enable |
| 80 | +#pragma warning disable |
| 81 | + |
| 82 | +using System; |
| 83 | +using System.Runtime.CompilerServices; |
| 84 | +using HotChocolate; |
| 85 | +using HotChocolate.Types; |
| 86 | +using HotChocolate.Execution.Configuration; |
| 87 | + |
| 88 | +namespace Microsoft.Extensions.DependencyInjection |
| 89 | +{ |
| 90 | + public static partial class TestsTypesRequestExecutorBuilderExtensions |
| 91 | + { |
| 92 | + public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder) |
| 93 | + { |
| 94 | + AddObjectTypeExtension_8734371<global::TestNamespace.Test>(builder, global::TestNamespace.TestType.Initialize); |
| 95 | + return builder; |
| 96 | + } |
| 97 | + |
| 98 | + private static void AddObjectTypeExtension_8734371<T>( |
| 99 | + global::HotChocolate.Execution.Configuration.IRequestExecutorBuilder builder, |
| 100 | + Action<IObjectTypeDescriptor<T>> initialize) |
| 101 | + { |
| 102 | + builder.ConfigureSchema(sb => |
| 103 | + { |
| 104 | + string typeName = typeof(T).FullName!; |
| 105 | + string typeKey = $"8734371_Type_ObjectType<{typeName}>"; |
| 106 | + string hooksKey = $"8734371_Hooks_ObjectType<{typeName}>"; |
| 107 | + |
| 108 | + if (!sb.ContextData.ContainsKey(typeKey)) |
| 109 | + { |
| 110 | + sb.AddObjectType<T>( |
| 111 | + descriptor => |
| 112 | + { |
| 113 | + var hooks = (global::System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)descriptor.Extend().Context.ContextData[hooksKey]!; |
| 114 | + foreach (var configure in hooks) |
| 115 | + { |
| 116 | + configure(descriptor); |
| 117 | + }; |
| 118 | + }); |
| 119 | + sb.ContextData.Add(typeKey, null); |
| 120 | + } |
| 121 | + |
| 122 | + if (!sb.ContextData.TryGetValue(hooksKey, out var value)) |
| 123 | + { |
| 124 | + value = new System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>(); |
| 125 | + sb.ContextData.Add(hooksKey, value); |
| 126 | + } |
| 127 | + |
| 128 | + ((System.Collections.Generic.List<Action<IObjectTypeDescriptor<T>>>)value!).Add(initialize); |
| 129 | + }); |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +``` |
| 135 | + |
| 136 | +## HotChocolateTypes.735550c.g.cs |
| 137 | + |
| 138 | +```csharp |
| 139 | +// <auto-generated/> |
| 140 | +
|
| 141 | +#nullable enable |
| 142 | +#pragma warning disable |
| 143 | + |
| 144 | +using System; |
| 145 | +using System.Runtime.CompilerServices; |
| 146 | +using HotChocolate; |
| 147 | +using HotChocolate.Types; |
| 148 | +using HotChocolate.Execution.Configuration; |
| 149 | +using Microsoft.Extensions.DependencyInjection; |
| 150 | + |
| 151 | +namespace TestNamespace |
| 152 | +{ |
| 153 | +public static partial class TestType |
| 154 | +{ |
| 155 | + internal static void Initialize(global::HotChocolate.Types.IObjectTypeDescriptor<global::TestNamespace.Test> descriptor) |
| 156 | + { |
| 157 | + const global::System.Reflection.BindingFlags bindingFlags = |
| 158 | + global::System.Reflection.BindingFlags.Public |
| 159 | + | global::System.Reflection.BindingFlags.NonPublic |
| 160 | + | global::System.Reflection.BindingFlags.Static; |
| 161 | + |
| 162 | + var thisType = typeof(global::TestNamespace.TestType); |
| 163 | + var bindingResolver = descriptor.Extend().Context.ParameterBindingResolver; |
| 164 | + global::TestNamespace.TestTypeResolvers.InitializeBindings(bindingResolver); |
| 165 | + |
| 166 | + descriptor |
| 167 | + .Field(thisType.GetMember("GetTest", bindingFlags)[0]) |
| 168 | + .ExtendWith(c => |
| 169 | + { |
| 170 | + c.Definition.SetSourceGeneratorFlags(); |
| 171 | + c.Definition.Resolvers = global::TestNamespace.TestTypeResolvers.TestType_GetTest(); |
| 172 | + }); |
| 173 | + |
| 174 | + Configure(descriptor); |
| 175 | + } |
| 176 | + |
| 177 | + static partial void Configure(global::HotChocolate.Types.IObjectTypeDescriptor<global::TestNamespace.Test> descriptor); |
| 178 | +} |
| 179 | +} |
| 180 | + |
| 181 | + |
| 182 | +``` |
| 183 | + |
0 commit comments