Skip to content

Add extensions support to GraphQLRequest#591

Merged
leszekhanusz merged 12 commits intographql-python:masterfrom
magicmark:add-request-extensions
Apr 24, 2026
Merged

Add extensions support to GraphQLRequest#591
leszekhanusz merged 12 commits intographql-python:masterfrom
magicmark:add-request-extensions

Conversation

@magicmark
Copy link
Copy Markdown
Contributor

@magicmark magicmark commented Apr 23, 2026

Summary

Adds an optional extensions parameter to GraphQLRequest, as defined in the GraphQL over HTTP spec. When set, it is included as a top-level key in the request payload alongside query, variables, and operationName.

No transport changes needed — all transports already serialize request.payload.

request = GraphQLRequest(
    "query { viewer { name } }",
    extensions={"persistedQuery": {"version": 1, "sha256Hash": "abc123"}},
)
result = await session.execute(request)

Closes #590

Test plan

  • Unit tests for extensions in payload, copy, override, and serialize_variable_values
  • Integration tests for execute, subscribe, and batch across aiohttp, httpx, requests, and websockets

Support the `extensions` field on GraphQL requests, as defined in the
GraphQL over HTTP spec. This allows passing protocol extensions (e.g.
persisted query IDs) as a top-level key in the request payload.

Closes graphql-python#590

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7fb869a) to head (562a4c2).
⚠️ Report is 59 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##            master      #591    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           38        40     +2     
  Lines         2908      3321   +413     
==========================================
+ Hits          2908      3321   +413     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

magicmark and others added 11 commits April 23, 2026 16:21
Verify that extensions set on GraphQLRequest are sent in the HTTP
request body for aiohttp, httpx, and requests transports.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover extensions across all transports and operation types:
- aiohttp subscribe (HTTP + websocket)
- aiohttp, httpx, and requests execute_batch

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Merge 6 unit tests into one test_graphql_request_extensions
- Merge aiohttp execute + subscribe into one test
- Drop redundant httpx sync batch test (same code path as async)
- Tighten assertions and remove unnecessary comments
- Parse WS logged message as JSON instead of fragile string matching

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@magicmark magicmark marked this pull request as ready for review April 23, 2026 22:03
@magicmark magicmark marked this pull request as draft April 23, 2026 22:07
@magicmark magicmark marked this pull request as ready for review April 24, 2026 04:44
@magicmark
Copy link
Copy Markdown
Contributor Author

@leszekhanusz what do you think about this approach vs a new argument to session.execute (and friends), or even extra_args?

(extra_args seems to be something intended to be passed directly to the transport though, so that's probably not a good fit)

@leszekhanusz
Copy link
Copy Markdown
Collaborator

Looks good to me! Much better than having to add an extensions attribute to ALL the execute and subscribe methods.

@leszekhanusz leszekhanusz merged commit 76c02b6 into graphql-python:master Apr 24, 2026
16 checks passed
@leszekhanusz
Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support extensions on requests

2 participants