Skip to content

Commit c79dceb

Browse files
committed
Added IApplicationBuilder overload to MapGraphQL. (#6830)
1 parent 3d8bbe0 commit c79dceb

File tree

4 files changed

+59
-23
lines changed

4 files changed

+59
-23
lines changed

.github/workflows/ci-cleanup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
cleanup:
10-
runs-on: ubuntu-latest
10+
runs-on: self-ubuntu
1111
steps:
1212
- name: Check out code
1313
uses: actions/checkout@v3

.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ concurrency:
1212
jobs:
1313
check-changes:
1414
name: Check for Changes
15-
runs-on: ubuntu-latest
15+
runs-on: self-ubuntu
1616
if: github.event.pull_request.draft == false
1717
outputs:
1818
website_changes: ${{ steps.check-website.outputs.website_changes }}
@@ -56,7 +56,7 @@ jobs:
5656
5757
pr-labeler:
5858
name: Apply Labels
59-
runs-on: ubuntu-latest
59+
runs-on: self-ubuntu
6060
permissions:
6161
contents: read
6262
pull-requests: write
@@ -67,7 +67,7 @@ jobs:
6767

6868
spellcheck:
6969
name: "Spellcheck Documentation"
70-
runs-on: ubuntu-latest
70+
runs-on: self-ubuntu
7171
needs: check-changes
7272
if: needs.check-changes.outputs.website_changes == 'true'
7373
steps:
@@ -91,7 +91,7 @@ jobs:
9191
name: "Website Tests"
9292
needs: check-changes
9393
if: needs.check-changes.outputs.website_changes == 'true'
94-
runs-on: ubuntu-latest
94+
runs-on: self-ubuntu
9595
steps:
9696
- name: Checkout Repository
9797
uses: actions/checkout@v2
@@ -123,7 +123,7 @@ jobs:
123123

124124
configure:
125125
name: Generate Test Matrix
126-
runs-on: ubuntu-latest
126+
runs-on: self-ubuntu
127127
needs: check-changes
128128
if: needs.check-changes.outputs.library_changes == 'true'
129129

@@ -150,7 +150,7 @@ jobs:
150150

151151
library-tests:
152152
name: Run ${{ matrix.name }}
153-
runs-on: ubuntu-latest
153+
runs-on: self-ubuntu
154154
needs: [configure, check-changes]
155155
if: needs.check-changes.outputs.library_changes == 'true'
156156

@@ -277,7 +277,7 @@ jobs:
277277
278278
codeql:
279279
name: CodeQL
280-
runs-on: ubuntu-latest
280+
runs-on: self-ubuntu
281281
needs: check-changes
282282
if: needs.check-changes.outputs.src_changes == 'true'
283283

@@ -323,7 +323,7 @@ jobs:
323323
name: Merge and Upload Coverage
324324
needs: library-tests
325325
if: always() && needs.library-tests.result != 'cancelled'
326-
runs-on: ubuntu-latest
326+
runs-on: self-ubuntu
327327
steps:
328328
- name: Checkout repository
329329
uses: actions/checkout@v2
@@ -383,7 +383,7 @@ jobs:
383383
name: "CI Status Check"
384384
needs: [library-tests, website-tests]
385385
if: always()
386-
runs-on: ubuntu-latest
386+
runs-on: self-ubuntu
387387
steps:
388388
- name: Check if Library Tests or Website Tests failed
389389
run: exit 1

.github/workflows/coverage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ concurrency:
1414
jobs:
1515
configure:
1616
name: Generate Test Matrix
17-
runs-on: ubuntu-latest
17+
runs-on: self-ubuntu
1818

1919
outputs:
2020
matrix: ${{ steps.set-matrix.outputs.matrix }}
@@ -39,7 +39,7 @@ jobs:
3939

4040
library-tests:
4141
name: Run ${{ matrix.name }}
42-
runs-on: ubuntu-latest
42+
runs-on: self-ubuntu
4343
needs: configure
4444

4545
strategy:
@@ -115,7 +115,7 @@ jobs:
115115
name: Merge and Upload Coverage
116116
needs: library-tests
117117
if: always() && needs.library-tests.result != 'cancelled'
118-
runs-on: ubuntu-latest
118+
runs-on: self-ubuntu
119119
steps:
120120
- name: Checkout repository
121121
uses: actions/checkout@v2

src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/EndpointRouteBuilderExtensions.cs

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,60 @@ public static GraphQLEndpointConventionBuilder MapGraphQL(
7878
var requestPipeline = endpointRouteBuilder.CreateApplicationBuilder();
7979
var schemaNameOrDefault = schemaName ?? Schema.DefaultName;
8080

81-
requestPipeline
81+
requestPipeline.MapGraphQL(path, schemaNameOrDefault);
82+
83+
return new GraphQLEndpointConventionBuilder(
84+
endpointRouteBuilder
85+
.Map(pattern, requestPipeline.Build())
86+
.WithDisplayName("Hot Chocolate GraphQL Pipeline"));
87+
}
88+
89+
/// <summary>
90+
/// Adds a GraphQL endpoint to the endpoint configurations.
91+
/// </summary>
92+
/// <param name="applicationBuilder">
93+
/// The <see cref="IApplicationBuilder"/>.
94+
/// </param>
95+
/// <param name="path">
96+
/// The path to which the GraphQL endpoint shall be mapped.
97+
/// </param>
98+
/// <param name="schemaName">
99+
/// The name of the schema that shall be used by this endpoint.
100+
/// </param>
101+
/// <returns>
102+
/// Returns the <see cref="IEndpointConventionBuilder"/> so that
103+
/// configuration can be chained.
104+
/// </returns>
105+
/// <exception cref="ArgumentNullException">
106+
/// The <paramref name="applicationBuilder" /> is <c>null</c>.
107+
/// </exception>
108+
public static IApplicationBuilder MapGraphQL(
109+
this IApplicationBuilder applicationBuilder,
110+
PathString path,
111+
string schemaName)
112+
{
113+
if (applicationBuilder is null)
114+
{
115+
throw new ArgumentNullException(nameof(applicationBuilder));
116+
}
117+
118+
path = path.ToString().TrimEnd('/');
119+
120+
applicationBuilder
82121
.UseCancellation()
83-
.UseMiddleware<WebSocketSubscriptionMiddleware>(schemaNameOrDefault)
84-
.UseMiddleware<HttpPostMiddleware>(schemaNameOrDefault)
85-
.UseMiddleware<HttpMultipartMiddleware>(schemaNameOrDefault)
86-
.UseMiddleware<HttpGetMiddleware>(schemaNameOrDefault)
87-
.UseMiddleware<HttpGetSchemaMiddleware>(schemaNameOrDefault, Integrated)
122+
.UseMiddleware<WebSocketSubscriptionMiddleware>(schemaName)
123+
.UseMiddleware<HttpPostMiddleware>(schemaName)
124+
.UseMiddleware<HttpMultipartMiddleware>(schemaName)
125+
.UseMiddleware<HttpGetMiddleware>(schemaName)
126+
.UseMiddleware<HttpGetSchemaMiddleware>(schemaName, Integrated)
88127
.UseBananaCakePop(path)
89128
.Use(_ => context =>
90129
{
91130
context.Response.StatusCode = 404;
92131
return Task.CompletedTask;
93132
});
94133

95-
return new GraphQLEndpointConventionBuilder(
96-
endpointRouteBuilder
97-
.Map(pattern, requestPipeline.Build())
98-
.WithDisplayName("Hot Chocolate GraphQL Pipeline"));
134+
return applicationBuilder;
99135
}
100136

101137
/// <summary>

0 commit comments

Comments
 (0)