Skip to content

Commit

Permalink
Minor optimizations for the operation compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Jul 7, 2023
1 parent 460f874 commit 99dc6f0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ private void CompleteSelectionSet(CompilerContext context)
isConditional = true;
}

if (fieldType.IsCompositeType())
// Determines if the type is a composite type.
if (fieldType.IsType(TypeKind.Object, TypeKind.Interface, TypeKind.Union))
{
if (selection.SelectionSet is null)
{
Expand Down Expand Up @@ -861,4 +862,4 @@ public override bool Equals(object? obj)
public override int GetHashCode()
=> HashCode.Combine(SelectionSet, Path);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Selection(
? Flags.Internal
: Flags.None;

if (Type.IsListType())
if (Type.IsType(TypeKind.List))
{
_flags |= Flags.List;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ private static bool IsType(this IType type, TypeKind kind1, TypeKind kind2)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsType(this IType type, TypeKind kind1, TypeKind kind2, TypeKind kind3)
internal static bool IsType(this IType type, TypeKind kind1, TypeKind kind2, TypeKind kind3)
{
if (type.Kind == kind1 || type.Kind == kind2 || type.Kind == kind3)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using HotChocolate.Fusion.Pipeline;
using HotChocolate.Fusion.Planning;
using HotChocolate.Language;
using HotChocolate.Types.Descriptors;
using Microsoft.Extensions.DependencyInjection.Extensions;
using static HotChocolate.Fusion.ThrowHelper;

Expand Down Expand Up @@ -53,6 +54,7 @@ public static FusionGatewayBuilder AddFusionGatewayServer(
.UseField(next => next)
.AddOperationCompilerOptimizer<OperationQueryPlanCompiler>()
.AddOperationCompilerOptimizer<FieldFlagsOptimizer>()
.AddConvention<INamingConventions>(_ => new DefaultNamingConventions())
.Configure(
c =>
{
Expand Down
22 changes: 15 additions & 7 deletions src/HotChocolate/Fusion/test/Shared/DemoProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using HotChocolate.Fusion.Shared.Products;
using HotChocolate.Fusion.Shared.Reviews;
using HotChocolate.Fusion.Shared.Shipping;
using HotChocolate.Types.Descriptors;
using HotChocolate.Utilities.Introspection;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -77,7 +78,8 @@ public static async Task<DemoProject> CreateAsync(CancellationToken ct = default
.AddMutationType<ReviewsMutation>()
.AddSubscriptionType<ReviewsSubscription>()
.AddMutationConventions()
.AddGlobalObjectIdentification(),
.AddGlobalObjectIdentification()
.AddConvention<INamingConventions>(_ => new DefaultNamingConventions()),
c => c
.UseWebSockets()
.UseRouting()
Expand All @@ -99,7 +101,8 @@ public static async Task<DemoProject> CreateAsync(CancellationToken ct = default
.AddMutationType<Reviews2.ReviewsMutation>()
.AddSubscriptionType<Reviews2.ReviewsSubscription>()
.AddMutationConventions()
.AddGlobalObjectIdentification(),
.AddGlobalObjectIdentification()
.AddConvention<INamingConventions>(_ => new DefaultNamingConventions()),
c => c
.UseWebSockets()
.UseRouting()
Expand All @@ -120,7 +123,8 @@ public static async Task<DemoProject> CreateAsync(CancellationToken ct = default
.AddQueryType<AccountQuery>()
.AddMutationType<AccountMutation>()
.AddMutationConventions()
.AddGlobalObjectIdentification(),
.AddGlobalObjectIdentification()
.AddConvention<INamingConventions>(_ => new DefaultNamingConventions()),
c => c
.UseRouting()
.UseEndpoints(endpoints => endpoints.MapGraphQL()));
Expand All @@ -138,7 +142,8 @@ public static async Task<DemoProject> CreateAsync(CancellationToken ct = default
.AddSingleton<ProductRepository>()
.AddGraphQLServer()
.AddQueryType<ProductQuery>()
.AddGlobalObjectIdentification(),
.AddGlobalObjectIdentification()
.AddConvention<INamingConventions>(_ => new DefaultNamingConventions()),
c => c
.UseRouting()
.UseEndpoints(endpoints => endpoints.MapGraphQL()));
Expand All @@ -155,7 +160,8 @@ public static async Task<DemoProject> CreateAsync(CancellationToken ct = default
.AddRouting()
.AddGraphQLServer()
.AddQueryType<ShippingQuery>()
.ConfigureSchema(b => b.SetContextData(GlobalIdSupportEnabled, 1)),
.ConfigureSchema(b => b.SetContextData(GlobalIdSupportEnabled, 1))
.AddConvention<INamingConventions>(_ => new DefaultNamingConventions()),
c => c
.UseRouting()
.UseEndpoints(endpoints => endpoints.MapGraphQL()));
Expand All @@ -174,7 +180,8 @@ public static async Task<DemoProject> CreateAsync(CancellationToken ct = default
.AddQueryType<AppointmentQuery>()
.AddObjectType<Appointments.Patient1>()
.AddObjectType<Patient2>()
.AddGlobalObjectIdentification(),
.AddGlobalObjectIdentification()
.AddConvention<INamingConventions>(_ => new DefaultNamingConventions()),
c => c
.UseRouting()
.UseEndpoints(endpoints => endpoints.MapGraphQL()));
Expand All @@ -191,7 +198,8 @@ public static async Task<DemoProject> CreateAsync(CancellationToken ct = default
.AddRouting()
.AddGraphQLServer()
.AddQueryType<Patient1Query>()
.AddGlobalObjectIdentification(),
.AddGlobalObjectIdentification()
.AddConvention<INamingConventions>(_ => new DefaultNamingConventions()),
c => c
.UseRouting()
.UseEndpoints(endpoints => endpoints.MapGraphQL()));
Expand Down

0 comments on commit 99dc6f0

Please sign in to comment.