Code Monkey home page Code Monkey logo

spotify-graphql's Introduction

Spotify GraphQL npm version https://david-dm.org/wittydeveloper/spotify-graphql TypeScript

GraphQL schema for Spotify Web API — TypeScript / Node.js (v6)


Try with the interactive console !

See spotify-graphql-examples for more examples


import SpotifyGraphQLClient from '../src/spotify-graphql';
import config from './config';

SpotifyGraphQLClient(config).query(`
  {
    track(id: "3W2ZcrRsInZbjWylOi6KhZ") {
      name
      artists {
        name
      }
    }
  }
`).then(result => {
  console.log(JSON.stringify(result));
});

// Print : 
// {
//   "data": {
//     "track": {
//       "name": "You & Me - Flume Remix",
//       "artists": [
//         {
//           "name": "Disclosure"
//         },
//         {
//           "name": "Eliza Doolittle"
//         },
//         {
//           "name": "Flume"
//         }
//       ]
//     }
//   }
// }

Queries

Albums

  • Get an Album ✅
  • Get Several Albums ✅
  • Get an Album's Tracks ✅

Artists

  • Get an Artist ✅
  • Get Several Artists ✅
  • Get an Artist's Albums ✅
  • Get an Artist's Top Tracks ✅
  • Get an Artist's Related Artists ✅

Tracks

  • Get a Track ✅
  • Get Several Tracks ✅
  • Get Audio Features for a Track ✅
  • Get Audio Features for Several Tracks ✅
  • Get Audio Analysis for a Track ❌

Search

  • Search for an Item ✅

Playlists

  • Get a List of a User's Playlists ✅
  • Get a List of Current User's Playlists ✅
  • Get a Playlist ✅
  • Get a Playlist's Tracks ✅

Create a Playlist

  • Add Tracks to a Playlist ❌
  • Remove Tracks from a Playlist ❌
  • Reorder or replace a Playlist's Tracks ❌
  • Change a Playlist's Details ❌

User Profiles

  • Get a User's Profile ✅
  • Get Current User's Profile ✅

User Library

  • Get Current User's Saved Tracks ✅
  • Check Current User's Saved Tracks ❌
  • Save Tracks for Current User ❌
  • Remove Tracks for Current User ❌
  • Get Current User's Saved Albums ✅ ❌
  • Check Current User's Saved Albums ❌
  • Save Albums for Current User ❌
  • Remove Albums for Current User ❌

Personalization

  • Get User's Top Artists and Tracks ✅

Browse

  • Get a List of New Releases ❌
  • Get a List of Featured Playlists ❌
  • Get a List of Browse Categories ❌
  • Get a Single Browse Category ❌
  • Get a Category's playlists ❌
  • Get Recommendations Based on Seeds ❌
  • Get Available Genre Seeds ❌

Follow

  • Get Followed Artists ❌
  • Check if Current User Follows Artists or Users ❌
  • Follow Artists or Users ❌
  • Unfollow Artists or Users ❌
  • Check if Users Follow a Playlist ❌
  • Follow a Playlist ❌
  • Unfollow a Playlist ❌

Player

  • Get the Current User's Recently Played Tracks ✅
  • Get Information About The User's Current Playback ✅
  • Transfer a User's Playback ❌
  • Get a User's Available Devices ❌
  • Get the User's Currently Playing Track ❌
  • Start/Resume a User's Playback ❌
  • Pause a User's Playback ❌
  • Skip User's Playback To Next Track ❌
  • Skip User's Playback To Previous Track ❌
  • Seek To Position In Currently Playing Track ❌
  • Set Repeat Mode On User's Playback ❌
  • Set Volume For User's Playback ❌
  • Toggle Shuffle For User's Playback ❌

spotify-graphql's People

Contributors

charlypoly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

spotify-graphql's Issues

Document that the `spechiness` field is useless for music

The docs for speechiness state that

Values below 0.33 most likely represent music and other non-speech-like tracks.

The speechiness of Bohemian Rhapsody - 2011 Mix is 0.0536. That of Penny, a track with no vocals whatsoever, is 0.0478. That makes the field useless for separating tracks with vocals from tracks without (useful for example in creating "focus" playlists).

Full artists from tracks

I'm loading tracks and for their artists, I'd like to show images and other full artist properties, including related artists. However, tracks only come with simplified artists. I'm now thinking if it's easier to do the joins or contribute.

I assume the challenge is to register when the user is asking for full properties and then do extra requests. I glanced at the resolvers and it looks like you're already doing something similar for tracks. I tried the following query in your new interactive console (👍):

{
  track(name: "Little Bit of This") {
    name
    album {
      name
      label  // null
      popularity  // null
      release_date  // null 
    }
  }
}

I get autocomplete for the full object properties. But in the response everything that isn't in simplified albums is null. I'm not sure why, and I couldn't find where variable.full is set.

Can you tell me what needed to be done in order to access full artists from tracks?

Spotify API change: userId is no longer used in playlist query

The playlist GraphQL query currently has a required userId parameter: https://github.com/wittydeveloper/spotify-graphql/blob/f3d3b119ba5c93487b7dd223172eb2cb2ce4c3df/lib/schema.ts#L194

There was a change to the Spotify API which means this parameter is no longer used:

https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/

On the 11th September 2018 we will roll out a change across all our APIs to simplify the URIs used to represent playlist objects. Instead of a long URI such as spotify:user:spotify:playlist:37i9dQZF1DZ06evO3OC4Te, you will now get the more succinct but still unique spotify:playlist:37i9dQZF1DZ06evO3OC4Te.

In tandem with this change, we are also releasing a set of simplified URLs for our Playlist Web API endpoints. The usage, functionality and response objects are identical, but the URLs are more concise and follow the new URI structure more closely.

You can see the full list of URLs in the table below:

Endpoint Usage
/v1/playlists/{playlist_id}/tracks Get/Add/Remove/Reorder/Replace a playlist’s tracks (depending on HTTP method)
/v1/playlists/{playlist_id} Retrieve or update a playlist’s details (depending on HTTP method)
/v1/me/playlists Create a Playlist (POST only)
/v1/playlists/{playlist_id}/images Get/Upload a Playlist Cover Image (depending on HTTP method)

spotify-web-api-node's v4.0.0 update accounts for these changes:

Modified functions that operate on playlists to drop the user id parameter. This is a breaking change. PR

Cannot find resolvers

Hi @wittydeveloper,

I'm trying to import spotify-graphql in a Typescript project, but I get the errors below during compilation. The import seems to come from lib/resolvers.ts and not dist/lib/resolvers.js. However, the resolvers folder is only in dist/lib, and not in just lib.

ERROR in [at-loader] ./node_modules/spotify-graphql/lib/resolvers.ts:1:32 
    TS2307: Cannot find module './resolvers/album'.

ERROR in [at-loader] ./node_modules/spotify-graphql/lib/resolvers.ts:2:33 
    TS2307: Cannot find module './resolvers/artist'.

ERROR in [at-loader] ./node_modules/spotify-graphql/lib/resolvers.ts:3:33 
    TS2307: Cannot find module './resolvers/player'.

...

pass webApiError ResponseHeader

Hello!

when hitting the rate limit, the web api responds with error code 429 and holds the Retry-After header with the amount of seconds to wait.
it would be great to get the headers (or at least that one) passed along. is this at all possible?

cheers,
Alex

Get Followed Artists

In your README you state that you don't support "get followed artists"
But I looked through your schema and it seems like this does the same:

me {
  artists {
    name
  }
}

Is that correct?

fix TS import

import SpotifyGraphQLClient from 'spotify-graphql'

is currently broken when using lib as NPM package..

add a CONTRIBUTE.md

for people that want to develop basic improvements on their own (schema improvements, etc)

Error handling

There is some error handling issues.

When a exception is raised in resolvers, the error do not bubble to query().then() callbacks..
This make debugging hard when Spotify returns 404 or 401..

update `graphql-tools` deps to `0.8.3`

This will remove the following warning at compilation

[...]/spotify-graphql/node_modules/graphql-tools/dist/autopublish.d.ts(3,24): error TS2307: Cannot find module 'graphql-subscriptions'.

playlist tracks iterator not iterating

hello!

based on the https://github.com/wittydeveloper/spotify-fetch-my-playlists I am trying to fetch a particular playlist.

const config = {
    accessToken: "<<TOKEN>>"
}

SpotifyGraphQLClient(config).query(`
{
    playlist(userId: "1128723762", id: "2YARXniaJywrRZbbQeSoAi") {
        id
        name
        tracks {
            track {
                id
                name
                artists {
                    id,
                    name
                }
                album {
                    id,
                    name
                }
            }
        }
    }
}
`).then(executionResult => {
        if (executionResult.errors) {
            console.log('error');
            console.error(JSON.stringify(executionResult.errors));
        } else {
            console.log('success');
            console.log(JSON.stringify(executionResult.data, null, 2));
            console.log("number of tracks:", executionResult.data["playlist"].tracks.length);
        }
    })

the number of tracks returned is 50. it should be 1133.
when debugging, i see that the initial response contains the 50 elements, a next url is also available, the offset iterator's offset is also incremented, only does the iterator not seem to be used afterwards.

what am i doing wrong?

parameters / variables example

Hello!

is there a way to pass in $variables?
I was trying the following and it craps out. :/

SpotifyGraphQLClient(config)
  .query(`
      {
        playlist(userId: "1128723762", id: $plid) {
          id
          uri
          name
        }
      }`, null, null, { plid: "2YARXniaJywrRZbbQeSoAi" })
  .then(res => {
    console.log(JSON.stringify(res, null, 2));
    return res;
  })

gives the error

"message": "Variable \"$plid\" is not defined.",

I did not find any examples or tests about passing variables. could you help?

`SpotifyQuery` Decorator ?

Definition

@SpotifyQuery(`
  {
    me {
      savedTracks(5) {
        artists {
          id
        }
      }
    }
  }
`)
function execute(artistsList, name) {
   console.log(name);
   return artistsList;
}

Usage

execute('hello').then((artistsList) => {
   console.log(artistsList)
}, (error) => {
   console.error(error)
});

// Output
// hello
// [ { id : 1, ... } ]

Add images

I'm using your library to query tracks, and I would like to display their album covers. I took from this, that your album's don't include images.

Is images something you intend to add in the near future? Or can you point me to what I'd have to do to add them to the schema? This is my first time with GraphQL, but I know that the SpotifyApi includes images when you query tracks or albums. I assume it wouldn't need extra calls.

Would appreciate 🙂.

[ANNOUNCEMENT] 2.0.0 on the way with breaking changes

This project created more than 4 years ago only supports queries - a subset of it.
The GraphQL ecosystem has made much progress on the back-end side that spotify-graphql could leverage.
One of them is GraphQL Mesh, a tool allowing the consumption of multiple data source types (REST, GRPC, other) using GraphQL.

The following rewrite plan is on the way:

[email protected] will leverage GraphQL Mesh to provide the following:

  • Support for all queries of Spotify API as of January 2021
  • Support for all mutations of Spotify API as of January 2021
  • published on npm as a server and node.js client version

[email protected] will add support for caching

[email protected] will add support nested queries with improved performances and pagination

(Note: [email protected] will provide a similar features-set as [email protected])


I'll keep you updated here on the progress of the following roadmap ⚡

Any feedback is welcome!

Specs

  • utils specs (done in #21 and #20 )
  • resolvers : all available queries
  • resolvers : me { playlists { tracks { ... } } }
  • client factory specs

Pagination goes into infinite loop when querying empty lists

When requesting a paginated resource with no values the paginator goes into an infinite loop of requests to the spotify api.

To reproduce the bug I made this query on a user with no public playlists

{
   user(id: "someid"){
    playlists{
      name
    }
  }
}

The api returns an empty list with total=0, but the !!iterator.total condition inside the shouldStopIterate function causes and infinite loop of requests.

willPaginate optimizations

Create factory willPaginateFor(options)

options :

  • debug: Boolean (default : false)
  • throttle: number (default: 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.