Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 2

GitHub API v4 search query strange behavior

Hi! I just wanted to check how your search is working, so I created a basic search query:

 

query { 
  search(first: 10, query:"juffalow", type:ISSUE) {
    edges {
      node {
        __typename
        ...on User {
          id
          name
        }
        ...on Issue {
          id
          title
        }
      }
    }
  }
}

First "issue" is with type argument. In the docs, there is "The types of search items to search within.". I would expect it takes an array of types, but it takes just one type.

Second "issue" is with the returned data. If I search for type "ISSUE" I would expect, it will return just issues. But it is returning also other types. Response I get:

 

{
  "data": {
    "search": {
      "edges": [
        {
          "node": {
            "__typename": "Issue",
            "id": "MDU6SXNzdWU1MDMzMzA2MDA=",
            "title": "Add tests"
          }
        },
        {
          "node": {
            "__typename": "Issue",
            "id": "MDU6SXNzdWUzOTQ4NzQ0MzQ=",
            "title": "REF: Write good git commit message"
          }
        },
        {
          "node": {
            "__typename": "Issue",
            "id": "MDU6SXNzdWUzOTA1NTUyMjU=",
            "title": "Write a good commit message."
          }
        },
        {
          "node": {
            "__typename": "PullRequest"
          }
        },
        {
          "node": {
            "__typename": "PullRequest"
          }
        },
        {
          "node": {
            "__typename": "Issue",
            "id": "MDU6SXNzdWU1MTc1OTY3ODE=",
            "title": "Consider using react webpack approach"
          }
        },
        {
          "node": {
            "__typename": "PullRequest"
          }
        },
        {
          "node": {
            "__typename": "Issue",
            "id": "MDU6SXNzdWUyODU2NjU2OTE=",
            "title": "Error: Native component for \"PhotoViewAndroid\" does not exist"
          }
        },
        {
          "node": {
            "__typename": "PullRequest"
          }
        },
        {
          "node": {
            "__typename": "PullRequest"
          }
        }
      ]
    }
  }
}

Am I doing something wrong, or I misunderstand someting?

1 Reply
Community Manager
Message 2 of 2

Re: GitHub API v4 search query strange behavior

The GitHub search API returns both issues and pull requests when the search type is `ISSUE`. This is the expected behavior. If you want to only get one or the other, you can include `is:issue` or `is:pr` in the query text.

 

I hope that helps!