File: subscriptions.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 (29 lines) | stat: -rw-r--r-- 708 bytes parent folder | download
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
Subscriptions
=============

Using the :ref:`websockets transport <websockets_transport>`, it is possible to execute GraphQL subscriptions:

.. code-block:: python

    from gql import gql, Client
    from gql.transport.websockets import WebsocketsTransport

    transport = WebsocketsTransport(url='wss://your_server/graphql')

    client = Client(
        transport=transport,
        fetch_schema_from_transport=True,
    )

    query = gql('''
        subscription yourSubscription {
            ...
        }
    ''')

    for result in client.subscribe(query):
        print (result)

.. note::

    The websockets transport can also execute queries or mutations, it is not restricted to subscriptions