@@ -15,11 +15,11 @@ module ServiceCollectionExtensions =
1515 let createStandardOptions executor rootFactory endpointUrl = {
1616 SchemaExecutor = executor
1717 RootFactory = rootFactory
18- ReadBufferSize = 4096
18+ ReadBufferSize = GraphQLOptionsDefaults.ReadBufferSize
1919 SerializerOptions = Json.serializerOptions
2020 WebsocketOptions = {
2121 EndpointUrl = endpointUrl
22- ConnectionInitTimeoutInMs = 3000
22+ ConnectionInitTimeout = TimeSpan.FromMilliseconds ( GraphQLOptionsDefaults.WebSocketConnectionInitTimeoutInMs )
2323 CustomPingHandler = ValueNone
2424 }
2525 }
@@ -31,16 +31,24 @@ module ServiceCollectionExtensions =
3131
3232 type IServiceCollection with
3333
34+ /// <summary>
35+ /// Adds GraphQL options to the service collection.
36+ /// <para>
37+ /// It also adds converters to <see href="Microsoft.AspNetCore.Http.Json.JsonOptions" />
38+ /// to support serialization of GraphQL responses.
39+ /// </para>
40+ /// </summary>
3441 [<Extension; CompiledName " AddGraphQLOptions" >]
3542 member services.AddGraphQLOptions < 'Root >
3643 (
37- executor : Executor < 'Root >,
44+ executorFactory : Func < IServiceProvider , Executor < 'Root > >,
3845 rootFactory : HttpContext -> 'Root ,
39- endpointUrl : string ,
46+ [<Optional ; DefaultParameterValue ( GraphQLOptionsDefaults.WebSocketEndpoint ) >] webSocketEndpointUrl : string ,
4047 [<Optional>] configure : Func < GraphQLOptions < 'Root >, GraphQLOptions < 'Root >>
4148 ) =
42- let options =
43- let options = createStandardOptions executor rootFactory endpointUrl
49+ let getOptions sp =
50+ let executor = executorFactory.Invoke sp
51+ let options = createStandardOptions executor rootFactory webSocketEndpointUrl
4452 match configure with
4553 | null -> options
4654 | _ -> configure.Invoke options
@@ -54,9 +62,10 @@ module ServiceCollectionExtensions =
5462 )
5563 )
5664 .AddSingleton< IOptionsFactory< GraphQLOptions< 'Root>>>(
57- { new IOptionsFactory< GraphQLOptions< 'Root>> with
58- member this.Create name = options
59- }
65+ fun sp ->
66+ { new IOptionsFactory< GraphQLOptions< 'Root>> with
67+ member this.Create name = ( getOptions sp)
68+ }
6069 )
6170 .Configure< GraphQLOptions< 'Root>>( Giraffe.HttpHandlers.IndentedOptionsName, ( fun o -> o.SerializerOptions.WriteIndented <- true ))
6271 .AddSingleton< IOptionsFactory< IGraphQLOptions>>( fun sp ->
@@ -66,6 +75,44 @@ module ServiceCollectionExtensions =
6675 }
6776 )
6877
78+ /// <summary>
79+ /// Adds GraphQL options to the service collection. Requires an executor instance to be provided.
80+ /// <para>
81+ /// It also adds converters to <see href="Microsoft.AspNetCore.Http.Json.JsonOptions" />
82+ /// to support serialization of GraphQL responses.
83+ /// </para>
84+ /// </summary>
85+ [<Extension; CompiledName " AddGraphQLOptions" >]
86+ member services.AddGraphQLOptions < 'Root >
87+ (
88+ executor : Executor < 'Root >,
89+ rootFactory : HttpContext -> 'Root ,
90+ [<Optional; DefaultParameterValue ( GraphQLOptionsDefaults.WebSocketEndpoint) >] webSocketEndpointUrl : string ,
91+ [<Optional>] configure : Func < GraphQLOptions < 'Root >, GraphQLOptions < 'Root >>
92+ ) =
93+ services.AddGraphQLOptions (( fun _ -> executor), rootFactory, webSocketEndpointUrl, configure)
94+
95+ /// <summary>
96+ /// Adds GraphQL options to the service collection. It gets the executor from the service provider.
97+ /// <para>
98+ /// It also adds converters to <see href="Microsoft.AspNetCore.Http.Json.JsonOptions" />
99+ /// to support serialization of GraphQL responses.
100+ /// </para>
101+ /// </summary>
102+ /// <remarks>
103+ /// The executor must be registered as a singleton service.
104+ /// </remarks>
105+ [<Extension; CompiledName " AddGraphQLOptions" >]
106+ member services.AddGraphQLOptions < 'Root >
107+ (
108+ rootFactory : HttpContext -> 'Root ,
109+ [<Optional; DefaultParameterValue ( GraphQLOptionsDefaults.WebSocketEndpoint) >] webSocketEndpointUrl : string ,
110+ [<Optional>] configure : Func < GraphQLOptions < 'Root >, GraphQLOptions < 'Root >>
111+ ) =
112+ let getExecutorService ( sp : IServiceProvider ) = sp.GetRequiredService< Executor< 'Root>>()
113+ services.AddGraphQLOptions ( getExecutorService, rootFactory, webSocketEndpointUrl, configure)
114+
115+
69116[<AutoOpen; Extension>]
70117module ApplicationBuilderExtensions =
71118
0 commit comments