2

I would like to execute a query for issues in a specific repository using GitHub GraphQL. Here is what I have:

query MyQuery {
  search(query: "repo:spring-projects/spring-boot in:title fonts", type: ISSUE, first: 3) {
    edges {
      node {
        ... on Issue {
          number
          title
          repository {
            name
          }
        }
      }
    }
  }
}

My problem is that I would like to externalize the actual query, i.e. in:title fonts and still be able to search for issues only within a specific repo. I tried adding a variable and using it in the query string:

search(query: "repo:spring-projects/spring-boot in:title $query", ...

but it doesn't work.

I can manipulate the query string and replace the variable myself, but I would like to no have to do it.

In other words: how to I query for issues within a specific repository, making the filter part variable but the repository stays the same and is not part of the query? Something like (but this obviously doesn't work, the repo: "spring-projects/spring-boot" part is invalid):

query MyQuery($query: String!) {
  search(repo: "spring-projects/spring-boot", query: $query, type: ISSUE, first: 3) {
    edges {
      node {
        ... on Issue {
          number
          title
          repository {
            name
          }
        }
      }
    }
  }
}

and the $query variable could be set to in:title fonts at runtime.

Edit: I don't want to list issues by repository, this is easy, e.g.:

query Issues {
  repository(owner: "spring-projects", name: "spring-boot") {
    issues(last: 3) {
      edges {
        node {
          number
          title
        }
      }
    }
  }
}```
wujek
  • 10,112
  • 12
  • 52
  • 88
  • no mercy, graphql doesn't support string manipulations, do it youself ... other API construction - send feature request or build your own – xadm Feb 07 '21 at 14:44
  • @xadm Well, I don't really need to implement it using string manipulations, I actually don't want to. I would very much prefer to use GitHubs solution to this, I just don't know how. – wujek Feb 07 '21 at 15:18
  • *'I can manipulate the query string and replace the variable myself, but I would like to no have to do it.'* - you must do it, prepare and pass entire `query` variable – xadm Feb 07 '21 at 15:21
  • My experience tells me that such string manipulations in queries are error prone and in some cases, like SQL, a security issue. For example, depending on what the user defines for the filter, it might break the whole query, right? But maybe This is the Way. – wujek Feb 07 '21 at 16:39
  • right but minimal/limited risk ... whole variable must be a string, usually not directly passed into sql query ... it's theirs/THIS SPECIFIC API authors decision (n-th version) ... usually complex 'where' conditions are [more type checkable] tree-like structures - NO ANY/strict rules in general graphql specs for conditions/filtering/sorting/etc - IMPLEMENTATION AUTHORS are responsible for rules/safety/etc. – xadm Feb 07 '21 at 16:59

0 Answers0