Some fields (like 'merged_at', 'base', 'head') are absent in the search results for pull requests

Hi everyone,

We are using ‘/search/issues’ API v3 call to get a list of recently changed pull requests:
https://api.github.com/search/issues?q=repo:<user>/<repo>+is:pr+updated:%3E2020-07-11T23:57:00Z&page=1&sort=updated&order=asc

But unlike the ‘/repos///pulls’ API v3 calls the result of the ‘search’ call does not contain some fields, for example, “merged_at”, “head”, “base”.

With the ‘search’ call we tried to reduce the traffic to the Github server (we use it instead of getting all available requests with ‘/repos///pulls’). But it seems that we are unable to get all the required information about pull requests with the ‘search’ call.
Are there any options to get these fields in the ‘search’ calls? Or are there any other solutions to get the recently changed pull requests?

Thank you.

1 Like

@denis-bigbrassband-com: The GraphQL API also exposes a search field, where ISSUE is one of its supported SearchTypes.

Here’s an example query that searches for all pull requests in the github/linguist repository updated after a certain time (you can modify this example to your liking):

query {
  search(type: ISSUE, first: 10, query: "repo:github/linguist is:pr updated:>2020-07-11T23:57:00Z") {
    edges {
      node {
        ... on PullRequest {
          author {
            login
          }
          number
          mergedAt
          baseRefName
          headRefName
        }
      }
    }
  }
}
Result Set
{
  "data": {
    "search": {
      "edges": [
        {
          "node": {
            "author": {
              "login": "mortend"
            },
            "number": 4938,
            "mergedAt": null,
            "baseRefName": "master",
            "headRefName": "uno-color"
          }
        },
        {
          "node": {
            "author": {
              "login": "PieterO"
            },
            "number": 4937,
            "mergedAt": null,
            "baseRefName": "master",
            "headRefName": "add-velocity-template-language"
          }
        },
        {
          "node": {
            "author": {
              "login": "Alhadis"
            },
            "number": 4936,
            "mergedAt": null,
            "baseRefName": "master",
            "headRefName": "generic-extensions"
          }
        },
        {
          "node": {
            "author": {
              "login": "jdbender66"
            },
            "number": 4935,
            "mergedAt": null,
            "baseRefName": "master",
            "headRefName": "patch-1"
          }
        },
        {
          "node": {
            "author": {
              "login": "sheerun"
            },
            "number": 4934,
            "mergedAt": "2020-07-29T08:29:42Z",
            "baseRefName": "master",
            "headRefName": "bundler"
          }
        },
        {
          "node": {
            "author": {
              "login": "sheerun"
            },
            "number": 4933,
            "mergedAt": null,
            "baseRefName": "master",
            "headRefName": "carp"
          }
        },
        {
          "node": {
            "author": {
              "login": "sheerun"
            },
            "number": 4932,
            "mergedAt": null,
            "baseRefName": "master",
            "headRefName": "asl"
          }
        },
        {
          "node": {
            "author": {
              "login": "Alhadis"
            },
            "number": 4931,
            "mergedAt": "2020-07-28T09:26:30Z",
            "baseRefName": "master",
            "headRefName": "misc-fixes"
          }
        },
        {
          "node": {
            "author": {
              "login": "brnrdog"
            },
            "number": 4929,
            "mergedAt": null,
            "baseRefName": "master",
            "headRefName": "reason-bs-8.1"
          }
        },
        {
          "node": {
            "author": {
              "login": "sambacha"
            },
            "number": 4928,
            "mergedAt": null,
            "baseRefName": "master",
            "headRefName": "add-edi-dev0"
          }
        }
      ]
    }
  }
}

With GraphQL, you can specify the data you need and nothing more: this query only targets five fields per resulting pull request. This kind of configurability is what sets it apart from the REST API’s preconfigured responses.

Does this help with what you’re looking to accomplish?

1 Like

Hi @francisfuzz,

Thank you for the recommendations.
We currently don’t use GraphQL in our project. It seems that it is time to start to do this. Could you recommend any Java library to work with GraphQL API?

@denis-bigbrassband-com - Thanks for writing back! I don’t have any official recommendations for a specific Java library to work with our GraphQL API––I suggest opening a new topic in our Programming Help and Discussion category and raising that question there.

If it helps as an additional resource, I highly encourage you to check out this GitHub Developer page showcasing Octokit (our official libraries for interfacing with the GitHub API) as well as other third-party libraries.

Does that help?

@francisfuzz
Thank you. I experimenting with this a bit, and it seems this gives all the required information for us.
Marked as resolved. Thank you again.

1 Like