The query we are using contains one parameter: the username. In order to make it more customizable, GraphQL allows us to use variables. First, we need to change the way we format the query slightly by adding the parameter definition:
query($login: String!) {
The parameter is called $name, is of the String type, and is mandatory (hence the final exclamation mark !). This declared parameter can then be used in the query, like so:
User(login: $login) {
So, the final query looks as follows:
query = """
query($login: String!) {
User(login: $login) {
login
}
}
"""
However, we now have to feed the parameter into the query in the API call. This is done using the variables parameter. It consists of a dictionary whose keys are the parameter names:
data = {
"query": query,
"variables": {"login": "me"},
}
After doing this, we can post this query once more using the same requests.post code we used...