From a329840714b506f81ec538b1f0749666b795c907 Mon Sep 17 00:00:00 2001 From: Tim Ward Date: Wed, 22 Jan 2025 02:18:47 -0800 Subject: [PATCH] Support @include/@skip for non-nullable fields (#7918) --- .../DirectiveCollectionExtensions.cs | 4 +- .../TypeDescriptors/PropertyKind.cs | 5 + .../Mappers/TypeDescriptorMapper.cs | 26 +- ...gmentIncludeAndSkipDirectiveTest.Client.cs | 2030 +++++++++++++++++ ...WithFragmentIncludeAndSkipDirectiveTest.cs | 46 + .../Integration/TestGeneration.cs | 31 + 6 files changed, 2137 insertions(+), 5 deletions(-) create mode 100644 src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveTest.Client.cs create mode 100644 src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveTest.cs diff --git a/src/HotChocolate/Core/src/Types/Types/Extensions/DirectiveCollectionExtensions.cs b/src/HotChocolate/Core/src/Types/Types/Extensions/DirectiveCollectionExtensions.cs index 9f01171896c..d9a98989e13 100644 --- a/src/HotChocolate/Core/src/Types/Types/Extensions/DirectiveCollectionExtensions.cs +++ b/src/HotChocolate/Core/src/Types/Types/Extensions/DirectiveCollectionExtensions.cs @@ -105,11 +105,11 @@ private static IValueNode GetIfArgumentValue(DirectiveNode directive) throw ThrowHelper.MissingIfArgument(directive); } - private static DirectiveNode? GetSkipDirectiveNode( + internal static DirectiveNode? GetSkipDirectiveNode( this IReadOnlyList directives) => GetDirectiveNode(directives, WellKnownDirectives.Skip); - private static DirectiveNode? GetIncludeDirectiveNode( + internal static DirectiveNode? GetIncludeDirectiveNode( this IReadOnlyList directives) => GetDirectiveNode(directives, WellKnownDirectives.Include); diff --git a/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Descriptors/TypeDescriptors/PropertyKind.cs b/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Descriptors/TypeDescriptors/PropertyKind.cs index ac2b9be1c8f..76a9dc3a599 100644 --- a/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Descriptors/TypeDescriptors/PropertyKind.cs +++ b/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Descriptors/TypeDescriptors/PropertyKind.cs @@ -19,4 +19,9 @@ public enum PropertyKind /// A non-null field that is deferred. /// DeferredField, + + /// + /// A non-null field that is included or skipped conditionally. + /// + SkipOrIncludeField } diff --git a/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/TypeDescriptorMapper.cs b/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/TypeDescriptorMapper.cs index 7216096f6ac..f475491bb2d 100644 --- a/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/TypeDescriptorMapper.cs +++ b/src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/TypeDescriptorMapper.cs @@ -375,6 +375,12 @@ private static void CollectClassesThatImplementInterface( } } + private static bool IncludeOrSkipDirective(OutputFieldModel field) + { + return field.SyntaxNode.Directives.GetIncludeDirectiveNode() is not null || + field.SyntaxNode.Directives.GetSkipDirectiveNode() is not null; + } + private static void AddProperties( ClientModel model, Dictionary typeDescriptors, @@ -388,6 +394,7 @@ private static void AddProperties( { INamedTypeDescriptor? fieldType; var namedType = field.Type.NamedType(); + var includeOrSkipDirective = IncludeOrSkipDirective(field); if (namedType.IsScalarType() || namedType.IsEnumType()) { @@ -402,14 +409,19 @@ private static void AddProperties( typeDescriptors); } + var propertyKind = includeOrSkipDirective + ? PropertyKind.SkipOrIncludeField + : PropertyKind.Field; properties.Add( new PropertyDescriptor( field.Name, field.ResponseName, BuildFieldType( field.Type, - fieldType), - field.Description)); + fieldType, + propertyKind), + field.Description, + propertyKind)); } typeDescriptorModel.Descriptor.CompleteProperties(properties); @@ -478,10 +490,18 @@ private static INamedTypeDescriptor GetFieldTypeDescriptor( private static ITypeDescriptor BuildFieldType( this IType original, - INamedTypeDescriptor namedTypeDescriptor) + INamedTypeDescriptor namedTypeDescriptor, + PropertyKind kind = PropertyKind.Field) { if (original is NonNullType nnt) { + if (kind == PropertyKind.SkipOrIncludeField) + { + return BuildFieldType( + nnt.Type, + namedTypeDescriptor); + } + return new NonNullTypeDescriptor( BuildFieldType( nnt.Type, diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveTest.Client.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveTest.Client.cs new file mode 100644 index 00000000000..f6b9fae6263 --- /dev/null +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveTest.Client.cs @@ -0,0 +1,2030 @@ +// 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 + +// StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient + +// +#nullable enable annotations +#nullable disable warnings + +namespace Microsoft.Extensions.DependencyInjection +{ + // StrawberryShake.CodeGeneration.CSharp.Generators.DependencyInjectionGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public static partial class StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClientServiceCollectionExtensions + { + public static global::StrawberryShake.IClientBuilder AddStarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient(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::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClientStoreAccessor(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("StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient", 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("StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient")); + }); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton, global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.GetHeroWithFragmentIncludeAndSkipDirective_Hero_DroidFromDroidEntityMapper>(services); + global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton, global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.GetHeroWithFragmentIncludeAndSkipDirective_Hero_HumanFromHumanEntityMapper>(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::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.GetHeroWithFragmentIncludeAndSkipDirectiveResultFactory>(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::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.GetHeroWithFragmentIncludeAndSkipDirectiveBuilder>(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(); + } + } + } + } +} + +namespace StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective +{ + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultTypeGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class GetHeroWithFragmentIncludeAndSkipDirectiveResult : global::System.IEquatable, IGetHeroWithFragmentIncludeAndSkipDirectiveResult + { + public GetHeroWithFragmentIncludeAndSkipDirectiveResult(global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero? hero) + { + Hero = hero; + } + + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero? Hero { get; } + + public virtual global::System.Boolean Equals(GetHeroWithFragmentIncludeAndSkipDirectiveResult? other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + if (other.GetType() != GetType()) + { + return false; + } + + return (((Hero is null && other.Hero is null) || Hero != null && Hero.Equals(other.Hero))); + } + + 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((GetHeroWithFragmentIncludeAndSkipDirectiveResult)obj); + } + + public override global::System.Int32 GetHashCode() + { + unchecked + { + int hash = 5; + if (Hero != null) + { + hash ^= 397 * Hero.GetHashCode(); + } + + return hash; + } + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultTypeGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class GetHeroWithFragmentIncludeAndSkipDirective_Hero_Droid : global::System.IEquatable, IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Droid + { + public GetHeroWithFragmentIncludeAndSkipDirective_Hero_Droid(global::System.String id, global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends? friends) + { + Id = id; + Friends = friends; + } + + public global::System.String Id { get; } + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends? Friends { get; } + + public virtual global::System.Boolean Equals(GetHeroWithFragmentIncludeAndSkipDirective_Hero_Droid? other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + if (other.GetType() != GetType()) + { + return false; + } + + return (Id.Equals(other.Id)) && ((Friends is null && other.Friends is null) || Friends != null && Friends.Equals(other.Friends)); + } + + 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((GetHeroWithFragmentIncludeAndSkipDirective_Hero_Droid)obj); + } + + public override global::System.Int32 GetHashCode() + { + unchecked + { + int hash = 5; + hash ^= 397 * Id.GetHashCode(); + if (Friends != null) + { + hash ^= 397 * Friends.GetHashCode(); + } + + return hash; + } + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultTypeGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class GetHeroWithFragmentIncludeAndSkipDirective_Hero_Human : global::System.IEquatable, IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Human + { + public GetHeroWithFragmentIncludeAndSkipDirective_Hero_Human(global::System.String id, global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends? friends) + { + Id = id; + Friends = friends; + } + + public global::System.String Id { get; } + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends? Friends { get; } + + public virtual global::System.Boolean Equals(GetHeroWithFragmentIncludeAndSkipDirective_Hero_Human? other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + if (other.GetType() != GetType()) + { + return false; + } + + return (Id.Equals(other.Id)) && ((Friends is null && other.Friends is null) || Friends != null && Friends.Equals(other.Friends)); + } + + 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((GetHeroWithFragmentIncludeAndSkipDirective_Hero_Human)obj); + } + + public override global::System.Int32 GetHashCode() + { + unchecked + { + int hash = 5; + hash ^= 397 * Id.GetHashCode(); + if (Friends != null) + { + hash ^= 397 * Friends.GetHashCode(); + } + + return hash; + } + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultTypeGenerator + /// + /// A connection to a list of items. + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_FriendsConnection : global::System.IEquatable, IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_FriendsConnection + { + public GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_FriendsConnection(global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo? includedPageInfo, global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo? skippedPageInfo) + { + IncludedPageInfo = includedPageInfo; + SkippedPageInfo = skippedPageInfo; + } + + /// + /// Information to aid in pagination. + /// + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo? IncludedPageInfo { get; } + /// + /// Information to aid in pagination. + /// + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo? SkippedPageInfo { get; } + + public virtual global::System.Boolean Equals(GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_FriendsConnection? other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + if (other.GetType() != GetType()) + { + return false; + } + + return (((IncludedPageInfo is null && other.IncludedPageInfo is null) || IncludedPageInfo != null && IncludedPageInfo.Equals(other.IncludedPageInfo))) && ((SkippedPageInfo is null && other.SkippedPageInfo is null) || SkippedPageInfo != null && SkippedPageInfo.Equals(other.SkippedPageInfo)); + } + + 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((GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_FriendsConnection)obj); + } + + public override global::System.Int32 GetHashCode() + { + unchecked + { + int hash = 5; + if (IncludedPageInfo != null) + { + hash ^= 397 * IncludedPageInfo.GetHashCode(); + } + + if (SkippedPageInfo != null) + { + hash ^= 397 * SkippedPageInfo.GetHashCode(); + } + + return hash; + } + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultTypeGenerator + /// + /// Information about pagination in a connection. + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo_PageInfo : global::System.IEquatable, IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo_PageInfo + { + public GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo_PageInfo(global::System.Boolean hasNextPage) + { + HasNextPage = hasNextPage; + } + + /// + /// Indicates whether more edges exist following the set defined by the clients arguments. + /// + public global::System.Boolean HasNextPage { get; } + + public virtual global::System.Boolean Equals(GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo_PageInfo? other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + if (other.GetType() != GetType()) + { + return false; + } + + return (global::System.Object.Equals(HasNextPage, other.HasNextPage)); + } + + 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((GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo_PageInfo)obj); + } + + public override global::System.Int32 GetHashCode() + { + unchecked + { + int hash = 5; + hash ^= 397 * HasNextPage.GetHashCode(); + return hash; + } + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultTypeGenerator + /// + /// Information about pagination in a connection. + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo_PageInfo : global::System.IEquatable, IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo_PageInfo + { + public GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo_PageInfo(global::System.Boolean hasNextPage) + { + HasNextPage = hasNextPage; + } + + /// + /// Indicates whether more edges exist following the set defined by the clients arguments. + /// + public global::System.Boolean HasNextPage { get; } + + public virtual global::System.Boolean Equals(GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo_PageInfo? other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + if (other.GetType() != GetType()) + { + return false; + } + + return (global::System.Object.Equals(HasNextPage, other.HasNextPage)); + } + + 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((GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo_PageInfo)obj); + } + + public override global::System.Int32 GetHashCode() + { + unchecked + { + int hash = 5; + hash ^= 397 * HasNextPage.GetHashCode(); + return hash; + } + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IGetHeroWithFragmentIncludeAndSkipDirectiveResult + { + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero? Hero { get; } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IHeroFragment + { + public global::System.String Id { get; } + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends? Friends { get; } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IGetHeroWithFragmentIncludeAndSkipDirective_Hero : IHeroFragment + { + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Droid : IGetHeroWithFragmentIncludeAndSkipDirective_Hero + { + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Human : IGetHeroWithFragmentIncludeAndSkipDirective_Hero + { + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + /// + /// A connection to a list of items. + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IFriendsFragment + { + /// + /// Information to aid in pagination. + /// + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo? IncludedPageInfo { get; } + /// + /// Information to aid in pagination. + /// + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo? SkippedPageInfo { get; } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + /// + /// A connection to a list of items. + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends : IFriendsFragment + { + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + /// + /// A connection to a list of items. + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_FriendsConnection : IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends + { + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + /// + /// Information about pagination in a connection. + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IPageInfoFragment + { + /// + /// Indicates whether more edges exist following the set defined by the clients arguments. + /// + public global::System.Boolean HasNextPage { get; } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + /// + /// Information about pagination in a connection. + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo : IPageInfoFragment + { + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + /// + /// Information about pagination in a connection. + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo_PageInfo : IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo + { + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + /// + /// Information about pagination in a connection. + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo : IPageInfoFragment + { + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultInterfaceGenerator + /// + /// Information about pagination in a connection. + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo_PageInfo : IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo + { + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.OperationDocumentGenerator + /// + /// Represents the operation service of the GetHeroWithFragmentIncludeAndSkipDirective GraphQL operation + /// + /// query GetHeroWithFragmentIncludeAndSkipDirective($includePageInfo: Boolean = false, $skipPageInfo: Boolean = true) { + /// hero(episode: NEW_HOPE) { + /// __typename + /// ... HeroFragment + /// ... on Droid { + /// id + /// } + /// ... on Human { + /// id + /// } + /// } + /// } + /// + /// fragment HeroFragment on Character { + /// id + /// friends { + /// __typename + /// ... FriendsFragment + /// } + /// } + /// + /// fragment FriendsFragment on FriendsConnection { + /// includedPageInfo: pageInfo @include(if: $includePageInfo) { + /// __typename + /// ... PageInfoFragment + /// } + /// skippedPageInfo: pageInfo @skip(if: $skipPageInfo) { + /// __typename + /// ... PageInfoFragment + /// } + /// } + /// + /// fragment PageInfoFragment on PageInfo { + /// hasNextPage + /// } + /// + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class GetHeroWithFragmentIncludeAndSkipDirectiveQueryDocument : global::StrawberryShake.IDocument + { + private GetHeroWithFragmentIncludeAndSkipDirectiveQueryDocument() + { + } + + public static GetHeroWithFragmentIncludeAndSkipDirectiveQueryDocument Instance { get; } = new GetHeroWithFragmentIncludeAndSkipDirectiveQueryDocument(); + public global::StrawberryShake.OperationKind Kind => global::StrawberryShake.OperationKind.Query; + public global::System.ReadOnlySpan Body => new global::System.Byte[] + { + 0x71, + 0x75, + 0x65, + 0x72, + 0x79, + 0x20, + 0x47, + 0x65, + 0x74, + 0x48, + 0x65, + 0x72, + 0x6f, + 0x57, + 0x69, + 0x74, + 0x68, + 0x46, + 0x72, + 0x61, + 0x67, + 0x6d, + 0x65, + 0x6e, + 0x74, + 0x49, + 0x6e, + 0x63, + 0x6c, + 0x75, + 0x64, + 0x65, + 0x41, + 0x6e, + 0x64, + 0x53, + 0x6b, + 0x69, + 0x70, + 0x44, + 0x69, + 0x72, + 0x65, + 0x63, + 0x74, + 0x69, + 0x76, + 0x65, + 0x28, + 0x24, + 0x69, + 0x6e, + 0x63, + 0x6c, + 0x75, + 0x64, + 0x65, + 0x50, + 0x61, + 0x67, + 0x65, + 0x49, + 0x6e, + 0x66, + 0x6f, + 0x3a, + 0x20, + 0x42, + 0x6f, + 0x6f, + 0x6c, + 0x65, + 0x61, + 0x6e, + 0x20, + 0x3d, + 0x20, + 0x66, + 0x61, + 0x6c, + 0x73, + 0x65, + 0x2c, + 0x20, + 0x24, + 0x73, + 0x6b, + 0x69, + 0x70, + 0x50, + 0x61, + 0x67, + 0x65, + 0x49, + 0x6e, + 0x66, + 0x6f, + 0x3a, + 0x20, + 0x42, + 0x6f, + 0x6f, + 0x6c, + 0x65, + 0x61, + 0x6e, + 0x20, + 0x3d, + 0x20, + 0x74, + 0x72, + 0x75, + 0x65, + 0x29, + 0x20, + 0x7b, + 0x20, + 0x68, + 0x65, + 0x72, + 0x6f, + 0x28, + 0x65, + 0x70, + 0x69, + 0x73, + 0x6f, + 0x64, + 0x65, + 0x3a, + 0x20, + 0x4e, + 0x45, + 0x57, + 0x5f, + 0x48, + 0x4f, + 0x50, + 0x45, + 0x29, + 0x20, + 0x7b, + 0x20, + 0x5f, + 0x5f, + 0x74, + 0x79, + 0x70, + 0x65, + 0x6e, + 0x61, + 0x6d, + 0x65, + 0x20, + 0x2e, + 0x2e, + 0x2e, + 0x20, + 0x48, + 0x65, + 0x72, + 0x6f, + 0x46, + 0x72, + 0x61, + 0x67, + 0x6d, + 0x65, + 0x6e, + 0x74, + 0x20, + 0x2e, + 0x2e, + 0x2e, + 0x20, + 0x6f, + 0x6e, + 0x20, + 0x44, + 0x72, + 0x6f, + 0x69, + 0x64, + 0x20, + 0x7b, + 0x20, + 0x69, + 0x64, + 0x20, + 0x7d, + 0x20, + 0x2e, + 0x2e, + 0x2e, + 0x20, + 0x6f, + 0x6e, + 0x20, + 0x48, + 0x75, + 0x6d, + 0x61, + 0x6e, + 0x20, + 0x7b, + 0x20, + 0x69, + 0x64, + 0x20, + 0x7d, + 0x20, + 0x7d, + 0x20, + 0x7d, + 0x20, + 0x66, + 0x72, + 0x61, + 0x67, + 0x6d, + 0x65, + 0x6e, + 0x74, + 0x20, + 0x48, + 0x65, + 0x72, + 0x6f, + 0x46, + 0x72, + 0x61, + 0x67, + 0x6d, + 0x65, + 0x6e, + 0x74, + 0x20, + 0x6f, + 0x6e, + 0x20, + 0x43, + 0x68, + 0x61, + 0x72, + 0x61, + 0x63, + 0x74, + 0x65, + 0x72, + 0x20, + 0x7b, + 0x20, + 0x69, + 0x64, + 0x20, + 0x66, + 0x72, + 0x69, + 0x65, + 0x6e, + 0x64, + 0x73, + 0x20, + 0x7b, + 0x20, + 0x5f, + 0x5f, + 0x74, + 0x79, + 0x70, + 0x65, + 0x6e, + 0x61, + 0x6d, + 0x65, + 0x20, + 0x2e, + 0x2e, + 0x2e, + 0x20, + 0x46, + 0x72, + 0x69, + 0x65, + 0x6e, + 0x64, + 0x73, + 0x46, + 0x72, + 0x61, + 0x67, + 0x6d, + 0x65, + 0x6e, + 0x74, + 0x20, + 0x7d, + 0x20, + 0x7d, + 0x20, + 0x66, + 0x72, + 0x61, + 0x67, + 0x6d, + 0x65, + 0x6e, + 0x74, + 0x20, + 0x46, + 0x72, + 0x69, + 0x65, + 0x6e, + 0x64, + 0x73, + 0x46, + 0x72, + 0x61, + 0x67, + 0x6d, + 0x65, + 0x6e, + 0x74, + 0x20, + 0x6f, + 0x6e, + 0x20, + 0x46, + 0x72, + 0x69, + 0x65, + 0x6e, + 0x64, + 0x73, + 0x43, + 0x6f, + 0x6e, + 0x6e, + 0x65, + 0x63, + 0x74, + 0x69, + 0x6f, + 0x6e, + 0x20, + 0x7b, + 0x20, + 0x69, + 0x6e, + 0x63, + 0x6c, + 0x75, + 0x64, + 0x65, + 0x64, + 0x50, + 0x61, + 0x67, + 0x65, + 0x49, + 0x6e, + 0x66, + 0x6f, + 0x3a, + 0x20, + 0x70, + 0x61, + 0x67, + 0x65, + 0x49, + 0x6e, + 0x66, + 0x6f, + 0x20, + 0x40, + 0x69, + 0x6e, + 0x63, + 0x6c, + 0x75, + 0x64, + 0x65, + 0x28, + 0x69, + 0x66, + 0x3a, + 0x20, + 0x24, + 0x69, + 0x6e, + 0x63, + 0x6c, + 0x75, + 0x64, + 0x65, + 0x50, + 0x61, + 0x67, + 0x65, + 0x49, + 0x6e, + 0x66, + 0x6f, + 0x29, + 0x20, + 0x7b, + 0x20, + 0x5f, + 0x5f, + 0x74, + 0x79, + 0x70, + 0x65, + 0x6e, + 0x61, + 0x6d, + 0x65, + 0x20, + 0x2e, + 0x2e, + 0x2e, + 0x20, + 0x50, + 0x61, + 0x67, + 0x65, + 0x49, + 0x6e, + 0x66, + 0x6f, + 0x46, + 0x72, + 0x61, + 0x67, + 0x6d, + 0x65, + 0x6e, + 0x74, + 0x20, + 0x7d, + 0x20, + 0x73, + 0x6b, + 0x69, + 0x70, + 0x70, + 0x65, + 0x64, + 0x50, + 0x61, + 0x67, + 0x65, + 0x49, + 0x6e, + 0x66, + 0x6f, + 0x3a, + 0x20, + 0x70, + 0x61, + 0x67, + 0x65, + 0x49, + 0x6e, + 0x66, + 0x6f, + 0x20, + 0x40, + 0x73, + 0x6b, + 0x69, + 0x70, + 0x28, + 0x69, + 0x66, + 0x3a, + 0x20, + 0x24, + 0x73, + 0x6b, + 0x69, + 0x70, + 0x50, + 0x61, + 0x67, + 0x65, + 0x49, + 0x6e, + 0x66, + 0x6f, + 0x29, + 0x20, + 0x7b, + 0x20, + 0x5f, + 0x5f, + 0x74, + 0x79, + 0x70, + 0x65, + 0x6e, + 0x61, + 0x6d, + 0x65, + 0x20, + 0x2e, + 0x2e, + 0x2e, + 0x20, + 0x50, + 0x61, + 0x67, + 0x65, + 0x49, + 0x6e, + 0x66, + 0x6f, + 0x46, + 0x72, + 0x61, + 0x67, + 0x6d, + 0x65, + 0x6e, + 0x74, + 0x20, + 0x7d, + 0x20, + 0x7d, + 0x20, + 0x66, + 0x72, + 0x61, + 0x67, + 0x6d, + 0x65, + 0x6e, + 0x74, + 0x20, + 0x50, + 0x61, + 0x67, + 0x65, + 0x49, + 0x6e, + 0x66, + 0x6f, + 0x46, + 0x72, + 0x61, + 0x67, + 0x6d, + 0x65, + 0x6e, + 0x74, + 0x20, + 0x6f, + 0x6e, + 0x20, + 0x50, + 0x61, + 0x67, + 0x65, + 0x49, + 0x6e, + 0x66, + 0x6f, + 0x20, + 0x7b, + 0x20, + 0x68, + 0x61, + 0x73, + 0x4e, + 0x65, + 0x78, + 0x74, + 0x50, + 0x61, + 0x67, + 0x65, + 0x20, + 0x7d + }; + public global::StrawberryShake.DocumentHash Hash { get; } = new global::StrawberryShake.DocumentHash("sha1Hash", "87f3c93b0135cfd1f7e0467b57ae1a6ef7d4e828"); + + 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 GetHeroWithFragmentIncludeAndSkipDirective GraphQL operation + /// + /// query GetHeroWithFragmentIncludeAndSkipDirective($includePageInfo: Boolean = false, $skipPageInfo: Boolean = true) { + /// hero(episode: NEW_HOPE) { + /// __typename + /// ... HeroFragment + /// ... on Droid { + /// id + /// } + /// ... on Human { + /// id + /// } + /// } + /// } + /// + /// fragment HeroFragment on Character { + /// id + /// friends { + /// __typename + /// ... FriendsFragment + /// } + /// } + /// + /// fragment FriendsFragment on FriendsConnection { + /// includedPageInfo: pageInfo @include(if: $includePageInfo) { + /// __typename + /// ... PageInfoFragment + /// } + /// skippedPageInfo: pageInfo @skip(if: $skipPageInfo) { + /// __typename + /// ... PageInfoFragment + /// } + /// } + /// + /// fragment PageInfoFragment on PageInfo { + /// hasNextPage + /// } + /// + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class GetHeroWithFragmentIncludeAndSkipDirectiveQuery : global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirectiveQuery + { + private readonly global::StrawberryShake.IOperationExecutor _operationExecutor; + private readonly global::StrawberryShake.Serialization.IInputValueFormatter _booleanFormatter; + public GetHeroWithFragmentIncludeAndSkipDirectiveQuery(global::StrawberryShake.IOperationExecutor operationExecutor, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver) + { + _operationExecutor = operationExecutor ?? throw new global::System.ArgumentNullException(nameof(operationExecutor)); + _booleanFormatter = serializerResolver.GetInputValueFormatter("Boolean"); + } + + global::System.Type global::StrawberryShake.IOperationRequestFactory.ResultType => typeof(IGetHeroWithFragmentIncludeAndSkipDirectiveResult); + + public async global::System.Threading.Tasks.Task> ExecuteAsync(global::System.Boolean? includePageInfo, global::System.Boolean? skipPageInfo, global::System.Threading.CancellationToken cancellationToken = default) + { + var request = CreateRequest(includePageInfo, skipPageInfo); + return await _operationExecutor.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + } + + public global::System.IObservable> Watch(global::System.Boolean? includePageInfo, global::System.Boolean? skipPageInfo, global::StrawberryShake.ExecutionStrategy? strategy = null) + { + var request = CreateRequest(includePageInfo, skipPageInfo); + return _operationExecutor.Watch(request, strategy); + } + + private global::StrawberryShake.OperationRequest CreateRequest(global::System.Boolean? includePageInfo, global::System.Boolean? skipPageInfo) + { + var variables = new global::System.Collections.Generic.Dictionary(); + variables.Add("includePageInfo", FormatIncludePageInfo(includePageInfo)); + variables.Add("skipPageInfo", FormatSkipPageInfo(skipPageInfo)); + return CreateRequest(variables); + } + + private global::StrawberryShake.OperationRequest CreateRequest(global::System.Collections.Generic.IReadOnlyDictionary? variables) + { + return new global::StrawberryShake.OperationRequest(id: GetHeroWithFragmentIncludeAndSkipDirectiveQueryDocument.Instance.Hash.Value, name: "GetHeroWithFragmentIncludeAndSkipDirective", document: GetHeroWithFragmentIncludeAndSkipDirectiveQueryDocument.Instance, strategy: global::StrawberryShake.RequestStrategy.Default, variables: variables); + } + + private global::System.Object? FormatIncludePageInfo(global::System.Boolean? value) + { + if (value is null) + { + return value; + } + else + { + return _booleanFormatter.Format(value); + } + } + + private global::System.Object? FormatSkipPageInfo(global::System.Boolean? value) + { + if (value is null) + { + return value; + } + else + { + return _booleanFormatter.Format(value); + } + } + + global::StrawberryShake.OperationRequest global::StrawberryShake.IOperationRequestFactory.Create(global::System.Collections.Generic.IReadOnlyDictionary? variables) + { + return CreateRequest(variables!); + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.OperationServiceInterfaceGenerator + /// + /// Represents the operation service of the GetHeroWithFragmentIncludeAndSkipDirective GraphQL operation + /// + /// query GetHeroWithFragmentIncludeAndSkipDirective($includePageInfo: Boolean = false, $skipPageInfo: Boolean = true) { + /// hero(episode: NEW_HOPE) { + /// __typename + /// ... HeroFragment + /// ... on Droid { + /// id + /// } + /// ... on Human { + /// id + /// } + /// } + /// } + /// + /// fragment HeroFragment on Character { + /// id + /// friends { + /// __typename + /// ... FriendsFragment + /// } + /// } + /// + /// fragment FriendsFragment on FriendsConnection { + /// includedPageInfo: pageInfo @include(if: $includePageInfo) { + /// __typename + /// ... PageInfoFragment + /// } + /// skippedPageInfo: pageInfo @skip(if: $skipPageInfo) { + /// __typename + /// ... PageInfoFragment + /// } + /// } + /// + /// fragment PageInfoFragment on PageInfo { + /// hasNextPage + /// } + /// + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IGetHeroWithFragmentIncludeAndSkipDirectiveQuery : global::StrawberryShake.IOperationRequestFactory + { + global::System.Threading.Tasks.Task> ExecuteAsync(global::System.Boolean? includePageInfo, global::System.Boolean? skipPageInfo, global::System.Threading.CancellationToken cancellationToken = default); + global::System.IObservable> Watch(global::System.Boolean? includePageInfo, global::System.Boolean? skipPageInfo, global::StrawberryShake.ExecutionStrategy? strategy = null); + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ClientGenerator + /// + /// Represents the StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient GraphQL client + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient : global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IStarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient + { + private readonly global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirectiveQuery _getHeroWithFragmentIncludeAndSkipDirective; + public StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient(global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirectiveQuery getHeroWithFragmentIncludeAndSkipDirective) + { + _getHeroWithFragmentIncludeAndSkipDirective = getHeroWithFragmentIncludeAndSkipDirective ?? throw new global::System.ArgumentNullException(nameof(getHeroWithFragmentIncludeAndSkipDirective)); + } + + public static global::System.String ClientName => "StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient"; + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirectiveQuery GetHeroWithFragmentIncludeAndSkipDirective => _getHeroWithFragmentIncludeAndSkipDirective; + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ClientInterfaceGenerator + /// + /// Represents the StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient GraphQL client + /// + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial interface IStarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient + { + global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirectiveQuery GetHeroWithFragmentIncludeAndSkipDirective { get; } + } +} + +namespace StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State +{ + // StrawberryShake.CodeGeneration.CSharp.Generators.EntityTypeGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "0.0.0.0")] + public partial class DroidEntity + { + public DroidEntity(global::System.String id = default !, global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.FriendsConnectionData? friends = default !) + { + Id = id; + Friends = friends; + } + + public global::System.String Id { get; } + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.FriendsConnectionData? Friends { get; } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.EntityTypeGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "0.0.0.0")] + public partial class HumanEntity + { + public HumanEntity(global::System.String id = default !, global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.FriendsConnectionData? friends = default !) + { + Id = id; + Friends = friends; + } + + public global::System.String Id { get; } + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.FriendsConnectionData? Friends { get; } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultDataFactoryGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class GetHeroWithFragmentIncludeAndSkipDirectiveResultFactory : global::StrawberryShake.IOperationResultDataFactory + { + private readonly global::StrawberryShake.IEntityStore _entityStore; + private readonly global::StrawberryShake.IEntityMapper _getHeroWithFragmentIncludeAndSkipDirective_Hero_DroidFromDroidEntityMapper; + private readonly global::StrawberryShake.IEntityMapper _getHeroWithFragmentIncludeAndSkipDirective_Hero_HumanFromHumanEntityMapper; + public GetHeroWithFragmentIncludeAndSkipDirectiveResultFactory(global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityMapper getHeroWithFragmentIncludeAndSkipDirective_Hero_DroidFromDroidEntityMapper, global::StrawberryShake.IEntityMapper getHeroWithFragmentIncludeAndSkipDirective_Hero_HumanFromHumanEntityMapper) + { + _entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore)); + _getHeroWithFragmentIncludeAndSkipDirective_Hero_DroidFromDroidEntityMapper = getHeroWithFragmentIncludeAndSkipDirective_Hero_DroidFromDroidEntityMapper ?? throw new global::System.ArgumentNullException(nameof(getHeroWithFragmentIncludeAndSkipDirective_Hero_DroidFromDroidEntityMapper)); + _getHeroWithFragmentIncludeAndSkipDirective_Hero_HumanFromHumanEntityMapper = getHeroWithFragmentIncludeAndSkipDirective_Hero_HumanFromHumanEntityMapper ?? throw new global::System.ArgumentNullException(nameof(getHeroWithFragmentIncludeAndSkipDirective_Hero_HumanFromHumanEntityMapper)); + } + + global::System.Type global::StrawberryShake.IOperationResultDataFactory.ResultType => typeof(global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirectiveResult); + + public GetHeroWithFragmentIncludeAndSkipDirectiveResult Create(global::StrawberryShake.IOperationResultDataInfo dataInfo, global::StrawberryShake.IEntityStoreSnapshot? snapshot = null) + { + if (snapshot is null) + { + snapshot = _entityStore.CurrentSnapshot; + } + + if (dataInfo is GetHeroWithFragmentIncludeAndSkipDirectiveResultInfo info) + { + return new GetHeroWithFragmentIncludeAndSkipDirectiveResult(MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero(info.Hero, snapshot)); + } + + throw new global::System.ArgumentException("GetHeroWithFragmentIncludeAndSkipDirectiveResultInfo expected."); + } + + private global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero? MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero(global::StrawberryShake.EntityId? entityId, global::StrawberryShake.IEntityStoreSnapshot snapshot) + { + if (entityId is null) + { + return null; + } + + if (entityId.Value.Name.Equals("Droid", global::System.StringComparison.Ordinal)) + { + return _getHeroWithFragmentIncludeAndSkipDirective_Hero_DroidFromDroidEntityMapper.Map(snapshot.GetEntity(entityId.Value) ?? throw new global::StrawberryShake.GraphQLClientException()); + } + + if (entityId.Value.Name.Equals("Human", global::System.StringComparison.Ordinal)) + { + return _getHeroWithFragmentIncludeAndSkipDirective_Hero_HumanFromHumanEntityMapper.Map(snapshot.GetEntity(entityId.Value) ?? throw new global::StrawberryShake.GraphQLClientException()); + } + + throw new global::System.NotSupportedException(); + } + + 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 GetHeroWithFragmentIncludeAndSkipDirectiveResultInfo : global::StrawberryShake.IOperationResultDataInfo + { + private readonly global::System.Collections.Generic.IReadOnlyCollection _entityIds; + private readonly global::System.UInt64 _version; + public GetHeroWithFragmentIncludeAndSkipDirectiveResultInfo(global::StrawberryShake.EntityId? hero, global::System.Collections.Generic.IReadOnlyCollection entityIds, global::System.UInt64 version) + { + Hero = hero; + _entityIds = entityIds ?? throw new global::System.ArgumentNullException(nameof(entityIds)); + _version = version; + } + + public global::StrawberryShake.EntityId? Hero { 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 GetHeroWithFragmentIncludeAndSkipDirectiveResultInfo(Hero, _entityIds, version); + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.JsonResultBuilderGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class GetHeroWithFragmentIncludeAndSkipDirectiveBuilder : global::StrawberryShake.OperationResultBuilder + { + private readonly global::StrawberryShake.IEntityStore _entityStore; + private readonly global::StrawberryShake.IEntityIdSerializer _idSerializer; + private readonly global::StrawberryShake.Serialization.ILeafValueParser _booleanParser; + private readonly global::StrawberryShake.Serialization.ILeafValueParser _iDParser; + public GetHeroWithFragmentIncludeAndSkipDirectiveBuilder(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)); + _booleanParser = serializerResolver.GetLeafValueParser("Boolean") ?? throw new global::System.ArgumentException("No serializer for type `Boolean` found."); + _iDParser = serializerResolver.GetLeafValueParser("ID") ?? throw new global::System.ArgumentException("No serializer for type `ID` 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 !; + global::StrawberryShake.EntityId? heroId = default !; + _entityStore.Update(session => + { + heroId = Update_IGetHeroWithFragmentIncludeAndSkipDirective_HeroEntity(session, global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "hero"), entityIds); + snapshot = session.CurrentSnapshot; + }); + return new GetHeroWithFragmentIncludeAndSkipDirectiveResultInfo(heroId, entityIds, snapshot.Version); + } + + private global::StrawberryShake.EntityId? Update_IGetHeroWithFragmentIncludeAndSkipDirective_HeroEntity(global::StrawberryShake.IEntityStoreUpdateSession session, global::System.Text.Json.JsonElement? obj, global::System.Collections.Generic.ISet entityIds) + { + if (!obj.HasValue) + { + return null; + } + + if (obj.Value.ValueKind == global::System.Text.Json.JsonValueKind.Null) + { + return null; + } + + global::StrawberryShake.EntityId entityId = _idSerializer.Parse(obj.Value); + entityIds.Add(entityId); + if (entityId.Name.Equals("Droid", global::System.StringComparison.Ordinal)) + { + if (session.CurrentSnapshot.TryGetEntity(entityId, out global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.DroidEntity? entity)) + { + session.SetEntity(entityId, new global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.DroidEntity(Deserialize_NonNullableString(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "id")), Deserialize_IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "friends")))); + } + else + { + session.SetEntity(entityId, new global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.DroidEntity(Deserialize_NonNullableString(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "id")), Deserialize_IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "friends")))); + } + + return entityId; + } + + if (entityId.Name.Equals("Human", global::System.StringComparison.Ordinal)) + { + if (session.CurrentSnapshot.TryGetEntity(entityId, out global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.HumanEntity? entity)) + { + session.SetEntity(entityId, new global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.HumanEntity(Deserialize_NonNullableString(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "id")), Deserialize_IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "friends")))); + } + else + { + session.SetEntity(entityId, new global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.HumanEntity(Deserialize_NonNullableString(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "id")), Deserialize_IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "friends")))); + } + + return entityId; + } + + throw new global::System.NotSupportedException(); + } + + private global::System.String Deserialize_NonNullableString(global::System.Text.Json.JsonElement? obj) + { + if (!obj.HasValue) + { + throw new global::System.ArgumentNullException(); + } + + if (obj.Value.ValueKind == global::System.Text.Json.JsonValueKind.Null) + { + throw new global::System.ArgumentNullException(); + } + + return _iDParser.Parse(obj.Value.GetString()!); + } + + private global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.FriendsConnectionData? Deserialize_IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends(global::System.Text.Json.JsonElement? obj) + { + if (!obj.HasValue) + { + return null; + } + + if (obj.Value.ValueKind == global::System.Text.Json.JsonValueKind.Null) + { + return null; + } + + var typename = obj.Value.GetProperty("__typename").GetString(); + if (typename?.Equals("FriendsConnection", global::System.StringComparison.Ordinal) ?? false) + { + return new global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.FriendsConnectionData(typename, includedPageInfo: Deserialize_IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "includedPageInfo")), skippedPageInfo: Deserialize_IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "skippedPageInfo"))); + } + + throw new global::System.NotSupportedException(); + } + + private global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.PageInfoData? Deserialize_IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo(global::System.Text.Json.JsonElement? obj) + { + if (!obj.HasValue) + { + return null; + } + + if (obj.Value.ValueKind == global::System.Text.Json.JsonValueKind.Null) + { + return null; + } + + var typename = obj.Value.GetProperty("__typename").GetString(); + if (typename?.Equals("PageInfo", global::System.StringComparison.Ordinal) ?? false) + { + return new global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.PageInfoData(typename, hasNextPage: Deserialize_NonNullableBoolean(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "hasNextPage"))); + } + + throw new global::System.NotSupportedException(); + } + + private global::System.Boolean Deserialize_NonNullableBoolean(global::System.Text.Json.JsonElement? obj) + { + if (!obj.HasValue) + { + throw new global::System.ArgumentNullException(); + } + + if (obj.Value.ValueKind == global::System.Text.Json.JsonValueKind.Null) + { + throw new global::System.ArgumentNullException(); + } + + return _booleanParser.Parse(obj.Value.GetBoolean()!); + } + + private global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.PageInfoData? Deserialize_IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo(global::System.Text.Json.JsonElement? obj) + { + if (!obj.HasValue) + { + return null; + } + + if (obj.Value.ValueKind == global::System.Text.Json.JsonValueKind.Null) + { + return null; + } + + var typename = obj.Value.GetProperty("__typename").GetString(); + if (typename?.Equals("PageInfo", global::System.StringComparison.Ordinal) ?? false) + { + return new global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.PageInfoData(typename, hasNextPage: Deserialize_NonNullableBoolean(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "hasNextPage"))); + } + + throw new global::System.NotSupportedException(); + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.DataTypeGenerator + ///A connection to a list of items. + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "0.0.0.0")] + public partial class FriendsConnectionData + { + public FriendsConnectionData(global::System.String __typename, global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.PageInfoData? includedPageInfo = default !, global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.PageInfoData? skippedPageInfo = default !) + { + this.__typename = __typename ?? throw new global::System.ArgumentNullException(nameof(__typename)); + IncludedPageInfo = includedPageInfo; + SkippedPageInfo = skippedPageInfo; + } + + public global::System.String __typename { get; } + ///Information to aid in pagination. + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.PageInfoData? IncludedPageInfo { get; } + ///Information to aid in pagination. + public global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.PageInfoData? SkippedPageInfo { get; } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.DataTypeGenerator + ///Information about pagination in a connection. + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "0.0.0.0")] + public partial class PageInfoData + { + public PageInfoData(global::System.String __typename, global::System.Boolean? hasNextPage = default !) + { + this.__typename = __typename ?? throw new global::System.ArgumentNullException(nameof(__typename)); + HasNextPage = hasNextPage; + } + + public global::System.String __typename { get; } + ///Indicates whether more edges exist following the set defined by the clients arguments. + public global::System.Boolean? HasNextPage { get; } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultFromEntityTypeMapperGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class GetHeroWithFragmentIncludeAndSkipDirective_Hero_DroidFromDroidEntityMapper : global::StrawberryShake.IEntityMapper + { + private readonly global::StrawberryShake.IEntityStore _entityStore; + public GetHeroWithFragmentIncludeAndSkipDirective_Hero_DroidFromDroidEntityMapper(global::StrawberryShake.IEntityStore entityStore) + { + _entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore)); + } + + public GetHeroWithFragmentIncludeAndSkipDirective_Hero_Droid Map(global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.DroidEntity entity, global::StrawberryShake.IEntityStoreSnapshot? snapshot = null) + { + if (snapshot is null) + { + snapshot = _entityStore.CurrentSnapshot; + } + + return new GetHeroWithFragmentIncludeAndSkipDirective_Hero_Droid(entity.Id, MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends(entity.Friends, snapshot)); + } + + private global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends? MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends(global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.FriendsConnectionData? data, global::StrawberryShake.IEntityStoreSnapshot snapshot) + { + if (data is null) + { + return null; + } + + IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends returnValue = default !; + if (data?.__typename.Equals("FriendsConnection", global::System.StringComparison.Ordinal) ?? false) + { + returnValue = new GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_FriendsConnection(MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo(data.IncludedPageInfo, snapshot), MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo(data.SkippedPageInfo, snapshot)); + } + else + { + throw new global::System.NotSupportedException(); + } + + return returnValue; + } + + private global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo? MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo(global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.PageInfoData? data, global::StrawberryShake.IEntityStoreSnapshot snapshot) + { + if (data is null) + { + return null; + } + + IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo returnValue = default !; + if (data?.__typename.Equals("PageInfo", global::System.StringComparison.Ordinal) ?? false) + { + returnValue = new GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo_PageInfo(data.HasNextPage ?? throw new global::System.ArgumentNullException()); + } + else + { + throw new global::System.NotSupportedException(); + } + + return returnValue; + } + + private global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo? MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo(global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.PageInfoData? data, global::StrawberryShake.IEntityStoreSnapshot snapshot) + { + if (data is null) + { + return null; + } + + IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo returnValue = default !; + if (data?.__typename.Equals("PageInfo", global::System.StringComparison.Ordinal) ?? false) + { + returnValue = new GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo_PageInfo(data.HasNextPage ?? throw new global::System.ArgumentNullException()); + } + else + { + throw new global::System.NotSupportedException(); + } + + return returnValue; + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.ResultFromEntityTypeMapperGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class GetHeroWithFragmentIncludeAndSkipDirective_Hero_HumanFromHumanEntityMapper : global::StrawberryShake.IEntityMapper + { + private readonly global::StrawberryShake.IEntityStore _entityStore; + public GetHeroWithFragmentIncludeAndSkipDirective_Hero_HumanFromHumanEntityMapper(global::StrawberryShake.IEntityStore entityStore) + { + _entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore)); + } + + public GetHeroWithFragmentIncludeAndSkipDirective_Hero_Human Map(global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.HumanEntity entity, global::StrawberryShake.IEntityStoreSnapshot? snapshot = null) + { + if (snapshot is null) + { + snapshot = _entityStore.CurrentSnapshot; + } + + return new GetHeroWithFragmentIncludeAndSkipDirective_Hero_Human(entity.Id, MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends(entity.Friends, snapshot)); + } + + private global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends? MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends(global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.FriendsConnectionData? data, global::StrawberryShake.IEntityStoreSnapshot snapshot) + { + if (data is null) + { + return null; + } + + IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends returnValue = default !; + if (data?.__typename.Equals("FriendsConnection", global::System.StringComparison.Ordinal) ?? false) + { + returnValue = new GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_FriendsConnection(MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo(data.IncludedPageInfo, snapshot), MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo(data.SkippedPageInfo, snapshot)); + } + else + { + throw new global::System.NotSupportedException(); + } + + return returnValue; + } + + private global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo? MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo(global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.PageInfoData? data, global::StrawberryShake.IEntityStoreSnapshot snapshot) + { + if (data is null) + { + return null; + } + + IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo returnValue = default !; + if (data?.__typename.Equals("PageInfo", global::System.StringComparison.Ordinal) ?? false) + { + returnValue = new GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_IncludedPageInfo_PageInfo(data.HasNextPage ?? throw new global::System.ArgumentNullException()); + } + else + { + throw new global::System.NotSupportedException(); + } + + return returnValue; + } + + private global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo? MapIGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo(global::StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective.State.PageInfoData? data, global::StrawberryShake.IEntityStoreSnapshot snapshot) + { + if (data is null) + { + return null; + } + + IGetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo returnValue = default !; + if (data?.__typename.Equals("PageInfo", global::System.StringComparison.Ordinal) ?? false) + { + returnValue = new GetHeroWithFragmentIncludeAndSkipDirective_Hero_Friends_SkippedPageInfo_PageInfo(data.HasNextPage ?? throw new global::System.ArgumentNullException()); + } + else + { + throw new global::System.NotSupportedException(); + } + + return returnValue; + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.EntityIdFactoryGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClientEntityIdFactory : 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 + { + "Droid" => ParseDroidEntityId(obj, __typename), + "Human" => ParseHumanEntityId(obj, __typename), + _ => throw new global::System.NotSupportedException()}; + } + + public global::System.String Format(global::StrawberryShake.EntityId entityId) + { + return entityId.Name switch + { + "Droid" => FormatDroidEntityId(entityId), + "Human" => FormatHumanEntityId(entityId), + _ => throw new global::System.NotSupportedException()}; + } + + private global::StrawberryShake.EntityId ParseDroidEntityId(global::System.Text.Json.JsonElement obj, global::System.String type) + { + return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!); + } + + private global::System.String FormatDroidEntityId(global::StrawberryShake.EntityId entityId) + { + using var writer = new global::StrawberryShake.Internal.ArrayWriter(); + using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options); + jsonWriter.WriteStartObject(); + jsonWriter.WriteString("__typename", entityId.Name); + jsonWriter.WriteString("id", (global::System.String)entityId.Value); + jsonWriter.WriteEndObject(); + jsonWriter.Flush(); + return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length); + } + + private global::StrawberryShake.EntityId ParseHumanEntityId(global::System.Text.Json.JsonElement obj, global::System.String type) + { + return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!); + } + + private global::System.String FormatHumanEntityId(global::StrawberryShake.EntityId entityId) + { + using var writer = new global::StrawberryShake.Internal.ArrayWriter(); + using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options); + jsonWriter.WriteStartObject(); + jsonWriter.WriteString("__typename", entityId.Name); + jsonWriter.WriteString("id", (global::System.String)entityId.Value); + jsonWriter.WriteEndObject(); + jsonWriter.Flush(); + return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length); + } + } + + // StrawberryShake.CodeGeneration.CSharp.Generators.StoreAccessorGenerator + [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.0.0")] + public partial class StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClientStoreAccessor : global::StrawberryShake.StoreAccessor + { + public StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClientStoreAccessor(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) + { + } + } +} + + diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveTest.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveTest.cs new file mode 100644 index 00000000000..34c94242b79 --- /dev/null +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveTest.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using HotChocolate.AspNetCore.Tests.Utilities; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using StrawberryShake.Transport.WebSockets; +using Xunit; + +namespace StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsGetHeroWithFragmentIncludeAndSkipDirective; + +public class StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveTest : ServerTestBase +{ + public StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveTest(TestServerFactory serverFactory) : base(serverFactory) + { + } + + [Fact] + public async Task Execute_StarWarsGetHeroWithFragmentIncludeAndSkipDirective_Test() + { + // arrange + CancellationToken ct = new CancellationTokenSource(20_000).Token; + using IWebHost host = TestServerHelper.CreateServer( + _ => { }, + out var port); + var serviceCollection = new ServiceCollection(); + serviceCollection.AddHttpClient( + StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient.ClientName, + c => c.BaseAddress = new Uri("http://localhost:" + port + "/graphql")); + serviceCollection.AddWebSocketClient( + StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient.ClientName, + c => c.Uri = new Uri("ws://localhost:" + port + "/graphql")); + serviceCollection.AddStarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient(); + IServiceProvider services = serviceCollection.BuildServiceProvider(); + StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveClient client = services.GetRequiredService(); + + // act + var result = await client.GetHeroWithFragmentIncludeAndSkipDirective.ExecuteAsync(false, true, ct); + + // assert + result.EnsureNoErrors(); + Assert.Null(result.Data!.Hero!.Friends!.IncludedPageInfo); + Assert.Null(result.Data!.Hero!.Friends!.SkippedPageInfo); + } +} 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 1a547a4b613..6a79609fb6a 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/TestGeneration.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/TestGeneration.cs @@ -16,6 +16,37 @@ public void StarWarsGetHero() => } }"); + + [Fact] + public void StarWarsGetHeroWithFragmentIncludeAndSkipDirective() => + AssertStarWarsResult( + CreateIntegrationTest(), + @"query GetHeroWithFragmentIncludeAndSkipDirective($includePageInfo: Boolean = false, $skipPageInfo: Boolean = true) { + hero(episode: NEW_HOPE) { + ...HeroFragment + } + } + + fragment HeroFragment on Character { + id + friends { + ...FriendsFragment + } + } + + fragment FriendsFragment on FriendsConnection { + includedPageInfo: pageInfo @include(if: $includePageInfo) { + ...PageInfoFragment + } + skippedPageInfo: pageInfo @skip(if: $skipPageInfo) { + ...PageInfoFragment + } + } + + fragment PageInfoFragment on PageInfo { + hasNextPage + }"); + [Fact] public void StarWarsGetFriendsNoStore() => AssertStarWarsResult(