Skip to content

regex sub-selection #2

@konsumer

Description

@konsumer

I often have to do a bunch of regexes to get the text I actually need. If I could put it in my query, that'd be even better.

Here is an example:

I have a lil query that grabs some data from the google play-store. I do my pre-processing of input via js template strings in the query, and I'd like to do my post-processing in the query itself:

const details = (id, country='US', lang='en') => graphql(schema, `{
  page(url: "https://play.google.com/store/apps/details?id=${id}&hl=${lang}_${country}"){
    title: text(selector: "[itemprop='name']")
    icon: attr(selector: "[itemprop='image']", name: "src")
    developerName: text(selector: "a[href^='/store/apps/dev']")
    developerUrl: attr(selector: "a[href^='/store/apps/dev']", name: "href")
    developerId: attr(selector: "a[href^='/store/apps/dev']", name: "href", search="/store/apps/dev?id=(.+)")
  }
}`)

In this example, I am pulling developerId from the same place I get developerUrl, extracting the id from the regex search. I'm not quite sure how to handle multiple matches, but it would be pretty useful, even if it just returned the 1st match:

{
  "data": {
    "page": {
      "title": "Hello Neighbor",
      "icon": "https://lh3.googleusercontent.com/r1wx-kmI9I_zxv8UIF_0_YvmhoLOx25mjT23GCO4bse6H-pgqfjZ5Tvz3HRJ0i2HdEoQ=s100",
      "developerName": "tinyBuild",
      "developerUrl": "/store/apps/dev?id=4988311280735374056",
      "developerId": "4988311280735374056"
    }
  }
}

Is there interest in this? Should I make a PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions