diff --git a/src/StrawberryShake/Client/src/Transport.InMemory/DependencyInjection/InMemoryClient.cs b/src/StrawberryShake/Client/src/Transport.InMemory/DependencyInjection/InMemoryClient.cs index e0594bc1b8a..223e4b9f456 100644 --- a/src/StrawberryShake/Client/src/Transport.InMemory/DependencyInjection/InMemoryClient.cs +++ b/src/StrawberryShake/Client/src/Transport.InMemory/DependencyInjection/InMemoryClient.cs @@ -152,9 +152,9 @@ await interceptor { value = (source, key) switch { - (Dictionary s, string prop) => s[prop], - (List l, int i) => l[i], - _ => null, + (Dictionary s, string prop) when s.ContainsKey(prop) => s[prop], + (List l, int i) when i < l.Count => l[i], + _ => null }; } diff --git a/src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/Generators/OperationServiceGenerator.cs b/src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/Generators/OperationServiceGenerator.cs index b870886d0cb..993cc75d213 100644 --- a/src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/Generators/OperationServiceGenerator.cs +++ b/src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/Generators/OperationServiceGenerator.cs @@ -446,7 +446,7 @@ private MethodBuilder CreateRequestMethod(OperationDescriptor descriptor) } else if (argument.Type.NamedType() is not ScalarTypeDescriptor { Name: "Upload" }) { - return; + continue; } classBuilder diff --git a/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/OperationDescriptorMapper.cs b/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/OperationDescriptorMapper.cs index 54e07fb5868..2ce4dc2ffbd 100644 --- a/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/OperationDescriptorMapper.cs +++ b/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/OperationDescriptorMapper.cs @@ -25,7 +25,7 @@ public static void Map(ClientModel model, IMapperContext context) var namedTypeDescriptor = context.Types.Single(type => type.Name.EqualsOrdinal(typeName)); - hasUpload = namedTypeDescriptor.HasUpload(); + hasUpload = hasUpload || namedTypeDescriptor.HasUpload(); return new PropertyDescriptor( arg.Name, diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/InputGeneratorTests.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/InputGeneratorTests.cs index 7d5cf96bd43..e7a73a26451 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/InputGeneratorTests.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/InputGeneratorTests.cs @@ -229,4 +229,40 @@ scalar Upload ", "extend schema @key(fields: \"id\")"); } + + [Fact] + public void Operation_With_FirstNonUpload() + { + AssertResult( + @"query test( + $string: String! + $upload: Upload!) { + foo(string: $string upload: $upload) + }", + @"type Query { + foo(string: String! upload: Upload!): String + } + + scalar Upload + ", + "extend schema @key(fields: \"id\")"); + } + + [Fact] + public void Operation_With_LastNonUpload() + { + AssertResult( + @"query test( + $upload: Upload! + $string: String!) { + foo(string: $string upload: $upload) + }", + @"type Query { + foo(string: String! upload: Upload!): String + } + + scalar Upload + ", + "extend schema @key(fields: \"id\")"); + } } diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/TestGeneration.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/TestGeneration.cs index 3d17f6ba792..94e373c7b67 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/TestGeneration.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/TestGeneration.cs @@ -264,6 +264,7 @@ public class TestGeneration */ private const string UploadQueries = @" query TestUpload( + $nonUpload: String $single: Upload $list: [Upload] $nested: [[Upload]] @@ -271,6 +272,7 @@ public class TestGeneration $objectList: [TestInput] $objectNested: [[TestInput]]) { upload( + nonUpload: $nonUpload single: $single list: $list nested: $nested @@ -281,6 +283,7 @@ public class TestGeneration private const string UploadSchema = @" type Query { upload( + nonUpload: String single: Upload list: [Upload] nested: [[Upload]] diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalarTest.Client.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalarTest.Client.cs index 9e0ddce46a7..795e4864486 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalarTest.Client.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalarTest.Client.cs @@ -542,8 +542,8 @@ public partial class BazInput : global::StrawberryShake.CodeGeneration.CSharp.In /// /// Represents the operation service of the TestUpload GraphQL operation /// - /// query TestUpload($single: Upload, $list: [Upload], $nested: [[Upload]], $object: TestInput, $objectList: [TestInput], $objectNested: [[TestInput]]) { - /// upload(single: $single, list: $list, nested: $nested, object: $object, objectList: $objectList, objectNested: $objectNested) + /// query TestUpload($nonUpload: String, $single: Upload, $list: [Upload], $nested: [[Upload]], $object: TestInput, $objectList: [TestInput], $objectNested: [[TestInput]]) { + /// upload(nonUpload: $nonUpload, single: $single, list: $list, nested: $nested, object: $object, objectList: $objectList, objectNested: $objectNested) /// } /// /// @@ -556,8 +556,8 @@ private TestUploadQueryDocument() public static TestUploadQueryDocument Instance { get; } = new TestUploadQueryDocument(); public global::StrawberryShake.OperationKind Kind => global::StrawberryShake.OperationKind.Query; - public global::System.ReadOnlySpan Body => new global::System.Byte[]{0x71, 0x75, 0x65, 0x72, 0x79, 0x20, 0x54, 0x65, 0x73, 0x74, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x24, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x3a, 0x20, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x2c, 0x20, 0x24, 0x6c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x5b, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x5d, 0x2c, 0x20, 0x24, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x5b, 0x5b, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x5d, 0x5d, 0x2c, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x3a, 0x20, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x2c, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x5b, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x5d, 0x2c, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x5b, 0x5b, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x5d, 0x5d, 0x29, 0x20, 0x7b, 0x20, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x3a, 0x20, 0x24, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x2c, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x24, 0x6c, 0x69, 0x73, 0x74, 0x2c, 0x20, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x24, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x2c, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x3a, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2c, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x2c, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x29, 0x20, 0x7d}; - public global::StrawberryShake.DocumentHash Hash { get; } = new global::StrawberryShake.DocumentHash("sha1Hash", "6bf1f196920f143f9b98f6df1876adc9ef634c8c"); + public global::System.ReadOnlySpan Body => new global::System.Byte[]{0x71, 0x75, 0x65, 0x72, 0x79, 0x20, 0x54, 0x65, 0x73, 0x74, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x24, 0x6e, 0x6f, 0x6e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x3a, 0x20, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2c, 0x20, 0x24, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x3a, 0x20, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x2c, 0x20, 0x24, 0x6c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x5b, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x5d, 0x2c, 0x20, 0x24, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x5b, 0x5b, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x5d, 0x5d, 0x2c, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x3a, 0x20, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x2c, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x5b, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x5d, 0x2c, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x5b, 0x5b, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x5d, 0x5d, 0x29, 0x20, 0x7b, 0x20, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x6e, 0x6f, 0x6e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x3a, 0x20, 0x24, 0x6e, 0x6f, 0x6e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x2c, 0x20, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x3a, 0x20, 0x24, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x2c, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x24, 0x6c, 0x69, 0x73, 0x74, 0x2c, 0x20, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x24, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x2c, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x3a, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2c, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x2c, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x29, 0x20, 0x7d}; + public global::StrawberryShake.DocumentHash Hash { get; } = new global::StrawberryShake.DocumentHash("sha1Hash", "7cd8f1db7bb9937a9b48c70ce9dc152f52782f96"); public override global::System.String ToString() { #if NETCOREAPP3_1_OR_GREATER @@ -572,8 +572,8 @@ private TestUploadQueryDocument() /// /// Represents the operation service of the TestUpload GraphQL operation /// - /// query TestUpload($single: Upload, $list: [Upload], $nested: [[Upload]], $object: TestInput, $objectList: [TestInput], $objectNested: [[TestInput]]) { - /// upload(single: $single, list: $list, nested: $nested, object: $object, objectList: $objectList, objectNested: $objectNested) + /// query TestUpload($nonUpload: String, $single: Upload, $list: [Upload], $nested: [[Upload]], $object: TestInput, $objectList: [TestInput], $objectNested: [[TestInput]]) { + /// upload(nonUpload: $nonUpload, single: $single, list: $list, nested: $nested, object: $object, objectList: $objectList, objectNested: $objectNested) /// } /// /// @@ -581,19 +581,21 @@ private TestUploadQueryDocument() public partial class TestUploadQuery : global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar.ITestUploadQuery { private readonly global::StrawberryShake.IOperationExecutor _operationExecutor; + private readonly global::StrawberryShake.Serialization.IInputValueFormatter _stringFormatter; private readonly global::StrawberryShake.Serialization.IInputValueFormatter _uploadFormatter; private readonly global::StrawberryShake.Serialization.IInputValueFormatter _testInputFormatter; public TestUploadQuery(global::StrawberryShake.IOperationExecutor operationExecutor, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver) { _operationExecutor = operationExecutor ?? throw new global::System.ArgumentNullException(nameof(operationExecutor)); + _stringFormatter = serializerResolver.GetInputValueFormatter("String"); _uploadFormatter = serializerResolver.GetInputValueFormatter("Upload"); _testInputFormatter = serializerResolver.GetInputValueFormatter("TestInput"); } global::System.Type global::StrawberryShake.IOperationRequestFactory.ResultType => typeof(ITestUploadResult); - public async global::System.Threading.Tasks.Task> ExecuteAsync(global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::System.Threading.CancellationToken cancellationToken = default) + public async global::System.Threading.Tasks.Task> ExecuteAsync(global::System.String? nonUpload, global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::System.Threading.CancellationToken cancellationToken = default) { - var request = CreateRequest(single, list, nested, @object, objectList, objectNested); + var request = CreateRequest(nonUpload, single, list, nested, @object, objectList, objectNested); return await _operationExecutor.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); } @@ -711,15 +713,16 @@ private void MapFilesFromArgumentObjectNested(global::System.String path, global } } - public global::System.IObservable> Watch(global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::StrawberryShake.ExecutionStrategy? strategy = null) + public global::System.IObservable> Watch(global::System.String? nonUpload, global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::StrawberryShake.ExecutionStrategy? strategy = null) { - var request = CreateRequest(single, list, nested, @object, objectList, objectNested); + var request = CreateRequest(nonUpload, single, list, nested, @object, objectList, objectNested); return _operationExecutor.Watch(request, strategy); } - private global::StrawberryShake.OperationRequest CreateRequest(global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested) + private global::StrawberryShake.OperationRequest CreateRequest(global::System.String? nonUpload, global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested) { var variables = new global::System.Collections.Generic.Dictionary(); + variables.Add("nonUpload", FormatNonUpload(nonUpload)); variables.Add("single", FormatSingle(single)); variables.Add("list", FormatList(list)); variables.Add("nested", FormatNested(nested)); @@ -741,6 +744,18 @@ private void MapFilesFromArgumentObjectNested(global::System.String path, global return new global::StrawberryShake.OperationRequest(id: TestUploadQueryDocument.Instance.Hash.Value, name: "TestUpload", document: TestUploadQueryDocument.Instance, strategy: global::StrawberryShake.RequestStrategy.Default, files: files, variables: variables); } + private global::System.Object? FormatNonUpload(global::System.String? value) + { + if (value is null) + { + return value; + } + else + { + return _stringFormatter.Format(value); + } + } + private global::System.Object? FormatSingle(global::StrawberryShake.Upload? value) { if (value is null) @@ -901,16 +916,16 @@ private void MapFilesFromArgumentObjectNested(global::System.String path, global /// /// Represents the operation service of the TestUpload GraphQL operation /// - /// query TestUpload($single: Upload, $list: [Upload], $nested: [[Upload]], $object: TestInput, $objectList: [TestInput], $objectNested: [[TestInput]]) { - /// upload(single: $single, list: $list, nested: $nested, object: $object, objectList: $objectList, objectNested: $objectNested) + /// query TestUpload($nonUpload: String, $single: Upload, $list: [Upload], $nested: [[Upload]], $object: TestInput, $objectList: [TestInput], $objectNested: [[TestInput]]) { + /// upload(nonUpload: $nonUpload, single: $single, list: $list, nested: $nested, object: $object, objectList: $objectList, objectNested: $objectNested) /// } /// /// [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] public partial interface ITestUploadQuery : global::StrawberryShake.IOperationRequestFactory { - global::System.Threading.Tasks.Task> ExecuteAsync(global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::System.Threading.CancellationToken cancellationToken = default); - global::System.IObservable> Watch(global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::StrawberryShake.ExecutionStrategy? strategy = null); + global::System.Threading.Tasks.Task> ExecuteAsync(global::System.String? nonUpload, global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::System.Threading.CancellationToken cancellationToken = default); + global::System.IObservable> Watch(global::System.String? nonUpload, global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::StrawberryShake.ExecutionStrategy? strategy = null); } // StrawberryShake.CodeGeneration.CSharp.Generators.ClientGenerator @@ -1025,15 +1040,15 @@ public partial class TestUploadBuilder : global::StrawberryShake.OperationResult { private readonly global::StrawberryShake.IEntityStore _entityStore; private readonly global::StrawberryShake.IEntityIdSerializer _idSerializer; - private readonly global::StrawberryShake.Serialization.ILeafValueParser _uploadParser; private readonly global::StrawberryShake.Serialization.ILeafValueParser _stringParser; + private readonly global::StrawberryShake.Serialization.ILeafValueParser _uploadParser; public TestUploadBuilder(global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer idSerializer, global::StrawberryShake.IOperationResultDataFactory resultDataFactory, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver) { _entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore)); _idSerializer = idSerializer ?? throw new global::System.ArgumentNullException(nameof(idSerializer)); ResultDataFactory = resultDataFactory ?? throw new global::System.ArgumentNullException(nameof(resultDataFactory)); - _uploadParser = serializerResolver.GetLeafValueParser("Upload") ?? throw new global::System.ArgumentException("No serializer for type `Upload` found."); _stringParser = serializerResolver.GetLeafValueParser("String") ?? throw new global::System.ArgumentException("No serializer for type `String` found."); + _uploadParser = serializerResolver.GetLeafValueParser("Upload") ?? throw new global::System.ArgumentException("No serializer for type `Upload` found."); } protected override global::StrawberryShake.IOperationResultDataFactory ResultDataFactory { get; } diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalarTest.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalarTest.cs index 891d57da8cc..a1664259c3b 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalarTest.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalarTest.cs @@ -23,6 +23,7 @@ public async Task Execute_UploadScalar_Argument() // act var result = await client.TestUpload.ExecuteAsync( + "foo", new Upload(data, "test-file"), null, null, @@ -47,6 +48,7 @@ public async Task Execute_UploadScalarList_Argument() // act var result = await client.TestUpload.ExecuteAsync( + "foo", null, new Upload?[] { new Upload(dataA, "A"), new Upload(dataB, "B") }, null, @@ -71,6 +73,7 @@ public async Task Execute_UploadScalarNested_Argument() // act var result = await client.TestUpload.ExecuteAsync( + "foo", null, null, new[] { new Upload?[] { new Upload(dataA, "A"), new Upload(dataB, "B") } }, @@ -94,6 +97,7 @@ public async Task Execute_Input_Argument() // act var result = await client.TestUpload.ExecuteAsync( + "foo", null, null, null, @@ -123,6 +127,7 @@ public async Task Execute_InputList_Argument() using var dataB = CreateStream("b"); // act var result = await client.TestUpload.ExecuteAsync( + "foo", null, null, null, @@ -163,6 +168,7 @@ public async Task Execute_InputNested_Argument() // act var result = await client.TestUpload.ExecuteAsync( + "foo", null, null, null, @@ -220,6 +226,7 @@ public async Task Execute_ListWorksWithNull() // act var result = await client.TestUpload.ExecuteAsync( + "foo", null, new Upload?[] { new Upload(dataA, "A"), null, new Upload(dataB, "B") }, null, diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalar_InMemoryTest.Client.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalar_InMemoryTest.Client.cs index 1fbefa86a8c..0a7365eb561 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalar_InMemoryTest.Client.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalar_InMemoryTest.Client.cs @@ -542,8 +542,8 @@ public partial class BazInput : global::StrawberryShake.CodeGeneration.CSharp.In /// /// Represents the operation service of the TestUpload GraphQL operation /// - /// query TestUpload($single: Upload, $list: [Upload], $nested: [[Upload]], $object: TestInput, $objectList: [TestInput], $objectNested: [[TestInput]]) { - /// upload(single: $single, list: $list, nested: $nested, object: $object, objectList: $objectList, objectNested: $objectNested) + /// query TestUpload($nonUpload: String, $single: Upload, $list: [Upload], $nested: [[Upload]], $object: TestInput, $objectList: [TestInput], $objectNested: [[TestInput]]) { + /// upload(nonUpload: $nonUpload, single: $single, list: $list, nested: $nested, object: $object, objectList: $objectList, objectNested: $objectNested) /// } /// /// @@ -556,8 +556,8 @@ private TestUploadQueryDocument() public static TestUploadQueryDocument Instance { get; } = new TestUploadQueryDocument(); public global::StrawberryShake.OperationKind Kind => global::StrawberryShake.OperationKind.Query; - public global::System.ReadOnlySpan Body => new global::System.Byte[]{0x71, 0x75, 0x65, 0x72, 0x79, 0x20, 0x54, 0x65, 0x73, 0x74, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x24, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x3a, 0x20, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x2c, 0x20, 0x24, 0x6c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x5b, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x5d, 0x2c, 0x20, 0x24, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x5b, 0x5b, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x5d, 0x5d, 0x2c, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x3a, 0x20, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x2c, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x5b, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x5d, 0x2c, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x5b, 0x5b, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x5d, 0x5d, 0x29, 0x20, 0x7b, 0x20, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x3a, 0x20, 0x24, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x2c, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x24, 0x6c, 0x69, 0x73, 0x74, 0x2c, 0x20, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x24, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x2c, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x3a, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2c, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x2c, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x29, 0x20, 0x7d}; - public global::StrawberryShake.DocumentHash Hash { get; } = new global::StrawberryShake.DocumentHash("sha1Hash", "6bf1f196920f143f9b98f6df1876adc9ef634c8c"); + public global::System.ReadOnlySpan Body => new global::System.Byte[]{0x71, 0x75, 0x65, 0x72, 0x79, 0x20, 0x54, 0x65, 0x73, 0x74, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x24, 0x6e, 0x6f, 0x6e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x3a, 0x20, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2c, 0x20, 0x24, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x3a, 0x20, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x2c, 0x20, 0x24, 0x6c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x5b, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x5d, 0x2c, 0x20, 0x24, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x5b, 0x5b, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x5d, 0x5d, 0x2c, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x3a, 0x20, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x2c, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x5b, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x5d, 0x2c, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x5b, 0x5b, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x5d, 0x5d, 0x29, 0x20, 0x7b, 0x20, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x6e, 0x6f, 0x6e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x3a, 0x20, 0x24, 0x6e, 0x6f, 0x6e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x2c, 0x20, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x3a, 0x20, 0x24, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x2c, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x24, 0x6c, 0x69, 0x73, 0x74, 0x2c, 0x20, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x24, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x2c, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x3a, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2c, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x3a, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x2c, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x24, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x29, 0x20, 0x7d}; + public global::StrawberryShake.DocumentHash Hash { get; } = new global::StrawberryShake.DocumentHash("sha1Hash", "7cd8f1db7bb9937a9b48c70ce9dc152f52782f96"); public override global::System.String ToString() { #if NETCOREAPP3_1_OR_GREATER @@ -572,8 +572,8 @@ private TestUploadQueryDocument() /// /// Represents the operation service of the TestUpload GraphQL operation /// - /// query TestUpload($single: Upload, $list: [Upload], $nested: [[Upload]], $object: TestInput, $objectList: [TestInput], $objectNested: [[TestInput]]) { - /// upload(single: $single, list: $list, nested: $nested, object: $object, objectList: $objectList, objectNested: $objectNested) + /// query TestUpload($nonUpload: String, $single: Upload, $list: [Upload], $nested: [[Upload]], $object: TestInput, $objectList: [TestInput], $objectNested: [[TestInput]]) { + /// upload(nonUpload: $nonUpload, single: $single, list: $list, nested: $nested, object: $object, objectList: $objectList, objectNested: $objectNested) /// } /// /// @@ -581,19 +581,21 @@ private TestUploadQueryDocument() public partial class TestUploadQuery : global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar_InMemory.ITestUploadQuery { private readonly global::StrawberryShake.IOperationExecutor _operationExecutor; + private readonly global::StrawberryShake.Serialization.IInputValueFormatter _stringFormatter; private readonly global::StrawberryShake.Serialization.IInputValueFormatter _uploadFormatter; private readonly global::StrawberryShake.Serialization.IInputValueFormatter _testInputFormatter; public TestUploadQuery(global::StrawberryShake.IOperationExecutor operationExecutor, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver) { _operationExecutor = operationExecutor ?? throw new global::System.ArgumentNullException(nameof(operationExecutor)); + _stringFormatter = serializerResolver.GetInputValueFormatter("String"); _uploadFormatter = serializerResolver.GetInputValueFormatter("Upload"); _testInputFormatter = serializerResolver.GetInputValueFormatter("TestInput"); } global::System.Type global::StrawberryShake.IOperationRequestFactory.ResultType => typeof(ITestUploadResult); - public async global::System.Threading.Tasks.Task> ExecuteAsync(global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar_InMemory.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::System.Threading.CancellationToken cancellationToken = default) + public async global::System.Threading.Tasks.Task> ExecuteAsync(global::System.String? nonUpload, global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar_InMemory.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::System.Threading.CancellationToken cancellationToken = default) { - var request = CreateRequest(single, list, nested, @object, objectList, objectNested); + var request = CreateRequest(nonUpload, single, list, nested, @object, objectList, objectNested); return await _operationExecutor.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); } @@ -711,15 +713,16 @@ private void MapFilesFromArgumentObjectNested(global::System.String path, global } } - public global::System.IObservable> Watch(global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar_InMemory.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::StrawberryShake.ExecutionStrategy? strategy = null) + public global::System.IObservable> Watch(global::System.String? nonUpload, global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar_InMemory.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::StrawberryShake.ExecutionStrategy? strategy = null) { - var request = CreateRequest(single, list, nested, @object, objectList, objectNested); + var request = CreateRequest(nonUpload, single, list, nested, @object, objectList, objectNested); return _operationExecutor.Watch(request, strategy); } - private global::StrawberryShake.OperationRequest CreateRequest(global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar_InMemory.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested) + private global::StrawberryShake.OperationRequest CreateRequest(global::System.String? nonUpload, global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar_InMemory.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested) { var variables = new global::System.Collections.Generic.Dictionary(); + variables.Add("nonUpload", FormatNonUpload(nonUpload)); variables.Add("single", FormatSingle(single)); variables.Add("list", FormatList(list)); variables.Add("nested", FormatNested(nested)); @@ -741,6 +744,18 @@ private void MapFilesFromArgumentObjectNested(global::System.String path, global return new global::StrawberryShake.OperationRequest(id: TestUploadQueryDocument.Instance.Hash.Value, name: "TestUpload", document: TestUploadQueryDocument.Instance, strategy: global::StrawberryShake.RequestStrategy.Default, files: files, variables: variables); } + private global::System.Object? FormatNonUpload(global::System.String? value) + { + if (value is null) + { + return value; + } + else + { + return _stringFormatter.Format(value); + } + } + private global::System.Object? FormatSingle(global::StrawberryShake.Upload? value) { if (value is null) @@ -901,16 +916,16 @@ private void MapFilesFromArgumentObjectNested(global::System.String path, global /// /// Represents the operation service of the TestUpload GraphQL operation /// - /// query TestUpload($single: Upload, $list: [Upload], $nested: [[Upload]], $object: TestInput, $objectList: [TestInput], $objectNested: [[TestInput]]) { - /// upload(single: $single, list: $list, nested: $nested, object: $object, objectList: $objectList, objectNested: $objectNested) + /// query TestUpload($nonUpload: String, $single: Upload, $list: [Upload], $nested: [[Upload]], $object: TestInput, $objectList: [TestInput], $objectNested: [[TestInput]]) { + /// upload(nonUpload: $nonUpload, single: $single, list: $list, nested: $nested, object: $object, objectList: $objectList, objectNested: $objectNested) /// } /// /// [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] public partial interface ITestUploadQuery : global::StrawberryShake.IOperationRequestFactory { - global::System.Threading.Tasks.Task> ExecuteAsync(global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar_InMemory.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::System.Threading.CancellationToken cancellationToken = default); - global::System.IObservable> Watch(global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar_InMemory.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::StrawberryShake.ExecutionStrategy? strategy = null); + global::System.Threading.Tasks.Task> ExecuteAsync(global::System.String? nonUpload, global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar_InMemory.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::System.Threading.CancellationToken cancellationToken = default); + global::System.IObservable> Watch(global::System.String? nonUpload, global::StrawberryShake.Upload? single, global::System.Collections.Generic.IReadOnlyList? list, global::System.Collections.Generic.IReadOnlyList?>? nested, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar_InMemory.TestInput? @object, global::System.Collections.Generic.IReadOnlyList? objectList, global::System.Collections.Generic.IReadOnlyList?>? objectNested, global::StrawberryShake.ExecutionStrategy? strategy = null); } // StrawberryShake.CodeGeneration.CSharp.Generators.ClientGenerator @@ -1025,15 +1040,15 @@ public partial class TestUploadBuilder : global::StrawberryShake.OperationResult { private readonly global::StrawberryShake.IEntityStore _entityStore; private readonly global::StrawberryShake.IEntityIdSerializer _idSerializer; - private readonly global::StrawberryShake.Serialization.ILeafValueParser _uploadParser; private readonly global::StrawberryShake.Serialization.ILeafValueParser _stringParser; + private readonly global::StrawberryShake.Serialization.ILeafValueParser _uploadParser; public TestUploadBuilder(global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer idSerializer, global::StrawberryShake.IOperationResultDataFactory resultDataFactory, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver) { _entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore)); _idSerializer = idSerializer ?? throw new global::System.ArgumentNullException(nameof(idSerializer)); ResultDataFactory = resultDataFactory ?? throw new global::System.ArgumentNullException(nameof(resultDataFactory)); - _uploadParser = serializerResolver.GetLeafValueParser("Upload") ?? throw new global::System.ArgumentException("No serializer for type `Upload` found."); _stringParser = serializerResolver.GetLeafValueParser("String") ?? throw new global::System.ArgumentException("No serializer for type `String` found."); + _uploadParser = serializerResolver.GetLeafValueParser("Upload") ?? throw new global::System.ArgumentException("No serializer for type `Upload` found."); } protected override global::StrawberryShake.IOperationResultDataFactory ResultDataFactory { get; } diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalar_InMemoryTest.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalar_InMemoryTest.cs index b29a3d2d515..d0c1f81b363 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalar_InMemoryTest.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalar_InMemoryTest.cs @@ -19,6 +19,7 @@ public async Task Execute_UploadScalar_Argument() // act var result = await client.TestUpload.ExecuteAsync( + "foo", new Upload(data, "test-file"), null, null, @@ -40,6 +41,7 @@ public async Task Execute_UploadScalarList_Argument() // act var result = await client.TestUpload.ExecuteAsync( + "foo", null, new Upload?[] { new Upload(dataA, "A"), new Upload(dataB, "B") }, null, @@ -61,6 +63,7 @@ public async Task Execute_UploadScalarNested_Argument() // act var result = await client.TestUpload.ExecuteAsync( + "foo", null, null, new[] { new Upload?[] { new Upload(dataA, "A"), new Upload(dataB, "B") } }, @@ -81,6 +84,7 @@ public async Task Execute_Input_Argument() // act var result = await client.TestUpload.ExecuteAsync( + "foo", null, null, null, @@ -107,6 +111,7 @@ public async Task Execute_InputList_Argument() using var dataB = CreateStream("b"); // act var result = await client.TestUpload.ExecuteAsync( + "foo", null, null, null, @@ -144,6 +149,7 @@ public async Task Execute_InputNested_Argument() // act var result = await client.TestUpload.ExecuteAsync( + "foo", null, null, null, diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadSchemaHelpers.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadSchemaHelpers.cs index cd200c4afa0..4843484859c 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadSchemaHelpers.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadSchemaHelpers.cs @@ -33,6 +33,7 @@ public static string ReadContents(this IFile file) public class UploadQueries { public string Upload( + string? nonUpload, IFile? single, IFile?[]? list, IFile?[]?[]? nested, diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/InputGeneratorTests.Operation_With_FirstNonUpload.snap b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/InputGeneratorTests.Operation_With_FirstNonUpload.snap new file mode 100644 index 00000000000..7fd03562785 --- /dev/null +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/InputGeneratorTests.Operation_With_FirstNonUpload.snap @@ -0,0 +1,458 @@ +// ReSharper disable BuiltInTypeReferenceStyle +// ReSharper disable RedundantNameQualifier +// ReSharper disable ArrangeObjectCreationWhenTypeEvident +// ReSharper disable UnusedType.Global +// ReSharper disable PartialTypeWithSinglePart +// ReSharper disable UnusedMethodReturnValue.Local +// ReSharper disable ConvertToAutoProperty +// ReSharper disable UnusedMember.Global +// ReSharper disable SuggestVarOrType_SimpleTypes +// ReSharper disable InconsistentNaming + +// FooClient + +// +#nullable enable + +namespace Foo.Bar +{ + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultTypeGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class TestResult : global::System.IEquatable, ITestResult + { + public TestResult(global::System.String? foo) + { + Foo = foo; + } + + public global::System.String? Foo { get; } + + public virtual global::System.Boolean Equals(TestResult? other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + if (other.GetType() != GetType()) + { + return false; + } + + return (((Foo is null && other.Foo is null) || Foo != null && Foo.Equals(other.Foo))); + } + + public override global::System.Boolean Equals(global::System.Object? obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + + if (ReferenceEquals(this, obj)) + { + return true; + } + + if (obj.GetType() != GetType()) + { + return false; + } + + return Equals((TestResult)obj); + } + + public override global::System.Int32 GetHashCode() + { + unchecked + { + int hash = 5; + if (Foo != null) + { + hash ^= 397 * Foo.GetHashCode(); + } + + return hash; + } + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface ITestResult + { + public global::System.String? Foo { get; } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.OperationDocumentGenerator + /// + /// Represents the operation service of the Test GraphQL operation + /// + /// query Test($string: String!, $upload: Upload!) { + /// foo(string: $string, upload: $upload) + /// } + /// + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class TestQueryDocument : global::StrawberryShake.IDocument + { + private TestQueryDocument() + { + } + + public static TestQueryDocument Instance { get; } = new TestQueryDocument(); + public global::StrawberryShake.OperationKind Kind => global::StrawberryShake.OperationKind.Query; + public global::System.ReadOnlySpan Body => new global::System.Byte[]{0x71, 0x75, 0x65, 0x72, 0x79, 0x20, 0x54, 0x65, 0x73, 0x74, 0x28, 0x24, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x21, 0x2c, 0x20, 0x24, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x3a, 0x20, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x21, 0x29, 0x20, 0x7b, 0x20, 0x66, 0x6f, 0x6f, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x24, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2c, 0x20, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x3a, 0x20, 0x24, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x29, 0x20, 0x7d}; + public global::StrawberryShake.DocumentHash Hash { get; } = new global::StrawberryShake.DocumentHash("sha1Hash", "35fd86e6fe5db1cabaf4a986a0976560add8afcd"); + public override global::System.String ToString() + { +#if NETCOREAPP3_1_OR_GREATER + return global::System.Text.Encoding.UTF8.GetString(Body); +#else + return global::System.Text.Encoding.UTF8.GetString(Body.ToArray()); +#endif + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.OperationServiceGenerator + /// + /// Represents the operation service of the Test GraphQL operation + /// + /// query Test($string: String!, $upload: Upload!) { + /// foo(string: $string, upload: $upload) + /// } + /// + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class TestQuery : global::Foo.Bar.ITestQuery + { + private readonly global::StrawberryShake.IOperationExecutor _operationExecutor; + private readonly global::StrawberryShake.Serialization.IInputValueFormatter _stringFormatter; + private readonly global::StrawberryShake.Serialization.IInputValueFormatter _uploadFormatter; + public TestQuery(global::StrawberryShake.IOperationExecutor operationExecutor, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver) + { + _operationExecutor = operationExecutor ?? throw new global::System.ArgumentNullException(nameof(operationExecutor)); + _stringFormatter = serializerResolver.GetInputValueFormatter("String"); + _uploadFormatter = serializerResolver.GetInputValueFormatter("Upload"); + } + + global::System.Type global::StrawberryShake.IOperationRequestFactory.ResultType => typeof(ITestResult); + public async global::System.Threading.Tasks.Task> ExecuteAsync(global::System.String @string, global::StrawberryShake.Upload upload, global::System.Threading.CancellationToken cancellationToken = default) + { + var request = CreateRequest(@string, upload); + return await _operationExecutor.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + } + + private void MapFilesFromArgumentUpload(global::System.String path, global::StrawberryShake.Upload value, global::System.Collections.Generic.Dictionary files) + { + files.Add(path, value is global::StrawberryShake.Upload u ? u : null); + } + + public global::System.IObservable> Watch(global::System.String @string, global::StrawberryShake.Upload upload, global::StrawberryShake.ExecutionStrategy? strategy = null) + { + var request = CreateRequest(@string, upload); + return _operationExecutor.Watch(request, strategy); + } + + private global::StrawberryShake.OperationRequest CreateRequest(global::System.String @string, global::StrawberryShake.Upload upload) + { + var variables = new global::System.Collections.Generic.Dictionary(); + variables.Add("string", FormatString(@string)); + variables.Add("upload", FormatUpload(upload)); + var files = new global::System.Collections.Generic.Dictionary(); + MapFilesFromArgumentUpload("variables.upload", upload, files); + return CreateRequest(variables, files); + } + + private global::StrawberryShake.OperationRequest CreateRequest(global::System.Collections.Generic.IReadOnlyDictionary? variables, global::System.Collections.Generic.Dictionary files) + { + return new global::StrawberryShake.OperationRequest(id: TestQueryDocument.Instance.Hash.Value, name: "Test", document: TestQueryDocument.Instance, strategy: global::StrawberryShake.RequestStrategy.Default, files: files, variables: variables); + } + + private global::System.Object? FormatString(global::System.String value) + { + if (value is null) + { + throw new global::System.ArgumentNullException(nameof(value)); + } + + return _stringFormatter.Format(value); + } + + private global::System.Object? FormatUpload(global::StrawberryShake.Upload value) + { + return _uploadFormatter.Format(value); + } + + global::StrawberryShake.OperationRequest global::StrawberryShake.IOperationRequestFactory.Create(global::System.Collections.Generic.IReadOnlyDictionary? variables) + { + return CreateRequest(variables!, new global::System.Collections.Generic.Dictionary()); + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.OperationServiceInterfaceGenerator + /// + /// Represents the operation service of the Test GraphQL operation + /// + /// query Test($string: String!, $upload: Upload!) { + /// foo(string: $string, upload: $upload) + /// } + /// + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface ITestQuery : global::StrawberryShake.IOperationRequestFactory + { + global::System.Threading.Tasks.Task> ExecuteAsync(global::System.String @string, global::StrawberryShake.Upload upload, global::System.Threading.CancellationToken cancellationToken = default); + global::System.IObservable> Watch(global::System.String @string, global::StrawberryShake.Upload upload, global::StrawberryShake.ExecutionStrategy? strategy = null); + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ClientGenerator + /// + /// Represents the FooClient GraphQL client + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class FooClient : global::Foo.Bar.IFooClient + { + private readonly global::Foo.Bar.ITestQuery _test; + public FooClient(global::Foo.Bar.ITestQuery test) + { + _test = test ?? throw new global::System.ArgumentNullException(nameof(test)); + } + + public static global::System.String ClientName => "FooClient"; + public global::Foo.Bar.ITestQuery Test => _test; + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ClientInterfaceGenerator + /// + /// Represents the FooClient GraphQL client + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IFooClient + { + global::Foo.Bar.ITestQuery Test { get; } + } +} + +namespace Foo.Bar.State +{ + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultDataFactoryGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class TestResultFactory : global::StrawberryShake.IOperationResultDataFactory + { + private readonly global::StrawberryShake.IEntityStore _entityStore; + public TestResultFactory(global::StrawberryShake.IEntityStore entityStore) + { + _entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore)); + } + + global::System.Type global::StrawberryShake.IOperationResultDataFactory.ResultType => typeof(global::Foo.Bar.ITestResult); + public TestResult Create(global::StrawberryShake.IOperationResultDataInfo dataInfo, global::StrawberryShake.IEntityStoreSnapshot? snapshot = null) + { + if (snapshot is null) + { + snapshot = _entityStore.CurrentSnapshot; + } + + if (dataInfo is TestResultInfo info) + { + return new TestResult(info.Foo); + } + + throw new global::System.ArgumentException("TestResultInfo expected."); + } + + global::System.Object global::StrawberryShake.IOperationResultDataFactory.Create(global::StrawberryShake.IOperationResultDataInfo dataInfo, global::StrawberryShake.IEntityStoreSnapshot? snapshot) + { + return Create(dataInfo, snapshot); + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInfoGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class TestResultInfo : global::StrawberryShake.IOperationResultDataInfo + { + private readonly global::System.Collections.Generic.IReadOnlyCollection _entityIds; + private readonly global::System.UInt64 _version; + public TestResultInfo(global::System.String? foo, global::System.Collections.Generic.IReadOnlyCollection entityIds, global::System.UInt64 version) + { + Foo = foo; + _entityIds = entityIds ?? throw new global::System.ArgumentNullException(nameof(entityIds)); + _version = version; + } + + public global::System.String? Foo { get; } + + public global::System.Collections.Generic.IReadOnlyCollection EntityIds => _entityIds; + public global::System.UInt64 Version => _version; + public global::StrawberryShake.IOperationResultDataInfo WithVersion(global::System.UInt64 version) + { + return new TestResultInfo(Foo, _entityIds, version); + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.JsonResultBuilderGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class TestBuilder : global::StrawberryShake.OperationResultBuilder + { + private readonly global::StrawberryShake.IEntityStore _entityStore; + private readonly global::StrawberryShake.IEntityIdSerializer _idSerializer; + private readonly global::StrawberryShake.Serialization.ILeafValueParser _stringParser; + private readonly global::StrawberryShake.Serialization.ILeafValueParser _uploadParser; + public TestBuilder(global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer idSerializer, global::StrawberryShake.IOperationResultDataFactory resultDataFactory, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver) + { + _entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore)); + _idSerializer = idSerializer ?? throw new global::System.ArgumentNullException(nameof(idSerializer)); + ResultDataFactory = resultDataFactory ?? throw new global::System.ArgumentNullException(nameof(resultDataFactory)); + _stringParser = serializerResolver.GetLeafValueParser("String") ?? throw new global::System.ArgumentException("No serializer for type `String` found."); + _uploadParser = serializerResolver.GetLeafValueParser("Upload") ?? throw new global::System.ArgumentException("No serializer for type `Upload` found."); + } + + protected override global::StrawberryShake.IOperationResultDataFactory ResultDataFactory { get; } + + protected override global::StrawberryShake.IOperationResultDataInfo BuildData(global::System.Text.Json.JsonElement obj) + { + var entityIds = new global::System.Collections.Generic.HashSet(); + global::StrawberryShake.IEntityStoreSnapshot snapshot = default !; + _entityStore.Update(session => + { + snapshot = session.CurrentSnapshot; + }); + return new TestResultInfo(Deserialize_String(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "foo")), entityIds, snapshot.Version); + } + + private global::System.String? Deserialize_String(global::System.Text.Json.JsonElement? obj) + { + if (!obj.HasValue) + { + return null; + } + + return _stringParser.Parse(obj.Value.GetString()!); + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.EntityIdFactoryGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class FooClientEntityIdFactory : global::StrawberryShake.IEntityIdSerializer + { + private static readonly global::System.Text.Json.JsonWriterOptions _options = new global::System.Text.Json.JsonWriterOptions() + {Indented = false}; + public global::StrawberryShake.EntityId Parse(global::System.Text.Json.JsonElement obj) + { + global::System.String __typename = obj.GetProperty("__typename").GetString()!; + return __typename switch + { + _ => throw new global::System.NotSupportedException()}; + } + + public global::System.String Format(global::StrawberryShake.EntityId entityId) + { + return entityId.Name switch + { + _ => throw new global::System.NotSupportedException()}; + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.StoreAccessorGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class FooClientStoreAccessor : global::StrawberryShake.StoreAccessor + { + public FooClientStoreAccessor(global::StrawberryShake.IOperationStore operationStore, global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer entityIdSerializer, global::System.Collections.Generic.IEnumerable requestFactories, global::System.Collections.Generic.IEnumerable resultDataFactories) : base(operationStore, entityStore, entityIdSerializer, requestFactories, resultDataFactories) + { + } + } +} + +namespace Microsoft.Extensions.DependencyInjection +{ + // StrawberryShake.CodeGeneration.CSharp.Generators.DependencyInjectionGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public static partial class FooClientServiceCollectionExtensions + { + public static global::StrawberryShake.IClientBuilder AddFooClient(this global::Microsoft.Extensions.DependencyInjection.IServiceCollection services, global::StrawberryShake.ExecutionStrategy strategy = global::StrawberryShake.ExecutionStrategy.NetworkOnly) + { + var serviceCollection = new global::Microsoft.Extensions.DependencyInjection.ServiceCollection(); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => + { + ConfigureClientDefault(sp, serviceCollection, strategy); + return new ClientServiceProvider(global::Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(serviceCollection)); + }); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => new global::Foo.Bar.State.FooClientStoreAccessor(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)), global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)), global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)), global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)), global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)))); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp))); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp))); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp))); + return new global::StrawberryShake.ClientBuilder("FooClient", services, serviceCollection); + } + + private static global::Microsoft.Extensions.DependencyInjection.IServiceCollection ConfigureClientDefault(global::System.IServiceProvider parentServices, global::Microsoft.Extensions.DependencyInjection.ServiceCollection services, global::StrawberryShake.ExecutionStrategy strategy = global::StrawberryShake.ExecutionStrategy.NetworkOnly) + { + global::Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddSingleton(services, sp => new global::StrawberryShake.OperationStore(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp))); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => + { + var clientFactory = global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(parentServices); + return new global::StrawberryShake.Transport.Http.HttpConnection(() => clientFactory.CreateClient("FooClient")); + }); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => new global::StrawberryShake.Serialization.SerializerResolver(global::System.Linq.Enumerable.Concat(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(parentServices), global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(sp)))); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton, global::Foo.Bar.State.TestResultFactory>(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(sp)); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton, global::Foo.Bar.State.TestBuilder>(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton>(services, sp => new global::StrawberryShake.OperationExecutor(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp), () => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(sp), () => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(sp), global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp), strategy)); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton, global::StrawberryShake.Json.JsonResultPatcher>(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)); + return services; + } + + private sealed class ClientServiceProvider : System.IServiceProvider, System.IDisposable + { + private readonly System.IServiceProvider _provider; + public ClientServiceProvider(System.IServiceProvider provider) + { + _provider = provider; + } + + public object? GetService(System.Type serviceType) + { + return _provider.GetService(serviceType); + } + + public void Dispose() + { + if (_provider is System.IDisposable d) + { + d.Dispose(); + } + } + } + } +} + + diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/InputGeneratorTests.Operation_With_LastNonUpload.snap b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/InputGeneratorTests.Operation_With_LastNonUpload.snap new file mode 100644 index 00000000000..476ec23e407 --- /dev/null +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/InputGeneratorTests.Operation_With_LastNonUpload.snap @@ -0,0 +1,458 @@ +// ReSharper disable BuiltInTypeReferenceStyle +// ReSharper disable RedundantNameQualifier +// ReSharper disable ArrangeObjectCreationWhenTypeEvident +// ReSharper disable UnusedType.Global +// ReSharper disable PartialTypeWithSinglePart +// ReSharper disable UnusedMethodReturnValue.Local +// ReSharper disable ConvertToAutoProperty +// ReSharper disable UnusedMember.Global +// ReSharper disable SuggestVarOrType_SimpleTypes +// ReSharper disable InconsistentNaming + +// FooClient + +// +#nullable enable + +namespace Foo.Bar +{ + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultTypeGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class TestResult : global::System.IEquatable, ITestResult + { + public TestResult(global::System.String? foo) + { + Foo = foo; + } + + public global::System.String? Foo { get; } + + public virtual global::System.Boolean Equals(TestResult? other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + if (other.GetType() != GetType()) + { + return false; + } + + return (((Foo is null && other.Foo is null) || Foo != null && Foo.Equals(other.Foo))); + } + + public override global::System.Boolean Equals(global::System.Object? obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + + if (ReferenceEquals(this, obj)) + { + return true; + } + + if (obj.GetType() != GetType()) + { + return false; + } + + return Equals((TestResult)obj); + } + + public override global::System.Int32 GetHashCode() + { + unchecked + { + int hash = 5; + if (Foo != null) + { + hash ^= 397 * Foo.GetHashCode(); + } + + return hash; + } + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface ITestResult + { + public global::System.String? Foo { get; } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.OperationDocumentGenerator + /// + /// Represents the operation service of the Test GraphQL operation + /// + /// query Test($upload: Upload!, $string: String!) { + /// foo(string: $string, upload: $upload) + /// } + /// + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class TestQueryDocument : global::StrawberryShake.IDocument + { + private TestQueryDocument() + { + } + + public static TestQueryDocument Instance { get; } = new TestQueryDocument(); + public global::StrawberryShake.OperationKind Kind => global::StrawberryShake.OperationKind.Query; + public global::System.ReadOnlySpan Body => new global::System.Byte[]{0x71, 0x75, 0x65, 0x72, 0x79, 0x20, 0x54, 0x65, 0x73, 0x74, 0x28, 0x24, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x3a, 0x20, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x21, 0x2c, 0x20, 0x24, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x21, 0x29, 0x20, 0x7b, 0x20, 0x66, 0x6f, 0x6f, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x24, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2c, 0x20, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x3a, 0x20, 0x24, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x29, 0x20, 0x7d}; + public global::StrawberryShake.DocumentHash Hash { get; } = new global::StrawberryShake.DocumentHash("sha1Hash", "923286e3634ae4122c172e158505589d75ff1363"); + public override global::System.String ToString() + { +#if NETCOREAPP3_1_OR_GREATER + return global::System.Text.Encoding.UTF8.GetString(Body); +#else + return global::System.Text.Encoding.UTF8.GetString(Body.ToArray()); +#endif + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.OperationServiceGenerator + /// + /// Represents the operation service of the Test GraphQL operation + /// + /// query Test($upload: Upload!, $string: String!) { + /// foo(string: $string, upload: $upload) + /// } + /// + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class TestQuery : global::Foo.Bar.ITestQuery + { + private readonly global::StrawberryShake.IOperationExecutor _operationExecutor; + private readonly global::StrawberryShake.Serialization.IInputValueFormatter _uploadFormatter; + private readonly global::StrawberryShake.Serialization.IInputValueFormatter _stringFormatter; + public TestQuery(global::StrawberryShake.IOperationExecutor operationExecutor, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver) + { + _operationExecutor = operationExecutor ?? throw new global::System.ArgumentNullException(nameof(operationExecutor)); + _uploadFormatter = serializerResolver.GetInputValueFormatter("Upload"); + _stringFormatter = serializerResolver.GetInputValueFormatter("String"); + } + + global::System.Type global::StrawberryShake.IOperationRequestFactory.ResultType => typeof(ITestResult); + public async global::System.Threading.Tasks.Task> ExecuteAsync(global::StrawberryShake.Upload upload, global::System.String @string, global::System.Threading.CancellationToken cancellationToken = default) + { + var request = CreateRequest(upload, @string); + return await _operationExecutor.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + } + + private void MapFilesFromArgumentUpload(global::System.String path, global::StrawberryShake.Upload value, global::System.Collections.Generic.Dictionary files) + { + files.Add(path, value is global::StrawberryShake.Upload u ? u : null); + } + + public global::System.IObservable> Watch(global::StrawberryShake.Upload upload, global::System.String @string, global::StrawberryShake.ExecutionStrategy? strategy = null) + { + var request = CreateRequest(upload, @string); + return _operationExecutor.Watch(request, strategy); + } + + private global::StrawberryShake.OperationRequest CreateRequest(global::StrawberryShake.Upload upload, global::System.String @string) + { + var variables = new global::System.Collections.Generic.Dictionary(); + variables.Add("upload", FormatUpload(upload)); + variables.Add("string", FormatString(@string)); + var files = new global::System.Collections.Generic.Dictionary(); + MapFilesFromArgumentUpload("variables.upload", upload, files); + return CreateRequest(variables, files); + } + + private global::StrawberryShake.OperationRequest CreateRequest(global::System.Collections.Generic.IReadOnlyDictionary? variables, global::System.Collections.Generic.Dictionary files) + { + return new global::StrawberryShake.OperationRequest(id: TestQueryDocument.Instance.Hash.Value, name: "Test", document: TestQueryDocument.Instance, strategy: global::StrawberryShake.RequestStrategy.Default, files: files, variables: variables); + } + + private global::System.Object? FormatUpload(global::StrawberryShake.Upload value) + { + return _uploadFormatter.Format(value); + } + + private global::System.Object? FormatString(global::System.String value) + { + if (value is null) + { + throw new global::System.ArgumentNullException(nameof(value)); + } + + return _stringFormatter.Format(value); + } + + global::StrawberryShake.OperationRequest global::StrawberryShake.IOperationRequestFactory.Create(global::System.Collections.Generic.IReadOnlyDictionary? variables) + { + return CreateRequest(variables!, new global::System.Collections.Generic.Dictionary()); + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.OperationServiceInterfaceGenerator + /// + /// Represents the operation service of the Test GraphQL operation + /// + /// query Test($upload: Upload!, $string: String!) { + /// foo(string: $string, upload: $upload) + /// } + /// + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface ITestQuery : global::StrawberryShake.IOperationRequestFactory + { + global::System.Threading.Tasks.Task> ExecuteAsync(global::StrawberryShake.Upload upload, global::System.String @string, global::System.Threading.CancellationToken cancellationToken = default); + global::System.IObservable> Watch(global::StrawberryShake.Upload upload, global::System.String @string, global::StrawberryShake.ExecutionStrategy? strategy = null); + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ClientGenerator + /// + /// Represents the FooClient GraphQL client + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class FooClient : global::Foo.Bar.IFooClient + { + private readonly global::Foo.Bar.ITestQuery _test; + public FooClient(global::Foo.Bar.ITestQuery test) + { + _test = test ?? throw new global::System.ArgumentNullException(nameof(test)); + } + + public static global::System.String ClientName => "FooClient"; + public global::Foo.Bar.ITestQuery Test => _test; + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ClientInterfaceGenerator + /// + /// Represents the FooClient GraphQL client + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IFooClient + { + global::Foo.Bar.ITestQuery Test { get; } + } +} + +namespace Foo.Bar.State +{ + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultDataFactoryGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class TestResultFactory : global::StrawberryShake.IOperationResultDataFactory + { + private readonly global::StrawberryShake.IEntityStore _entityStore; + public TestResultFactory(global::StrawberryShake.IEntityStore entityStore) + { + _entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore)); + } + + global::System.Type global::StrawberryShake.IOperationResultDataFactory.ResultType => typeof(global::Foo.Bar.ITestResult); + public TestResult Create(global::StrawberryShake.IOperationResultDataInfo dataInfo, global::StrawberryShake.IEntityStoreSnapshot? snapshot = null) + { + if (snapshot is null) + { + snapshot = _entityStore.CurrentSnapshot; + } + + if (dataInfo is TestResultInfo info) + { + return new TestResult(info.Foo); + } + + throw new global::System.ArgumentException("TestResultInfo expected."); + } + + global::System.Object global::StrawberryShake.IOperationResultDataFactory.Create(global::StrawberryShake.IOperationResultDataInfo dataInfo, global::StrawberryShake.IEntityStoreSnapshot? snapshot) + { + return Create(dataInfo, snapshot); + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInfoGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class TestResultInfo : global::StrawberryShake.IOperationResultDataInfo + { + private readonly global::System.Collections.Generic.IReadOnlyCollection _entityIds; + private readonly global::System.UInt64 _version; + public TestResultInfo(global::System.String? foo, global::System.Collections.Generic.IReadOnlyCollection entityIds, global::System.UInt64 version) + { + Foo = foo; + _entityIds = entityIds ?? throw new global::System.ArgumentNullException(nameof(entityIds)); + _version = version; + } + + public global::System.String? Foo { get; } + + public global::System.Collections.Generic.IReadOnlyCollection EntityIds => _entityIds; + public global::System.UInt64 Version => _version; + public global::StrawberryShake.IOperationResultDataInfo WithVersion(global::System.UInt64 version) + { + return new TestResultInfo(Foo, _entityIds, version); + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.JsonResultBuilderGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class TestBuilder : global::StrawberryShake.OperationResultBuilder + { + private readonly global::StrawberryShake.IEntityStore _entityStore; + private readonly global::StrawberryShake.IEntityIdSerializer _idSerializer; + private readonly global::StrawberryShake.Serialization.ILeafValueParser _uploadParser; + private readonly global::StrawberryShake.Serialization.ILeafValueParser _stringParser; + public TestBuilder(global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer idSerializer, global::StrawberryShake.IOperationResultDataFactory resultDataFactory, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver) + { + _entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore)); + _idSerializer = idSerializer ?? throw new global::System.ArgumentNullException(nameof(idSerializer)); + ResultDataFactory = resultDataFactory ?? throw new global::System.ArgumentNullException(nameof(resultDataFactory)); + _uploadParser = serializerResolver.GetLeafValueParser("Upload") ?? throw new global::System.ArgumentException("No serializer for type `Upload` found."); + _stringParser = serializerResolver.GetLeafValueParser("String") ?? throw new global::System.ArgumentException("No serializer for type `String` found."); + } + + protected override global::StrawberryShake.IOperationResultDataFactory ResultDataFactory { get; } + + protected override global::StrawberryShake.IOperationResultDataInfo BuildData(global::System.Text.Json.JsonElement obj) + { + var entityIds = new global::System.Collections.Generic.HashSet(); + global::StrawberryShake.IEntityStoreSnapshot snapshot = default !; + _entityStore.Update(session => + { + snapshot = session.CurrentSnapshot; + }); + return new TestResultInfo(Deserialize_String(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "foo")), entityIds, snapshot.Version); + } + + private global::System.String? Deserialize_String(global::System.Text.Json.JsonElement? obj) + { + if (!obj.HasValue) + { + return null; + } + + return _stringParser.Parse(obj.Value.GetString()!); + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.EntityIdFactoryGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class FooClientEntityIdFactory : global::StrawberryShake.IEntityIdSerializer + { + private static readonly global::System.Text.Json.JsonWriterOptions _options = new global::System.Text.Json.JsonWriterOptions() + {Indented = false}; + public global::StrawberryShake.EntityId Parse(global::System.Text.Json.JsonElement obj) + { + global::System.String __typename = obj.GetProperty("__typename").GetString()!; + return __typename switch + { + _ => throw new global::System.NotSupportedException()}; + } + + public global::System.String Format(global::StrawberryShake.EntityId entityId) + { + return entityId.Name switch + { + _ => throw new global::System.NotSupportedException()}; + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.StoreAccessorGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class FooClientStoreAccessor : global::StrawberryShake.StoreAccessor + { + public FooClientStoreAccessor(global::StrawberryShake.IOperationStore operationStore, global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer entityIdSerializer, global::System.Collections.Generic.IEnumerable requestFactories, global::System.Collections.Generic.IEnumerable resultDataFactories) : base(operationStore, entityStore, entityIdSerializer, requestFactories, resultDataFactories) + { + } + } +} + +namespace Microsoft.Extensions.DependencyInjection +{ + // StrawberryShake.CodeGeneration.CSharp.Generators.DependencyInjectionGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public static partial class FooClientServiceCollectionExtensions + { + public static global::StrawberryShake.IClientBuilder AddFooClient(this global::Microsoft.Extensions.DependencyInjection.IServiceCollection services, global::StrawberryShake.ExecutionStrategy strategy = global::StrawberryShake.ExecutionStrategy.NetworkOnly) + { + var serviceCollection = new global::Microsoft.Extensions.DependencyInjection.ServiceCollection(); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => + { + ConfigureClientDefault(sp, serviceCollection, strategy); + return new ClientServiceProvider(global::Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(serviceCollection)); + }); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => new global::Foo.Bar.State.FooClientStoreAccessor(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)), global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)), global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)), global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)), global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)))); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp))); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp))); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp))); + return new global::StrawberryShake.ClientBuilder("FooClient", services, serviceCollection); + } + + private static global::Microsoft.Extensions.DependencyInjection.IServiceCollection ConfigureClientDefault(global::System.IServiceProvider parentServices, global::Microsoft.Extensions.DependencyInjection.ServiceCollection services, global::StrawberryShake.ExecutionStrategy strategy = global::StrawberryShake.ExecutionStrategy.NetworkOnly) + { + global::Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddSingleton(services, sp => new global::StrawberryShake.OperationStore(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp))); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => + { + var clientFactory = global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(parentServices); + return new global::StrawberryShake.Transport.Http.HttpConnection(() => clientFactory.CreateClient("FooClient")); + }); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => new global::StrawberryShake.Serialization.SerializerResolver(global::System.Linq.Enumerable.Concat(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(parentServices), global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(sp)))); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton, global::Foo.Bar.State.TestResultFactory>(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(sp)); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton, global::Foo.Bar.State.TestBuilder>(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton>(services, sp => new global::StrawberryShake.OperationExecutor(global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp), () => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(sp), () => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService>(sp), global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp), strategy)); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton, global::StrawberryShake.Json.JsonResultPatcher>(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(services, sp => global::Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(sp)); + return services; + } + + private sealed class ClientServiceProvider : System.IServiceProvider, System.IDisposable + { + private readonly System.IServiceProvider _provider; + public ClientServiceProvider(System.IServiceProvider provider) + { + _provider = provider; + } + + public object? GetService(System.Type serviceType) + { + return _provider.GetService(serviceType); + } + + public void Dispose() + { + if (_provider is System.IDisposable d) + { + d.Dispose(); + } + } + } + } +} + +