I’m trying to make a post request to a GraphQL API using Python3 and would like some parts of the query to be variables, without doing strange string manipulations with pasting.
A good solution was something like this:
import requests
body = """
query ($first: Int, $occurredAtMin: DateTime){
app(id: "abc123") {
events(
first: $first
occurredAtMin: $occurredAtMin
) {
edges {
node {
type
occurredAt
}
}
}
}
}
"""
variables = {"first": 10, "occuredAtMin": "2023-09-05T14:23:47.00Z"}
resp = requests.post(url = url, json = {"query": body, "variables": variables}, headers=headers)
resp.json()
This seems to works fine for almost all variables, but I can’t make it work with the DateTime
type (occuredAtMin
variable).
Is there some elegant way to solve this?
I could just paste it as a string and it would work, but I would like to solve it in some nicer way.