Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NullReferenceException in HotChocolateAzureFunctionServiceCollectionExtensions #5581

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using HotChocolate;
using HotChocolate.AspNetCore;
using HotChocolate.AzureFunctions;
using HotChocolate.Execution.Configuration;
Expand Down Expand Up @@ -25,6 +26,9 @@ public static class HotChocolateAzureFunctionServiceCollectionExtensions
/// <param name="apiRoute">
/// The API route that was used in the GraphQL Azure Function.
/// </param>
/// <param name="schemaName">
/// The name of the schema that shall be used by this Azure Function.
/// </param>
/// <returns>
/// Returns the <see cref="IRequestExecutorBuilder"/> so that configuration can be chained.
/// </returns>
Expand All @@ -34,7 +38,8 @@ public static class HotChocolateAzureFunctionServiceCollectionExtensions
public static IRequestExecutorBuilder AddGraphQLFunction(
this IServiceCollection services,
int maxAllowedRequestSize = GraphQLAzureFunctionsConstants.DefaultMaxRequests,
string apiRoute = GraphQLAzureFunctionsConstants.DefaultGraphQLRoute)
string apiRoute = GraphQLAzureFunctionsConstants.DefaultGraphQLRoute,
string? schemaName = default)
{
if (services is null)
{
Expand All @@ -57,7 +62,7 @@ public static class HotChocolateAzureFunctionServiceCollectionExtensions
ServiceDescriptor.Singleton<IExtensionConfigProvider, GraphQLExtensions>());

// Add the Request Executor Dependency...
services.AddAzureFunctionsGraphQLRequestExecutorDependency(apiRoute);
services.AddAzureFunctionsGraphQLRequestExecutor(apiRoute, schemaName);

return executorBuilder;
}
Expand All @@ -67,9 +72,10 @@ public static class HotChocolateAzureFunctionServiceCollectionExtensions
/// in-process and isolate-process. Normal configuration should use AddGraphQLFunction()
/// extension instead which correctly call this internally.
/// </summary>
private static IServiceCollection AddAzureFunctionsGraphQLRequestExecutorDependency(
private static IServiceCollection AddAzureFunctionsGraphQLRequestExecutor(
this IServiceCollection services,
string apiRoute = GraphQLAzureFunctionsConstants.DefaultGraphQLRoute
string apiRoute = GraphQLAzureFunctionsConstants.DefaultGraphQLRoute,
string? schemaName = default
)
{
services.AddSingleton<IGraphQLRequestExecutor>(sp =>
Expand All @@ -82,6 +88,7 @@ public static class HotChocolateAzureFunctionServiceCollectionExtensions
{
configure(options);
}
var schemaNameOrDefault = schemaName ?? Schema.DefaultName;

var pipeline =
new PipelineBuilder()
Expand All @@ -92,7 +99,7 @@ public static class HotChocolateAzureFunctionServiceCollectionExtensions
.UseMiddleware<ToolDefaultFileMiddleware>(fileProvider, path)
.UseMiddleware<ToolOptionsFileMiddleware>(path)
.UseMiddleware<ToolStaticFileMiddleware>(fileProvider, path)
.UseMiddleware<HttpGetMiddleware>()
.UseMiddleware<HttpGetMiddleware>(schemaNameOrDefault, path)
.Compile(sp);

return new DefaultGraphQLRequestExecutor(pipeline, options);
Expand Down