Skip to content

Commit

Permalink
Added IApplicationBuilder overload to MapGraphQL. (#6830)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Jan 26, 2024
1 parent 3d8bbe0 commit c79dceb
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
cleanup:
runs-on: ubuntu-latest
runs-on: self-ubuntu
steps:
- name: Check out code
uses: actions/checkout@v3
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:
jobs:
check-changes:
name: Check for Changes
runs-on: ubuntu-latest
runs-on: self-ubuntu
if: github.event.pull_request.draft == false
outputs:
website_changes: ${{ steps.check-website.outputs.website_changes }}
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
pr-labeler:
name: Apply Labels
runs-on: ubuntu-latest
runs-on: self-ubuntu
permissions:
contents: read
pull-requests: write
Expand All @@ -67,7 +67,7 @@ jobs:

spellcheck:
name: "Spellcheck Documentation"
runs-on: ubuntu-latest
runs-on: self-ubuntu
needs: check-changes
if: needs.check-changes.outputs.website_changes == 'true'
steps:
Expand All @@ -91,7 +91,7 @@ jobs:
name: "Website Tests"
needs: check-changes
if: needs.check-changes.outputs.website_changes == 'true'
runs-on: ubuntu-latest
runs-on: self-ubuntu
steps:
- name: Checkout Repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:

configure:
name: Generate Test Matrix
runs-on: ubuntu-latest
runs-on: self-ubuntu
needs: check-changes
if: needs.check-changes.outputs.library_changes == 'true'

Expand All @@ -150,7 +150,7 @@ jobs:

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

Expand Down Expand Up @@ -277,7 +277,7 @@ jobs:
codeql:
name: CodeQL
runs-on: ubuntu-latest
runs-on: self-ubuntu
needs: check-changes
if: needs.check-changes.outputs.src_changes == 'true'

Expand Down Expand Up @@ -323,7 +323,7 @@ jobs:
name: Merge and Upload Coverage
needs: library-tests
if: always() && needs.library-tests.result != 'cancelled'
runs-on: ubuntu-latest
runs-on: self-ubuntu
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -383,7 +383,7 @@ jobs:
name: "CI Status Check"
needs: [library-tests, website-tests]
if: always()
runs-on: ubuntu-latest
runs-on: self-ubuntu
steps:
- name: Check if Library Tests or Website Tests failed
run: exit 1
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ concurrency:
jobs:
configure:
name: Generate Test Matrix
runs-on: ubuntu-latest
runs-on: self-ubuntu

outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
Expand All @@ -39,7 +39,7 @@ jobs:

library-tests:
name: Run ${{ matrix.name }}
runs-on: ubuntu-latest
runs-on: self-ubuntu
needs: configure

strategy:
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
name: Merge and Upload Coverage
needs: library-tests
if: always() && needs.library-tests.result != 'cancelled'
runs-on: ubuntu-latest
runs-on: self-ubuntu
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,60 @@ public static GraphQLEndpointConventionBuilder MapGraphQL(
var requestPipeline = endpointRouteBuilder.CreateApplicationBuilder();
var schemaNameOrDefault = schemaName ?? Schema.DefaultName;

requestPipeline
requestPipeline.MapGraphQL(path, schemaNameOrDefault);

return new GraphQLEndpointConventionBuilder(
endpointRouteBuilder
.Map(pattern, requestPipeline.Build())
.WithDisplayName("Hot Chocolate GraphQL Pipeline"));
}

/// <summary>
/// Adds a GraphQL endpoint to the endpoint configurations.
/// </summary>
/// <param name="applicationBuilder">
/// The <see cref="IApplicationBuilder"/>.
/// </param>
/// <param name="path">
/// The path to which the GraphQL endpoint shall be mapped.
/// </param>
/// <param name="schemaName">
/// The name of the schema that shall be used by this endpoint.
/// </param>
/// <returns>
/// Returns the <see cref="IEndpointConventionBuilder"/> so that
/// configuration can be chained.
/// </returns>
/// <exception cref="ArgumentNullException">
/// The <paramref name="applicationBuilder" /> is <c>null</c>.
/// </exception>
public static IApplicationBuilder MapGraphQL(
this IApplicationBuilder applicationBuilder,
PathString path,
string schemaName)
{
if (applicationBuilder is null)
{
throw new ArgumentNullException(nameof(applicationBuilder));
}

path = path.ToString().TrimEnd('/');

applicationBuilder
.UseCancellation()
.UseMiddleware<WebSocketSubscriptionMiddleware>(schemaNameOrDefault)
.UseMiddleware<HttpPostMiddleware>(schemaNameOrDefault)
.UseMiddleware<HttpMultipartMiddleware>(schemaNameOrDefault)
.UseMiddleware<HttpGetMiddleware>(schemaNameOrDefault)
.UseMiddleware<HttpGetSchemaMiddleware>(schemaNameOrDefault, Integrated)
.UseMiddleware<WebSocketSubscriptionMiddleware>(schemaName)
.UseMiddleware<HttpPostMiddleware>(schemaName)
.UseMiddleware<HttpMultipartMiddleware>(schemaName)
.UseMiddleware<HttpGetMiddleware>(schemaName)
.UseMiddleware<HttpGetSchemaMiddleware>(schemaName, Integrated)
.UseBananaCakePop(path)
.Use(_ => context =>
{
context.Response.StatusCode = 404;
return Task.CompletedTask;
});

return new GraphQLEndpointConventionBuilder(
endpointRouteBuilder
.Map(pattern, requestPipeline.Build())
.WithDisplayName("Hot Chocolate GraphQL Pipeline"));
return applicationBuilder;
}

/// <summary>
Expand Down

0 comments on commit c79dceb

Please sign in to comment.