https://prefect.io logo
Title
f

Farooque Shaikh

07/18/2022, 3:37 PM
I am trying to run a graphql query in Python using the below code: params={ "date_obj":"2022-07-18T01:32:26.584864+00:00", "curr_obj":"2022-07-18T05:32:26.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

Kevin Kho

07/18/2022, 3:41 PM
I think you need to pass
variables
into
client.graphl
which takes in a dictionary
f

Farooque Shaikh

07/18/2022, 3:42 PM
is there any example i can refer to
k

Kevin Kho

07/18/2022, 3:49 PM
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

Farooque Shaikh

07/18/2022, 3:58 PM
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-18T01:32:26.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-18T01:32:26.584864+00:00" } print(client.graphql(query,variables=vars))
k

Kevin Kho

07/18/2022, 3:59 PM
I think that’s because you wrapped all of the id, name, start_time, end_time in quotes
f

Farooque Shaikh

07/18/2022, 4:02 PM
Got you, it worked now, thank you so much for your quick help.. Really Appreciate
👍 1