File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ import asyncio
2
+
3
+ from gql import Client , gql
4
+ from gql .transport .phoenix_channel_websockets import PhoenixChannelWebsocketsTransport
5
+
6
+
7
+ async def main ():
8
+
9
+ transport = PhoenixChannelWebsocketsTransport (
10
+ channel_name = "YOUR_CHANNEL" , url = "wss://YOUR_URL/graphql"
11
+ )
12
+
13
+ # Using `async with` on the client will start a connection on the transport
14
+ # and provide a `session` variable to execute queries on this connection
15
+ async with Client (transport = transport ) as session :
16
+
17
+ # Execute single query
18
+ query = gql (
19
+ """
20
+ query yourQuery {
21
+ ...
22
+ }
23
+ """
24
+ )
25
+
26
+ result = await session .execute (query )
27
+ print (result )
28
+
29
+
30
+ asyncio .run (main ())
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ framework `channels`_.
10
10
Reference:
11
11
:class: `gql.transport.phoenix_channel_websockets.PhoenixChannelWebsocketsTransport `
12
12
13
+ .. literalinclude :: ../code_examples/phoenix_channel_async.py
14
+
13
15
.. _Absinthe : http://absinthe-graphql.org
14
16
.. _Phoenix : https://www.phoenixframework.org
15
17
.. _channels : https://hexdocs.pm/phoenix/Phoenix.Channel.html#content
You can’t perform that action at this time.
0 commit comments