File: phoenix_channel_async.py

package info (click to toggle)
python-gql 4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,900 kB
  • sloc: python: 21,677; makefile: 54
file content (30 lines) | stat: -rw-r--r-- 734 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
import asyncio

from gql import Client, gql
from gql.transport.phoenix_channel_websockets import PhoenixChannelWebsocketsTransport


async def main():

    transport = PhoenixChannelWebsocketsTransport(
        channel_name="YOUR_CHANNEL", url="wss://YOUR_URL/graphql"
    )

    # Using `async with` on the client will start a connection on the transport
    # and provide a `session` variable to execute queries on this connection
    async with Client(transport=transport) as session:

        # Execute single query
        query = gql(
            """
            query yourQuery {
                ...
            }
        """
        )

        result = await session.execute(query)
        print(result)


asyncio.run(main())