Filtering on v4 (GraphQL) issue sub nodes

Hello,

I’m trying to use the V4 API to get a list of my assigned issues along with it’s labels and references.

After some time I got the query you can see below, which works exactly how I want.

There is however a problem: it includes a lot of empty nodes I am not interested at. For example, if I want to get all the CrossReferencedEvent that are issues I will get a lot of empty nodes on the timeline edges array because the other events: LabeledEvent, ReferencedEvent, AssignedEvent etc.

How can I filter out those so I only get the events I am interested at?

{
  search(query: "assignee:danielo515", type: ISSUE, last: 100) {
    edges {
      node {
        ... on Issue {
          number
          title
          state
          timeline(first: 10) {
            edges {
              node {
                ... on CrossReferencedEvent {
                   source{
                    ... on Issue {
                      title
                      number
                    }
                  }
                }
              }
            }
          }
          labels(last: 10) {
            nodes {
              name
              color
            }
          }
          repository {
            name
          }
        }
      }
    }
  }
}

Thanks in advance 

As a side note, let me say that it was very hard to figure out where each possible interesting item was located. GraphQL documentatio is very confusing and even knowing what you are looking for is very hard to understand where it is. It took me a long time to found that CrossReferencedEvent was under timeline

Hey @danielo515, did you find a solution?

Hello @krasimir , no, not yet.

Do you have any idea ?

Nope. I didn’t.

Hi @danielo515,

Thanks for being here! Ideally, there would be a way to request only specific types of timeline items by having a filter on the timeline field. That doesn’t exist currently, we are opening an issue internally to explore that and will post any updates on this thread.

Best,

Thank you @andreagriffiths11 !

I’ll be looking for that

Regards

1 Like

Hi @danielo515,

It turns out there is something that might help you out a bit.  This is partially supported via the new timelineItems connection on the PullRequest or Issue objects, using the itemTypes argument. That connection is currently behind a preview.

So, give something like this a try (but again, remember you’ll need to pass in the preview media type via the Accept header):

{
  search(query: "assignee:danielo515", type: ISSUE, last: 100) {
    edges {
      node {
        ... on Issue {
          number
          title
          state
          timelineItems(first: 10, itemTypes: [CROSS_REFERENCED_EVENT]) {
            edges {
              node {
                ... on CrossReferencedEvent {
                  source {
                    ... on Issue {
                      title
                      number
                    }
                  }
                }
              }
            }
          }
          labels(last: 10) {
            nodes {
              name
              color
            }
          }
          repository {
            name
          }
        }
      }
    }
  }
}

This will allow you to get back only cross referenced events, but they will be for both issue and pull request sources. So, you’ll still see some empty objects for pull request sources.

Hope this helps.

Best,
Ivan

1 Like