z

    Zach

    2 years ago
    New to GraphQL and trying to use the Prefect Interactive API; this is my query but I am getting an error, can anyone help? I have a feeling there is something super simple I am missing: query:
    query {
      flow_run_state {
        flow_run {
          id,
          parameters,
          created,
          flow(where:{name:"my-flow-name"}) {
            name,
            id
          },
        }
      }
    }
    Error:
    {
      "graphQLErrors": [
        {
          "message": "Unknown argument \"where\" on field \"flow\" of type \"flow_run\".",
          "extensions": {
            "code": "GRAPHQL_VALIDATION_FAILED"
          }
        }
      ],
      "networkError": null,
      "message": "GraphQL error: Unknown argument \"where\" on field \"flow\" of type \"flow_run\"."
    }
    nicholas

    nicholas

    2 years ago
    Hi @Zach - I think that error is because you're applying the
    where
    clause on a nested field. Something like this should work instead:
    query {
      flow_run_state(where: {flow_run: {flow: {name: {_eq: "my-flow-name"}}}}) {
        flow_run {
          id,
          parameters,
          created,
          flow {
            name,
            id
          },
        }
      }
    }
    z

    Zach

    2 years ago
    ahhh so all your
    where
    clauses need to be at the top of the query?
    nicholas

    nicholas

    2 years ago
    It depends on how the resolver is written but that's often the case!
    z

    Zach

    2 years ago
    @nicholas One more question, is there anything I can do if my query keeps timing out?
    I just added two more
    where
    clauses and now it times out every time
    nicholas

    nicholas

    2 years ago
    Yes definitely, can you describe what you're trying to get? Maybe I can help you craft a performant query for it
    z

    Zach

    2 years ago
    I am trying to look at how long a certain task took across all flows that finished successfully. This is what I have so far:
    query {
      flow_run_state(where: 
        {
          state: {_eq: "Success"},
          created: {_gt: "2020-09-11T23:09:48.215241+00:00"}
          flow_run: {
            task_runs: {task: {name: {_eq: "task-name"}}}
            flow: {name: {_eq: "flow-name"}}
          }
        }
      ) {
        state,
        flow_run {
          id,
          created,
          flow {
            name,
          },
          task_runs {
            task {
              name
            }
            start_time,
            end_time
          }
        }
      }
    }
    I added the date filter to try to speed it up so that it was only looking at the past week or so
    nicholas

    nicholas

    2 years ago
    Ah ok, I can definitely see why that's timing out. For you knowledge, whenever you have nested fields, like:
    flow_run { flow { id } }
    Hasura creates a
    JOIN
    between the two tables. Sometimes this is performant and expected, but other times it's not, due to the size of the tables and/or the shape of the
    ORDER_BY
    and
    WHERE
    clauses it generates.
    As for the query itself, let me test a few things to see how best to do that
    Oh also, that
    JOIN
    includes nested fields in the
    where
    clause
    Can you try something like this?
    query TaskRunDuration {
      flow_run(where: { flow_id: {_eq: "your_flow_id"}, state: {_eq: "Success"} }) {
        id
        name
        
        task_runs(where: {task_id: {_eq: "your_task_id"}}) {
          start_time
          end_time
          id
        }
      }
    }
    z

    Zach

    2 years ago
    That worked! Thank you!
    nicholas

    nicholas

    2 years ago
    Fantastic! 👍