Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/code_examples/phoenix_channel_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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())
2 changes: 2 additions & 0 deletions docs/transports/phoenix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ framework `channels`_.
Reference:
:class:`gql.transport.phoenix_channel_websockets.PhoenixChannelWebsocketsTransport`

.. literalinclude:: ../code_examples/phoenix_channel_async.py

.. _Absinthe: http://absinthe-graphql.org
.. _Phoenix: https://www.phoenixframework.org
.. _channels: https://hexdocs.pm/phoenix/Phoenix.Channel.html#content