From 5e53932c533a4805a67f1d14b237b17eac25979d Mon Sep 17 00:00:00 2001
From: Tobias Tengler <45513122+tobias-tengler@users.noreply.github.com>
Date: Tue, 22 Feb 2022 20:04:49 +0100
Subject: [PATCH 1/2] Add default arguments to Map methods
---
.../EndpointRouteBuilderExtensions.cs | 60 ++++++++++++++-----
1 file changed, 44 insertions(+), 16 deletions(-)
diff --git a/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/EndpointRouteBuilderExtensions.cs b/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/EndpointRouteBuilderExtensions.cs
index f53e7d88640..eafead924fc 100644
--- a/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/EndpointRouteBuilderExtensions.cs
+++ b/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/EndpointRouteBuilderExtensions.cs
@@ -13,6 +13,12 @@ namespace Microsoft.AspNetCore.Builder;
///
public static class EndpointRouteBuilderExtensions
{
+ private const string GraphQLHttpPath = "/graphql";
+ private const string GraphQLWebSocketPath = "/graphql/ws";
+ private const string GraphQLSchemaPath = "/graphql/sdl";
+ private const string GraphQLToolPath = "/graphql/ui";
+ private const string GraphQLToolRelativeRequestPath = "..";
+
///
/// Adds a GraphQL endpoint to the endpoint configurations.
///
@@ -31,7 +37,7 @@ public static class EndpointRouteBuilderExtensions
///
public static GraphQLEndpointConventionBuilder MapGraphQL(
this IEndpointRouteBuilder endpointRouteBuilder,
- string path = "/graphql",
+ string path = GraphQLHttpPath,
NameString schemaName = default)
=> MapGraphQL(endpointRouteBuilder, new PathString(path), schemaName);
@@ -116,7 +122,7 @@ public static GraphQLEndpointConventionBuilder MapGraphQL(
///
public static GraphQLHttpEndpointConventionBuilder MapGraphQLHttp(
this IEndpointRouteBuilder endpointRouteBuilder,
- string pattern,
+ string pattern = GraphQLHttpPath,
NameString schemaName = default)
=> MapGraphQLHttp(endpointRouteBuilder, Parse(pattern), schemaName);
@@ -141,7 +147,7 @@ public static GraphQLHttpEndpointConventionBuilder MapGraphQLHttp(
///
public static GraphQLHttpEndpointConventionBuilder MapGraphQLHttp(
this IEndpointRouteBuilder endpointRouteBuilder,
- RoutePattern? pattern = default,
+ RoutePattern pattern,
NameString schemaName = default)
{
if (endpointRouteBuilder is null)
@@ -149,7 +155,7 @@ public static GraphQLHttpEndpointConventionBuilder MapGraphQLHttp(
throw new ArgumentNullException(nameof(endpointRouteBuilder));
}
- pattern ??= Parse("/graphql");
+ pattern ??= Parse(GraphQLHttpPath);
IApplicationBuilder requestPipeline = endpointRouteBuilder.CreateApplicationBuilder();
NameString schemaNameOrDefault = schemaName.HasValue ? schemaName : Schema.DefaultName;
@@ -192,7 +198,7 @@ public static GraphQLHttpEndpointConventionBuilder MapGraphQLHttp(
///
public static IEndpointConventionBuilder MapGraphQLWebSocket(
this IEndpointRouteBuilder endpointRouteBuilder,
- string pattern,
+ string pattern = GraphQLWebSocketPath,
NameString schemaName = default)
=> MapGraphQLWebSocket(endpointRouteBuilder, Parse(pattern), schemaName);
@@ -217,7 +223,7 @@ public static IEndpointConventionBuilder MapGraphQLWebSocket(
///
public static IEndpointConventionBuilder MapGraphQLWebSocket(
this IEndpointRouteBuilder endpointRouteBuilder,
- RoutePattern? pattern = default,
+ RoutePattern pattern,
NameString schemaName = default)
{
if (endpointRouteBuilder is null)
@@ -225,7 +231,7 @@ public static IEndpointConventionBuilder MapGraphQLWebSocket(
throw new ArgumentNullException(nameof(endpointRouteBuilder));
}
- pattern ??= Parse("/graphql/ws");
+ pattern ??= Parse(GraphQLWebSocketPath);
IApplicationBuilder requestPipeline = endpointRouteBuilder.CreateApplicationBuilder();
NameString schemaNameOrDefault = schemaName.HasValue ? schemaName : Schema.DefaultName;
@@ -266,7 +272,7 @@ public static IEndpointConventionBuilder MapGraphQLWebSocket(
///
public static IEndpointConventionBuilder MapGraphQLSchema(
this IEndpointRouteBuilder endpointRouteBuilder,
- string pattern,
+ string pattern = GraphQLSchemaPath,
NameString schemaName = default)
=> MapGraphQLSchema(endpointRouteBuilder, Parse(pattern), schemaName);
@@ -291,7 +297,7 @@ public static IEndpointConventionBuilder MapGraphQLSchema(
///
public static IEndpointConventionBuilder MapGraphQLSchema(
this IEndpointRouteBuilder endpointRouteBuilder,
- RoutePattern? pattern = default,
+ RoutePattern pattern,
NameString schemaName = default)
{
if (endpointRouteBuilder is null)
@@ -299,7 +305,7 @@ public static IEndpointConventionBuilder MapGraphQLSchema(
throw new ArgumentNullException(nameof(endpointRouteBuilder));
}
- pattern ??= Parse("/graphql/sdl");
+ pattern ??= Parse(GraphQLSchemaPath);
IApplicationBuilder requestPipeline = endpointRouteBuilder.CreateApplicationBuilder();
NameString schemaNameOrDefault = schemaName.HasValue ? schemaName : Schema.DefaultName;
@@ -328,7 +334,29 @@ public static IEndpointConventionBuilder MapGraphQLSchema(
/// The .
///
///
- /// The path to which banana cake pop is mapped.
+ /// The path to which Banana Cake Pop is mapped.
+ ///
+ ///
+ /// The relative path on which the server is listening for GraphQL requests.
+ ///
+ ///
+ /// Returns the so that
+ /// configuration can be chained.
+ ///
+ public static BananaCakePopEndpointConventionBuilder MapBananaCakePop(
+ this IEndpointRouteBuilder endpointRouteBuilder,
+ string toolPath = GraphQLToolPath,
+ string? relativeRequestPath = GraphQLToolRelativeRequestPath)
+ => MapBananaCakePop(endpointRouteBuilder, new PathString(toolPath), relativeRequestPath);
+
+ ///
+ /// Adds a Banana Cake Pop endpoint to the endpoint configurations.
+ ///
+ ///
+ /// The .
+ ///
+ ///
+ /// The path to which Banana Cake Pop is mapped.
///
///
/// The relative path on which the server is listening for GraphQL requests.
@@ -339,18 +367,18 @@ public static IEndpointConventionBuilder MapGraphQLSchema(
///
public static BananaCakePopEndpointConventionBuilder MapBananaCakePop(
this IEndpointRouteBuilder endpointRouteBuilder,
- PathString? toolPath = default,
- string? relativeRequestPath = "..")
+ PathString toolPath,
+ string? relativeRequestPath = GraphQLToolRelativeRequestPath)
{
if (endpointRouteBuilder is null)
{
throw new ArgumentNullException(nameof(endpointRouteBuilder));
}
- toolPath ??= "/graphql/ui";
- relativeRequestPath ??= "..";
+ toolPath = toolPath.ToString().TrimEnd('/');
+ relativeRequestPath ??= GraphQLToolRelativeRequestPath;
- RoutePattern pattern = Parse(toolPath.ToString() + "/{**slug}");
+ RoutePattern pattern = Parse(toolPath + "/{**slug}");
IApplicationBuilder requestPipeline = endpointRouteBuilder.CreateApplicationBuilder();
IFileProvider fileProvider = CreateFileProvider();
From fc806c516bc36b8ce08368ded55337d7f025e84f Mon Sep 17 00:00:00 2001
From: Tobias Tengler <45513122+tobias-tengler@users.noreply.github.com>
Date: Wed, 23 Feb 2022 19:55:57 +0100
Subject: [PATCH 2/2] Add ArgumentNullExceptions
---
.../Extensions/EndpointRouteBuilderExtensions.cs | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/EndpointRouteBuilderExtensions.cs b/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/EndpointRouteBuilderExtensions.cs
index eafead924fc..18c59d96ae0 100644
--- a/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/EndpointRouteBuilderExtensions.cs
+++ b/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/EndpointRouteBuilderExtensions.cs
@@ -155,7 +155,10 @@ public static GraphQLHttpEndpointConventionBuilder MapGraphQLHttp(
throw new ArgumentNullException(nameof(endpointRouteBuilder));
}
- pattern ??= Parse(GraphQLHttpPath);
+ if (pattern is null)
+ {
+ throw new ArgumentNullException(nameof(pattern));
+ }
IApplicationBuilder requestPipeline = endpointRouteBuilder.CreateApplicationBuilder();
NameString schemaNameOrDefault = schemaName.HasValue ? schemaName : Schema.DefaultName;
@@ -231,7 +234,10 @@ public static IEndpointConventionBuilder MapGraphQLWebSocket(
throw new ArgumentNullException(nameof(endpointRouteBuilder));
}
- pattern ??= Parse(GraphQLWebSocketPath);
+ if (pattern is null)
+ {
+ throw new ArgumentNullException(nameof(pattern));
+ }
IApplicationBuilder requestPipeline = endpointRouteBuilder.CreateApplicationBuilder();
NameString schemaNameOrDefault = schemaName.HasValue ? schemaName : Schema.DefaultName;
@@ -305,7 +311,10 @@ public static IEndpointConventionBuilder MapGraphQLSchema(
throw new ArgumentNullException(nameof(endpointRouteBuilder));
}
- pattern ??= Parse(GraphQLSchemaPath);
+ if (pattern is null)
+ {
+ throw new ArgumentNullException(nameof(pattern));
+ }
IApplicationBuilder requestPipeline = endpointRouteBuilder.CreateApplicationBuilder();
NameString schemaNameOrDefault = schemaName.HasValue ? schemaName : Schema.DefaultName;