Skip to content

Add an option to refuse query operations over POST - #10755

Merged
glen-84 merged 1 commit into
mainfrom
gai/enable-queries-over-post-option
Oct 29, 2026
Merged

glen-84 merged 1 commit into
mainfrom
gai/enable-queries-over-post-option

Conversation

@glen-84

@glen-84 glen-84 commented Oct 29, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds GraphQLServerOptions.EnableQueriesOverPost, true by default. When it is false, POST requests refuse query operations, so queries run over QUERY or GET while mutations and subscriptions stay on POST, as the QUERY proposal for GraphQL over HTTP recommends for query operations. It covers the GraphQL endpoint, multipart requests, and the persisted-operation POST routes, and the Fusion gateway gets it through the same middleware.
  • A refused query carries the executor's existing "The specified operation kind is not allowed." error, with the status a mutation refused over GET gets for the same Accept header and transport version. Its 405 lists the methods that serve queries in Allow (GET, HEAD, plus QUERY when QUERY requests are enabled, or an empty value when none does), with Accept-Query when QUERY is listed. In a request batch or an operation batch each query fails on its own, and a variable batch is refused as a whole. While the option is false, a query refused over GET lists the methods that serve queries instead of POST.
  • Docs: an EnableQueriesOverPost section on the endpoints page, rows in both options tables, and pointers from the POST and QUERY sections of the HTTP transport page.

Test plan

  • HttpPostMiddlewareTests: a single query, a variable batch, a request batch, and an operation batch are refused; a mutation and a subscription over POST still run; an interceptor that sets RequestFlags.AllowAll lets a query through.
  • GraphQLOverHttpSpecTests: status, Allow, and Accept-Query under Legacy, Draft20250508, and Draft20260903 for several Accept headers; the Allow list for each GET and QUERY configuration, including an empty header; a query refused over GET and HEAD while the option is false, and Allow: POST kept for a refused mutation.
  • PersistedOperationMiddlewareTests, HttpMultipartMiddlewareTests, HttpGetMiddlewareTests, and HttpQueryMiddlewareTests: the persisted POST and GET routes, multipart requests, and GET and QUERY still serving queries.
  • OperationKindTests in Fusion.AspNetCore.Tests: the gateway refuses a query and a query variable batch over POST and runs a mutation.
  • Ran those test classes on net10.0. Kestrel sends an empty Allow value as Allow: over HTTP/1.1, checked outside TestServer.

Copilot AI lite review requested due to automatic review settings October 29, 2026 10:21
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate labels Oct 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified, and the supplied evidence indicates the option is covered across affected transports, pipelines, response metadata, documentation, and tests.

No open issues 🎉

What changed in this PR

Adds GraphQLServerOptions.EnableQueriesOverPost, allowing applications to refuse GraphQL query operations over POST while continuing to support queries over GET or QUERY and mutations/subscriptions over POST.

Changes:

  • Added and documented the EnableQueriesOverPost server option.
  • Applied query restrictions across standard, multipart, persisted-operation, GET, QUERY, and Fusion pipelines.
  • Added refusal response handling for status codes, Allow, and Accept-Query headers.
  • Added comprehensive middleware, transport, persisted-operation, multipart, Fusion, and batching tests.
File Description
website/​content/​docs/​hotchocolate/​server/​options.md Documents the new option in the server options table.
website/​content/​docs/​hotchocolate/​server/​http-transport.md Documents refusing queries over POST and the relationship to QUERY requests.
website/​content/​docs/​hotchocolate/​server/​endpoints.md Documents configuration and endpoint behavior.
src/​HotChocolate/​Fusion/​test/​Fusion.AspNetCore.Tests/​OperationKindTests.cs Tests query refusal and mutation support through the Fusion gateway.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​PersistedOperationMiddlewareTests.cs Tests persisted query and mutation behavior over POST and GET.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​HttpQueryMiddlewareTests.cs Verifies QUERY requests continue to execute queries.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​HttpPostMiddlewareTests.cs Covers POST refusals, batching, mutations, subscriptions, and interceptor overrides.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​HttpMultipartMiddlewareTests.cs Tests query refusal for multipart requests.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​HttpGetMiddlewareTests.cs Verifies GET queries remain available.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​GraphQLOverHttpSpecTests.cs Covers status codes and Allow/Accept-Query headers across transport versions.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Utilities/​MiddlewareHelper.cs Adds POST flag filtering and refused-query response metadata handling.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Utilities/​HttpResultContextData.cs Defines response metadata keys for allowed methods and QUERY support.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​PersistedOperationMiddleware.cs Applies the option to persisted-operation POST and GET paths.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Options/​GraphQLServerOptions.cs Defines and clones EnableQueriesOverPost.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​HttpPostMiddlewareBase.cs Filters POST operation flags and marks refused single-query results.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​HttpGetMiddleware.cs Adds refused-query metadata for GET responses.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Formatters/​DefaultHttpResponseFormatter.cs Emits configured Allow and Accept-Query headers for refused operations.

Review effort: Lite

@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (74/74)

File Covered Changed Patch %
…/Formatters/DefaultHttpResponseFormatter.cs 17 17 100.0% 🟢
…/AspNetCore/src/AspNetCore.Pipeline/HttpGetMiddleware.cs 4 4 100.0% 🟢
…/AspNetCore/src/AspNetCore.Pipeline/HttpPostMiddlewareBase.cs 8 8 100.0% 🟢
…/src/AspNetCore.Pipeline/Options/GraphQLServerOptions.cs 2 2 100.0% 🟢
…/src/AspNetCore.Pipeline/PersistedOperationMiddleware.cs 12 12 100.0% 🟢
…/src/AspNetCore.Pipeline/Utilities/MiddlewareHelper.cs 31 31 100.0% 🟢

Project coverage: 59.3% (318668/537779 lines)

@glen-84
glen-84 merged commit dec5a6d into main Oct 29, 2026
159 checks passed
@glen-84
glen-84 deleted the gai/enable-queries-over-post-option branch October 29, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants