From 578a96489005b7f5347074c4aaf86a9d4a0fba5a Mon Sep 17 00:00:00 2001 From: Ciro Date: Thu, 17 Nov 2022 18:36:01 -0300 Subject: [PATCH] initial docs, still incomplete but is a lot --- examples/chat/assets/scripts.js | 1 + examples/helpers/graphiql.py | 6 +----- examples/upload_or_post.py | 19 ++++++++----------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/examples/chat/assets/scripts.js b/examples/chat/assets/scripts.js index cd5eabd..bc99060 100644 --- a/examples/chat/assets/scripts.js +++ b/examples/chat/assets/scripts.js @@ -143,6 +143,7 @@ function format_message(message, user){ message.name = 'You'; message_element.classList.add('chat-message-right'); }else{ + message.name = message.name || message.login; message_element.classList.add('chat-message-left'); } diff --git a/examples/helpers/graphiql.py b/examples/helpers/graphiql.py index 74aabcd..1104050 100644 --- a/examples/helpers/graphiql.py +++ b/examples/helpers/graphiql.py @@ -10,11 +10,7 @@ def graphiql_from(Query, Mutation=None): async def post(res, req): # we can pass whatever we want to context, query, headers or params, cookies etc - context_value = { - "query": req.get_queries(), - "headers": req.get_headers(), - "params": req.get_parameters(), - } + context_value = req.preserve() # get all incomming data and parses as json body = await res.get_json() diff --git a/examples/upload_or_post.py b/examples/upload_or_post.py index 12be60a..cbc4776 100644 --- a/examples/upload_or_post.py +++ b/examples/upload_or_post.py @@ -21,10 +21,8 @@ async def upload_chunks(res, req): # await all the data, returns received chunks if fail (most likely fail is aborted requests) data = await res.get_data() - print(f"Got {len(data)} chunks of data!") - for chunk in data: - print(f"Got chunk of data with length {len(chunk)}") - + print(f"Got chunks {len(data)} of data!") + # We respond when we are done res.cork_end("Thanks for the data!") @@ -32,11 +30,10 @@ async def upload_chunks(res, req): async def upload_json(res, req): print(f"Posted to {req.get_url()}") # await all the data and parses as json, returns None if fail - people = await res.get_json() - - if isinstance(people, list) and isinstance(people[0], dict): - print(f"First person is named: {people[0]['name']}") + info = await res.get_json() + print(info) + # We respond when we are done res.cork_end("Thanks for the data!") @@ -46,7 +43,7 @@ async def upload_text(res, req): # await all the data and decode as text, returns None if fail text = await res.get_text() # first parameter is the encoding (default utf-8) - print(f"Your text is ${text}") + print(f"Your text is {text}") # We respond when we are done res.cork_end("Thanks for the data!") @@ -59,7 +56,7 @@ async def upload_urlencoded(res, req): await res.get_form_urlencoded() ) # first parameter is the encoding (default utf-8) - print(f"Your form is ${form}") + print(f"Your form is {form}") # We respond when we are done res.cork_end("Thanks for the data!") @@ -76,7 +73,7 @@ async def upload_multiple(res, req): else: data = await res.get_text() - print(f"Your data is ${data}") + print(f"Your data is {data}") # We respond when we are done res.cork_end("Thanks for the data!")