https://prefect.io logo
b

Brad

05/05/2020, 2:14 AM
Hey team - is there a way to find out via the graphql api about which upstream task is linked to a downstream task run ? Specifically I’m interested in the input parameters to an upstream task
j

Jeremiah

05/05/2020, 3:48 AM
Hey @Brad - that’s a great question. We have convenience relationships for upstream / downstream tasks. For example, this query will get one (randomly selected) task run, as well as three of its upstream tasks:
Copy code
query {
  task_run(limit: 1) {
    task {
      upstream_edges(limit: 3) {
        upstream_task{
          id
          name
        }
      }
    }
  }
}
From any task, you can query its
upstream_edges
or
downstream_edges
and, for each edge, the corresponding
upstream_task
or
downstream_task
.
However, note this is from task-to-task, so once you have the upstream task ids, you’ll need to query for the corresponding task runs. However, I’m going to open an issue for us to support upstream/downstream relationships on task runs themselves
b

Brad

05/05/2020, 3:56 AM
Yeah okay I think this is where I was getting stuck - this will be the tasks themselves but not the task-runs right?
j

Jeremiah

05/05/2020, 3:58 AM
Yes, but once you have the tasks you can continue linking to their task runs, and filter by the common flow run id. For example, say your flow run id was XYZ:
Copy code
query {
  task_run(limit: 1, where: {flow_run_id: {_eq: XYZ}} ) {
    task {
      upstream_edges(limit: 3) {
        upstream_task{
          task_runs(where: {flow_run_id: {_eq: XYZ}}) {
            state
            id
          }
        }
      }
    }
  }
}
basically you’re stepping from: • task run in a given flow run • to task • to upstream edges • to upstream tasks • to their task runs in the same flow run
b

Brad

05/05/2020, 4:00 AM
ah yep - let me give that a go. Thanks @Jeremiah!
j

Jeremiah

05/05/2020, 4:00 AM
👌 it feels a little wordy but I think it’s the correct way to traverse the object hierarchy
Potentially we could introduce the shortcut I mentioned above but we’ll just be doing this for you behind the scenes
b

Brad

05/05/2020, 4:02 AM
yep, perfect - I will report back
j

Jeremiah

05/05/2020, 4:02 AM
awesome - and heads up I just edited that GQL by memory so i might have made a mistake with a missing plural or something, my apologies if so
👏 1
b

Brad

05/05/2020, 4:20 AM
Time to be more difficult. I also have a couple of layers of maps in between