File: httpx_async.rst

package info (click to toggle)
python-gql 3.6.0~b4-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,824 kB
  • sloc: python: 20,567; makefile: 52
file content (39 lines) | stat: -rw-r--r-- 997 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
.. _httpx_async_transport:

HTTPXAsyncTransport
===================

This transport uses the `httpx`_ library and allows you to send GraphQL queries using the HTTP protocol.

Reference: :class:`gql.transport.httpx.HTTPXAsyncTransport`

.. note::

    GraphQL subscriptions are not supported on the HTTP transport.
    For subscriptions you should use the :ref:`websockets transport <websockets_transport>`.

.. literalinclude:: ../code_examples/httpx_async.py

Authentication
--------------

There are multiple ways to authenticate depending on the server configuration.

1. Using HTTP Headers

.. code-block:: python

    transport = HTTPXAsyncTransport(
        url='https://SERVER_URL:SERVER_PORT/graphql',
        headers={'Authorization': 'token'}
    )

2. Using HTTP Cookies

You can manually set the cookies which will be sent with each connection:

.. code-block:: python

    transport = HTTPXAsyncTransport(url=url, cookies={"cookie1": "val1"})

.. _httpx: https://www.python-httpx.org