Below is a graphql query that retrieves user details like id,username,city,pincode by passing a variable that matches with a cityname called 'osaka' :
query = """ {
userinfo (cityName: "osaka")
{
id
user_name
city
pincode
}
}"""
this query is being posted to an external graphql api using requests module of python
url = 'http://192.168.200.58:8010/api/userdetails/v1/users'
r = requests.post(url, query,headers=headers, auth=HTTPBasicAuth('api', 'api123'))
json_data = json.loads(r.text)
how to query this api by passing cityname dynamically , i tried the below code but that did not work
json = {'query': """ {
userinfo ($cityname: str)
{
id
user_name
city
pincode
}
}""",
"variables":{"cityName":"LA"}
url = 'http://192.168.200.58:8010/api/userdetails/v1/users'
r = requests.post(url, json=json,headers=headers, auth=HTTPBasicAuth('api', 'api123'))
json_data = json.loads(r.text)