Skip to content

Commit 2d20946

Browse files
magicmarkclaude
andcommitted
Add request extensions to docs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4532d14 commit 2d20946

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

docs/usage/extensions.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,41 @@
33
Extensions
44
----------
55

6+
Request extensions
7+
^^^^^^^^^^^^^^^^^^
8+
9+
The `GraphQL over HTTP spec <https://github.com/graphql/graphql-over-http>`_
10+
defines an optional :code:`extensions` field on requests. This is sent as a
11+
top-level key in the request payload alongside :code:`query`, :code:`variables`,
12+
and :code:`operationName`.
13+
14+
You can use this to pass protocol extensions such as
15+
`persisted queries <https://www.apollographql.com/docs/apollo-server/performance/apq/>`_:
16+
17+
.. code-block:: python
18+
19+
from gql import Client, GraphQLRequest
20+
from gql.transport.aiohttp import AIOHTTPTransport
21+
22+
transport = AIOHTTPTransport(url="https://example.com/graphql")
23+
24+
async with Client(transport=transport) as session:
25+
26+
request = GraphQLRequest(
27+
"query { viewer { name } }",
28+
extensions={
29+
"persistedQuery": {
30+
"version": 1,
31+
"sha256Hash": "abc123...",
32+
}
33+
},
34+
)
35+
36+
result = await session.execute(request)
37+
38+
Response extensions
39+
^^^^^^^^^^^^^^^^^^^
40+
641
When you execute (or subscribe) GraphQL requests, the server will send
742
responses which may have 3 fields:
843

0 commit comments

Comments
 (0)