fix EntityGraphQLEndpointRouteExtensions.MapGraphQL to support chunked requests sent via PostAsJsonAsync#461
Merged
lukemurray merged 1 commit intoEntityGraphQL:masterfrom Aug 6, 2025
Conversation
…chunked HTTP requests sent by PostAsJsonAsync `PostAsJsonAsync` uses `Transfer-Encoding: chunked`, which causes `ContentLength` to be `null`. The previous GraphQL endpoint implementation rejected such requests with 400 Bad Request if `ContentLength` was null or zero, even though chunked requests are valid per HTTP/1.1. This change adds support for chunked requests by checking the `Transfer-Encoding` header before applying the `ContentLength` fallback logic. The issue is reproduced with `GraphQL_Endpoint_200_On_Chunked_Data_Query` test, that uses `CustomWebApplicationFactory` (won't work with `IClassFixture<WebApplicationFactory<Program>>` because it must communicate over the wire).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
HttpClient.PostAsJsonAsync()to call the GraphQL endpoint (EntityGraphQLEndpointRouteExtensions.MapGraphQL), the request fails with400 Bad Request. This happens becausePostAsJsonAsync:Transfer-Encoding: chunkedContent-LengthThe current implementation in
EntityGraphQLEndpointRouteExtensions.MapGraphQL<T>()rejects all requests whereContentLength == nullor0, making it incompatible with chunked transfers — despite chunked encoding being fully compliant with HTTP/1.1.This behavior makes the GraphQL endpoint incompatible with a common usage of HTTP client libraries.
Fix
In
MapGraphQL<TQueryType>, we now:Transfer-Encoding: chunkedContent-LengthThis ensures the GraphQL endpoint accepts another valid type of HTTP/1.1 requests.
Test Coverage
A new integration test using the existing
CustomWebApplicationFactoryinfrastructure has been added. It runs the app over a real TCP socket (Kestrel) to confirm that:PostAsJsonAsync()sends a chunked requestNote: the test must use communication over the wire, via
CustomWebApplicationFactory, a Testcontainer, or any other way that's not pure in-memory, like withIClassFixture<WebApplicationFactory<Program>>. Otherwise,Content-Lengthis set. I've also tried to reproduce it with the .NET 10 Preview 4 feature "Use WebApplicationFactory with Kestrel for integration testing" but the test passed similar to the way it passes withIClassFixture<WebApplicationFactory<Program>>, so it wasn't a good way to reproduce it with that method:Result
GraphQL over HTTP specPostAsJsonAsync