def update_session_access_token(self, access_token): self.websocket = WebsocketsTransport( url=self.url, init_payload={'token': access_token}) self.gql_client = Client(transport=self.websocket, # fetch_schema_from_transport=True, )
async def main(): transport = WebsocketsTransport( url='wss://countries.trevorblades.com/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=sample_transport, fetch_schema_from_transport=True, ) as session: # Execute single query query = gql(''' query getContinents { continents { code name } } ''') result = await session.execute(query) print(result) # Request subscription subscription = gql(''' subscription { somethingChanged { id } } ''') async for result in session.subscribe(subscription): print(result)
def __init__(self): self.url: str = 'wss://api.aidungeon.io/subscriptions' self.websocket = WebsocketsTransport(url=self.url) self.gql_client = Client(transport=self.websocket, # fetch_schema_from_transport=True, ) self.account_id: str = '' self.access_token: str = '' self.single_player_mode_id: str = 'scenario:458612'
def __init__(self): self.url: str = 'wss://api.aidungeon.io/subscriptions' self.websocket = WebsocketsTransport(url=self.url) self.gql_client = Client(transport=self.websocket, # fetch_schema_from_transport=True, ) self.account_id: str = '' self.access_token: str = '' self.single_player_mode_id: str = 'scenario:458612' self.scenario_id: str = '' # REVIEW: maybe call it setting_id ? self.character_name: str = '' self.story_pitch_template: str = '' self.story_pitch: str = '' self.adventure_id: str = '' self.public_id: str = '' self.quests: str = ''
async def main(): # Set up required api stuff via http transport = AIOHTTPTransport(url=API_URL) client = Client(transport=transport, fetch_schema_from_transport=False) async with client as session: logger.info("Checking for currenlty running session") result = await session.execute(get_sessions) logger.debug(f'<-- {pformat(result)}') prev_session_id = None if not result["sessions"] else result[ "sessions"][0]["sessionId"] if prev_session_id: logger.info( f'Found previous session with ID: {prev_session_id}, ending it' ) variables = {"sessionId": prev_session_id} result = await session.execute(end_session, variables) logger.debug(f"<-- {pformat(result)}") new_session_id = str(uuid.uuid4()) logger.info(f'Creating new session with ID: {new_session_id}') result = await session.execute( create_all_and_start_session, variable_values={"sessionId": new_session_id}) logger.debug(f'<-- {pformat(result)}') # Connect via websocket to handle real time mutations/subscriptions # NB API doesnt respond to messages sent via websocket. Maybe this is just normal? # Either way it's probably fine as errors should still be thrown transport = WebsocketsTransport(url=API_URL) client = Client(transport=transport, fetch_schema_from_transport=False) async with client as session: # await asyncio.gather( # handle_subscriptions(session), # handle_soldiers(session), # return_exceptions=False # ) asyncio.create_task(handle_entities(session)) await handle_subscriptions(session)
def init(): self.websocket = WebsocketsTransport( url=self.url, init_payload={'token': access_token}) self.gql_client = Client(transport=self.websocket)
def __init__(self, url: str): self.url = url self.options = { "transport": WebsocketsTransport(url=self.url), "fetch_schema_from_transport": True, }
from gql import gql, Client, WebsocketsTransport import os from dotenv import load_dotenv load_dotenv(verbose=True, override=True) SUBSCRIPTION_ADDRESS = os.getenv("SUBSCRIPTION_ADDRESS") TENANT_ID = os.getenv("TENANT_ID") TENANT_KEY = os.getenv("TENANT_KEY") transport = WebsocketsTransport( url=SUBSCRIPTION_ADDRESS, headers={ 'x-tenant-id': TENANT_ID, "x-tenant-key": TENANT_KEY }) client = Client( transport=transport, fetch_schema_from_transport=True, ) query = gql(''' subscription { signalAdded { id mac timestamp unit type