Variable substitution in search query string

schema-request

#1

I want to define a search query like the following:

search(first: 50, type:ISSUE, query: "is:closed base:master is:pr merged:\"$lastReleaseDate .. $now\"")

But it appears the variable substitution isn’t possible within a search string, and the only way I can get this to work is to modify the string outside of the query, and then pass in the entire search string, a la…

search(first: 50, type:ISSUE, query: $query)

Is that really the only option?


#2

Hi @jamesdh,

Is that really the only option?

Yes, I believe so with a search query. Unlike other parts of the schema, search is actually using a different query language (inside the query language) that’s outlined here. As a result, that means that the query string would have to be built outside of the GraphQL query and then passed in the way that you’re currently doing it.

One thing that we could do is add a first class pull request schema in GraphQL that would look something like this:

query($mergedBefore:DateTime, $mergedAfter:DateTime) {
  repository(owner:$owner,name:$name) {
    pullRequests(first:50, states:[CLOSED], mergedAfter:$mergedAfter, mergedBefore:$mergedBefore) {
      nodes {
        title
      }
    }
  }
}

If this would be valuable, we can make this a schema request and prioritize it accordingly.


#3

We ended up manually building the search string as you suggested. It’s not exactly an ideal DRY solution, but it works.

Preferably we’d be able to do everything via the GraphQL API but yea, we have to resort to the REST API for a number of things. Anything that can bring it closer to equilibrium with the REST API is greatly appreciated.


#4

:+1: definitely. I’ve marked this as a schema request and added it to our internal issue tracker to add in the merge ranges as arguments onto the issues connection. We’ll update you here when we have some more to share.