is there a query in graphql that allows you to start a station from a track?

As you say, you can search for the track and get the station factory that way. For example, this query:

query {
  search(query:"Let Me by Zayn", types:[SF], pagination: {limit: 1}) {
    items {
      ... on StationFactory {
        name
        id
      }
    }
  }
}

Returns this result:

{
  "data": {
    "search": {
      "items": [
        {
          "name": "Let Me",
          "id": "SF:21586:35686886"
        }
      ]
    }
  }
}

By including types:[SF] in the search parameters, results are limited to “station factories.” Station factories (see “Station and Station Factory” in the docs) can be used to start station playback (see info on setSource here).

A similar, but slightly different path, is to search for tracks (note that we are now specifying types:[TR] instead of types:[SF]):

query {
  search(query:"Let Me by Zayn", types:[TR], pagination: {limit: 1}) {
    items {
      ... on Track {
        name
        artist {
          name
        }
        stationFactory {
          id
        }
      }
    }
  }
}

Which returns:

{
  "data": {
    "search": {
      "items": [
        {
          "name": "Let Me",
          "artist": {
            "name": "ZAYN"
          },
          "stationFactory": {
            "id": "SF:21586:35686886"
          }
        }
      ]
    }
  }
}

There is one caveat/edge case to consider when using types:[TR]. Specifically, some tracks will not have a stationFactory ID. The vast majority of tracks will have stationFactory IDs so this shouldn’t be a major limiting factor, but it’s important to have a null check here.

Finally, if you know the track ID already, you can look up all the associated metadata for that track using the handy-dandy entity query. Here we are pulling out the station factory ID:

query {
  entity(id: "TR:35686886") {
    ... on Track {
      stationFactory {
        id
      }
    }
  }
}

Which returns:

{
  "data": {
    "entity": {
      "stationFactory": {
        "id": "SF:21586:35686886"
      }
    }
  }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top