Hello everyone, I’m trying to see if it’s possible...
# ask-community
d
Hello everyone, I’m trying to see if it’s possible to query for flows runs with a specific parameter value. I’ve been able to query for runs where the parameter has a certain key using
_has_key
. I’ve tried using
_contains
with no luck, although I’m not sure if that’s the right one either, or if this is even possible. Thanks!
a
@Daniel Komisar it’s possible to query it this way: Query:
Copy code
query ($param_value: jsonb) {
  flow_run(
    where: {_and: [{flow_id: {_eq: "eb45ed0a-a76c-445b-b0b8-1fdc05c1f54c"}}, 
      {parameters: {_eq: $param_value}}]}
  ) {
    name
    state
    end_time
    start_time
    parameters
  }
}
Query variables is where you put the parameter values you search for:
Copy code
{
  "param_value": {
    "x": 1
  }
}
here: x is the parameter name and 1 is the parameter value. This allows us to search for flow runs that have been triggered with this value of parameter “x”. Here is an example output:
d
perfect thank you
I haven’t been able to get this to work. I think I may have not explained well enough though. Since the parameters are a dict I want to search for runs where the parameters dict has a key with a certain value. I don’t care about the other keys. So I don’t think I can use
_eq
my understanding is that this is matching against the entire parameters dict. What I was hoping to do is something like this:
Copy code
query {
    flow_run(where: { parameters: { _contains: { upload: True }}}) {
			state
    		state_message
    }
}
which would return any flows that had the parameters
upload
key set to
True
and anything else in any other keys.
a
in that case you would need to filter out the result in your Python code. You can use the Client as follows:
Copy code
from prefect import Client

client = Client()

query = """
query ($param_value: jsonb) {
  flow_run(
    where: {_and: [{flow_id: {_eq: "eb45ed0a-a76c-445b-b0b8-1fdc05c1f54c"}}, 
      {parameters: {_eq: $param_value}}]}
  ) {
    name
    state
    end_time
    start_time
    parameters
  }
}
"""
response = client.graphql(query, variables=dict(param_value=dict(x=1)))
print(response)
Then, the response object will give you a dictionary-like GraphQLResult object you can filter further in your Python code