Overview
In this simplified example I have a function that returns a string. The string is ultimately going to be used for a GraphQL mutation.
def updateHasura (description,url,user_id):
query = f"""
mutation {{
insert_post(objects: {{description: {description}, url: {url}, user_id: {user_id}}}) {{
affected_rows
}}
}}
"""
print(query)
When I call the function I need to wrap the double quotation marks with single ones in order for the function to return the desired string.
updateHasura('"test"','"test"','"1"')
Gives me the desired output:
mutation {
insert_post(objects: {description: "test", url: "test", user_id: "1"}) {
affected_rows
}
}
Question
I don't want to double wrap the text when calling the function i.e. '"test"'
.
The nested curly brackets {{}}
in the f-string are also less than ideal.
How can I simplify this function and still return the desired output? I'm happy to use another approach other than the f-string if it simplifies this.
args = [arg.join('""') for arg in ['test', 'test', '1']] updateHasura(*args)
but technically you still didn't get rid of using double quotation.