Skip to content

Commit

Permalink
Fixed snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Feb 23, 2022
1 parent 6d19b79 commit 0e68db9
Show file tree
Hide file tree
Showing 34 changed files with 1,499 additions and 5,319 deletions.
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using HotChocolate;
using StrawberryShake.CodeGeneration.CSharp.Builders;
using StrawberryShake.CodeGeneration.CSharp.Extensions;
Expand Down Expand Up @@ -95,7 +94,7 @@ public class DependencyInjectionGenerator : CodeGenerator<DependencyInjectionDes
descriptor.TransportProfiles[0].Name);
}

foreach (var profile in descriptor.TransportProfiles)
foreach (TransportProfile profile in descriptor.TransportProfiles)
{
GenerateClientForProfile(settings, factory, descriptor, profile);
}
Expand Down Expand Up @@ -129,7 +128,7 @@ public class DependencyInjectionGenerator : CodeGenerator<DependencyInjectionDes
private static ICode GenerateClientServiceProviderFactory(
DependencyInjectionDescriptor descriptor)
{
CodeBlockBuilder codeBuilder = CodeBlockBuilder.New();
var codeBuilder = CodeBlockBuilder.New();

if (descriptor.TransportProfiles.Count == 1)
{
Expand All @@ -154,7 +153,7 @@ public class DependencyInjectionGenerator : CodeGenerator<DependencyInjectionDes
.AddArgument(_serviceCollection)));
}

IfBuilder ifProfile = IfBuilder.New();
var ifProfile = IfBuilder.New();

var enumName = CreateProfileEnumReference(descriptor);
for (var index = 0; index < descriptor.TransportProfiles.Count; index++)
Expand Down Expand Up @@ -423,13 +422,12 @@ private static string CreateProfileEnumReference(DependencyInjectionDescriptor d

body.AddEmptyLine();

foreach (var typeDescriptor in descriptor.TypeDescriptors
foreach (INamedTypeDescriptor typeDescriptor in descriptor.TypeDescriptors
.OfType<INamedTypeDescriptor>())
{
if (typeDescriptor.Kind == TypeKind.Entity && !typeDescriptor.IsInterface())
{
INamedTypeDescriptor namedTypeDescriptor =
(INamedTypeDescriptor)typeDescriptor.NamedType();
var namedTypeDescriptor = (INamedTypeDescriptor)typeDescriptor.NamedType();
NameString className = namedTypeDescriptor.ExtractMapperName();

var interfaceName =
Expand All @@ -447,7 +445,7 @@ private static string CreateProfileEnumReference(DependencyInjectionDescriptor d

body.AddEmptyLine();

foreach (var enumType in descriptor.EnumTypeDescriptor)
foreach (EnumTypeDescriptor enumType in descriptor.EnumTypeDescriptor)
{
body.AddMethodCall()
.SetMethodName(TypeNames.AddSingleton)
Expand All @@ -465,7 +463,8 @@ private static string CreateProfileEnumReference(DependencyInjectionDescriptor d
.AddArgument(_services);
}

foreach (var scalarTypes in descriptor.TypeDescriptors.OfType<ScalarTypeDescriptor>())
foreach (ScalarTypeDescriptor scalarTypes in
descriptor.TypeDescriptors.OfType<ScalarTypeDescriptor>())
{
if (_alternativeTypeNames.TryGetValue(scalarTypes.Name.Value, out var serializer))
{
Expand All @@ -482,7 +481,8 @@ private static string CreateProfileEnumReference(DependencyInjectionDescriptor d
}

var stringTypeInfo = new RuntimeTypeInfo(TypeNames.String);
foreach (var scalar in descriptor.TypeDescriptors.OfType<ScalarTypeDescriptor>())
foreach (ScalarTypeDescriptor scalar in
descriptor.TypeDescriptors.OfType<ScalarTypeDescriptor>())
{
if (scalar.RuntimeType.Equals(stringTypeInfo) &&
scalar.SerializationType.Equals(stringTypeInfo) &&
Expand All @@ -500,8 +500,8 @@ private static string CreateProfileEnumReference(DependencyInjectionDescriptor d
}
}

foreach (var inputTypeDescriptor in descriptor.TypeDescriptors
.Where(x => x.Kind is TypeKind.Input))
foreach (ITypeDescriptor inputTypeDescriptor in
descriptor.TypeDescriptors.Where(x => x.Kind is TypeKind.Input))
{
var formatter =
CreateInputValueFormatter(
Expand All @@ -518,7 +518,7 @@ private static string CreateProfileEnumReference(DependencyInjectionDescriptor d

body.AddEmptyLine();

foreach (var operation in descriptor.Operations)
foreach (OperationDescriptor operation in descriptor.Operations)
{
if (!(operation.ResultTypeReference is InterfaceTypeDescriptor typeDescriptor))
{
Expand All @@ -533,21 +533,21 @@ private static string CreateProfileEnumReference(DependencyInjectionDescriptor d
_ => throw ThrowHelper.DependencyInjection_InvalidOperationKind(operation)
};

string connectionKind = operationKind switch
var connectionKind = operationKind switch
{
TransportType.Http => TypeNames.IHttpConnection,
TransportType.WebSocket => TypeNames.IWebSocketConnection,
TransportType.InMemory => TypeNames.IInMemoryConnection,
var v => throw ThrowHelper.DependencyInjection_InvalidTransportType(v)
};

string operationName = operation.Name;
string fullName = operation.RuntimeType.ToString();
string operationInterfaceName = operation.InterfaceType.ToString();
string resultInterface = typeDescriptor.RuntimeType.ToString();
var operationName = operation.Name.Value;
var fullName = operation.RuntimeType.ToString();
var operationInterfaceName = operation.InterfaceType.ToString();
var resultInterface = typeDescriptor.RuntimeType.ToString();

// The factories are generated based on the concrete result type, which is the
// only implementee of the result type interface.
// only implementer of the result type interface.

var factoryName =
CreateResultFactoryName(
Expand Down Expand Up @@ -696,6 +696,18 @@ private static string CreateProfileEnumReference(DependencyInjectionDescriptor d
TypeNames.JsonDocument,
resultInterface))
.AddArgument(_sp)))
.AddArgument(
LambdaBuilder
.New()
.SetCode(
MethodCallBuilder
.Inline()
.SetMethodName(
TypeNames.GetRequiredService)
.AddGeneric(
TypeNames.IResultPatcher.WithGeneric(
TypeNames.JsonDocument))
.AddArgument(_sp)))
.If(settings.IsStoreEnabled(),
x => x
.AddArgument(
Expand All @@ -705,6 +717,12 @@ private static string CreateProfileEnumReference(DependencyInjectionDescriptor d
.AddGeneric(TypeNames.IOperationStore)
.AddArgument(_sp))
.AddArgument(_strategy)))))
.AddCode(MethodCallBuilder
.New()
.SetMethodName(TypeNames.AddSingleton)
.AddGeneric(TypeNames.IResultPatcher.WithGeneric(TypeNames.JsonDocument))
.AddGeneric(TypeNames.JsonResultPatcher)
.AddArgument(_services))
.AddCode(MethodCallBuilder
.New()
.SetMethodName(TypeNames.AddSingleton)
Expand Down
Expand Up @@ -41,6 +41,12 @@ public static class TypeNames
public const string OperationResultBuilder =
StrawberryShakeNamespace + "OperationResultBuilder";

public const string IResultPatcher =
StrawberryShakeNamespace + "IResultPatcher";

public const string JsonResultPatcher =
StrawberryShakeNamespace + "Json.JsonResultPatcher";

public const string ISerializerResolver =
StrawberryShakeNamespace + "Serialization.ISerializerResolver";

Expand Down

0 comments on commit 0e68db9

Please sign in to comment.