From 1035ba6dc849efe049a2952a772efb39a5550020 Mon Sep 17 00:00:00 2001 From: Andrii Chebukin Date: Tue, 12 May 2026 14:45:49 +0200 Subject: [PATCH] Fixed `AddGraphQL` overloads resolution --- .../ServiceCollectionExtensions.fs | 6 +- ...ata.GraphQL.IntegrationTests.Server.fsproj | 1 + ...iceCollectionExtensionsCompilationTests.fs | 64 +++++++++++++++++++ 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 tests/FSharp.Data.GraphQL.IntegrationTests.Server/ServiceCollectionExtensionsCompilationTests.fs diff --git a/src/FSharp.Data.GraphQL.Server.AspNetCore/ServiceCollectionExtensions.fs b/src/FSharp.Data.GraphQL.Server.AspNetCore/ServiceCollectionExtensions.fs index b9a35b11..fb3fd92f 100644 --- a/src/FSharp.Data.GraphQL.Server.AspNetCore/ServiceCollectionExtensions.fs +++ b/src/FSharp.Data.GraphQL.Server.AspNetCore/ServiceCollectionExtensions.fs @@ -257,7 +257,7 @@ module ServiceCollectionExtensions = member services.AddGraphQL<'Root, 'Handler when 'Handler :> GraphQLRequestHandler<'Root> and 'Handler : not struct> ( rootFactory : HttpContext -> 'Root, - [] webSocketEndpointPath : string, + webSocketEndpointPath : string, [] additionalConverters : JsonConverter seq ) = let getExecutorService (sp : IServiceProvider) = sp.GetRequiredService>() @@ -277,7 +277,7 @@ module ServiceCollectionExtensions = member services.AddGraphQL<'Root> ( rootFactory : HttpContext -> 'Root, - [] webSocketEndpointPath : string, + webSocketEndpointPath : string, [] additionalConverters : JsonConverter seq ) = let getExecutorService (sp : IServiceProvider) = sp.GetRequiredService>() @@ -301,7 +301,7 @@ module ServiceCollectionExtensions = [] additionalConverters : JsonConverter seq ) = let getExecutorService (sp : IServiceProvider) = sp.GetRequiredService>() - services.AddGraphQL<'Root, 'Handler> (getExecutorService, rootFactory, additionalConverters, configure = null) + services.AddGraphQL<'Root, 'Handler> (getExecutorService, rootFactory, additionalConverters, configure = configure) /// /// Adds GraphQL options and services to the service collection. It gets the executor from the service provider. diff --git a/tests/FSharp.Data.GraphQL.IntegrationTests.Server/FSharp.Data.GraphQL.IntegrationTests.Server.fsproj b/tests/FSharp.Data.GraphQL.IntegrationTests.Server/FSharp.Data.GraphQL.IntegrationTests.Server.fsproj index 6a4a691b..cdecb09f 100644 --- a/tests/FSharp.Data.GraphQL.IntegrationTests.Server/FSharp.Data.GraphQL.IntegrationTests.Server.fsproj +++ b/tests/FSharp.Data.GraphQL.IntegrationTests.Server/FSharp.Data.GraphQL.IntegrationTests.Server.fsproj @@ -15,6 +15,7 @@ + diff --git a/tests/FSharp.Data.GraphQL.IntegrationTests.Server/ServiceCollectionExtensionsCompilationTests.fs b/tests/FSharp.Data.GraphQL.IntegrationTests.Server/ServiceCollectionExtensionsCompilationTests.fs new file mode 100644 index 00000000..d0703f58 --- /dev/null +++ b/tests/FSharp.Data.GraphQL.IntegrationTests.Server/ServiceCollectionExtensionsCompilationTests.fs @@ -0,0 +1,64 @@ +/// Compilation-only tests that verify all public AddGraphQL overloads resolve correctly. +/// These functions are never called at runtime. +module FSharp.Data.GraphQL.IntegrationTests.Server.ServiceCollectionExtensionsCompilationTests + +open System +open Microsoft.AspNetCore.Http +open Microsoft.Extensions.DependencyInjection + +open FSharp.Data.GraphQL.Server.AspNetCore +open FSharp.Data.GraphQL.Samples.StarWarsApi + +let private rootFactory (ctx : HttpContext) : Root = Root(ctx) + +let private probe_ExecutorInstance_Handler_NoOptionals () = + let services = ServiceCollection() :> IServiceCollection + services.AddGraphQL>(Schema.executor, rootFactory) |> ignore + +let private probe_ExecutorInstance_Handler_WithWsPath () = + let services = ServiceCollection() :> IServiceCollection + services.AddGraphQL>(Schema.executor, rootFactory, "/ws") |> ignore + +let private probe_ExecutorInstance_Handler_WithConfigure () = + let services = ServiceCollection() :> IServiceCollection + let configure = Func, GraphQLOptions>(id) + services.AddGraphQL>(Schema.executor, rootFactory, configure) |> ignore + +let private probe_ExecutorInstance_NoHandler_NoOptionals () = + let services = ServiceCollection() :> IServiceCollection + services.AddGraphQL(Schema.executor, rootFactory) |> ignore + +let private probe_ExecutorInstance_NoHandler_WithWsPath () = + let services = ServiceCollection() :> IServiceCollection + services.AddGraphQL(Schema.executor, rootFactory, "/ws") |> ignore + +let private probe_ExecutorInstance_NoHandler_WithConfigure () = + let services = ServiceCollection() :> IServiceCollection + let configure = Func, GraphQLOptions>(id) + services.AddGraphQL(Schema.executor, rootFactory, configure) |> ignore + +let private probe_FromDI_Handler_WithWsPath () = + let services = ServiceCollection() :> IServiceCollection + services.AddGraphQL>(rootFactory, "/ws") |> ignore + +let private probe_FromDI_Handler_NoOptionals () = + let services = ServiceCollection() :> IServiceCollection + services.AddGraphQL>(rootFactory) |> ignore + +let private probe_FromDI_Handler_WithConfigure () = + let services = ServiceCollection() :> IServiceCollection + let configure = Func, GraphQLOptions>(id) + services.AddGraphQL>(rootFactory, configure) |> ignore + +let private probe_FromDI_NoHandler_WithWsPath () = + let services = ServiceCollection() :> IServiceCollection + services.AddGraphQL(rootFactory, "/ws") |> ignore + +let private probe_FromDI_NoHandler_NoOptionals () = + let services = ServiceCollection() :> IServiceCollection + services.AddGraphQL(rootFactory) |> ignore + +let private probe_FromDI_NoHandler_WithConfigure () = + let services = ServiceCollection() :> IServiceCollection + let configure = Func, GraphQLOptions>(id) + services.AddGraphQL(rootFactory, configure) |> ignore