Skip to content

Latest commit

 

History

History
112 lines (94 loc) · 2.77 KB

README.md

File metadata and controls

112 lines (94 loc) · 2.77 KB

Spotify Web API GraphQL

A proof of concept to create a GraphQL compatible proxy to talk with the Spotify Web API. It is based on @cobbweb's GraphQL parser.

Usage

Install

$ npm install 

Example

Suppose we would like to fetch some information from the Web API, defined by the following GraphQL query:

album(5CHfJNBnVafJEyYNiavoUi) {
  artists.first(1) {
    id,
    name
  },
  name,
  tracks.first(1) { id }
}

This will retrieve the album with id 5CHfJNBnVafJEyYNiavoUi using the Get an Album endpoint and filter the returned fields to match the query.

{
  "artists": [
    {
      "id": "6J6yx1t3nwIDyPXk5xa7O8",
      "name": "Vetusta Morla"
    }
  ],
  "name": "La Deriva",
  "tracks": [
    {
      "id": "1spx7pPpe3AGG2gIrsMbVm"
    }
  ]
}

There is basic support for queries that result in several requests. For instance, take this query:

artist(0OdUWJ0sBjDrqHygGUXeCF) {
  name,
  followers { total },
  toptracks.first(5) {
    id,
    name,
    popularity
  }
}

Fetching the data involves a request to the endpoints Get an Artist and Get Artist's Top Tracks. The adaptor will take care of it and will return this object:

{
  "name": "Band of Horses",
  "followers": {
    "total": 347707
  },
  "toptracks": [
    {
      "id": "4o0NjemqhmsYLIMwlcosvW",
      "name": "The Funeral",
      "popularity": 74
    },
    {
      "id": "3LeNQIGi0zwmQm8WShZB95",
      "name": "No One's Gonna Love You",
      "popularity": 70
    },
    {
      "id": "5MYfpFJYm8WNFGssR6H2Oz",
      "name": "No One's Gonna Love You - Live from Spotify Sweden",
      "popularity": 69
    },
    {
      "id": "5qWgGPylB0Al9IVq2HKTHE",
      "name": "Is There A Ghost",
      "popularity": 61
    },
    {
      "id": "3MNTXYdBLLeBJjbihvTjOJ",
      "name": "The General Specific",
      "popularity": 58
    }
  ]
}

Demo

After cloning, install deps with npm install. You can see a demo running npm run demo which executes the example queries from the examples folder and dumps the parsed object to the console.

You can re-build the parser by running npm run build

TODO

  • Support all endpoints from the Web API
  • Issue several requests to fetch missing fields. This is partially supported, but should cover cases like:
    • hydrating simple objects with full objects
    • using multi-get to resolve multiple requests for full tracks, full albums or full artists
  • Write tests
  • Implement an example using Relay