I am trying to run a graphql query in Python using...
# prefect-community
f
I am trying to run a graphql query in Python using the below code: params={ "date_obj":"2022-07-18T013226.584864+00:00", "curr_obj":"2022-07-18T053226.584864+00:00", } query=client.graphql( { 'query($date_obj: timestamptz=': { 'flow_run(where: {start_time: {_gte: $date_obj}})': { 'flow_id' } } however the parameter value for date_obj is not getting passed. Can someone please help on this
k
I think you need to pass
variables
into
client.graphl
which takes in a dictionary
f
is there any example i can refer to
k
Copy code
from prefect.client import Client 

client = Client()

query = """
query flowRun ($id: uuid){
  flow_run(where: {id: {_eq: $id}}) {
    id
  }
}
"""

vars = {
    "id": "7928d73a-a606-430e-a8ec-8194394fe5b8"
}


print(client.graphql(query, variables=vars))
f
It errored out with below message GRAPHQL_PARSE_FAILED: Syntax Error: Unexpected single quote character ('), did you mean to use a double quote (")? The passed variables were: {"date_obj": "2022-07-18T013226.584864+00:00"}
this is my code query = """ query flowRun ($date_obj: timestamptz) { flow_run(where: {start_time: {_gte: $date_obj}}) { 'flow_id', 'id', 'name', 'start_time', 'end_time', 'state', 'state_message', 'state_result', 'state_start_time', 'state_timestamp', 'tenant_id', 'times_resurrected', 'updated', 'version' } } """ vars = { "date_obj":"2022-07-18T013226.584864+00:00" } print(client.graphql(query,variables=vars))
k
I think that’s because you wrapped all of the id, name, start_time, end_time in quotes
f
Got you, it worked now, thank you so much for your quick help.. Really Appreciate
👍 1