charlypoly / spotify-graphql Goto Github PK
View Code? Open in Web Editor NEWGraphQL schema for Spotify WebAPI — TypeScript / Node.js (v6)
License: MIT License
GraphQL schema for Spotify WebAPI — TypeScript / Node.js (v6)
License: MIT License
Create factory willPaginateFor(options)
options :
debug
: Boolean (default : false
)throttle
: number (default: 0
)me {
devices {
id
is_active
is_restricted
name
type
volume_percent
}
}
https://developer.spotify.com/web-api/web-api-connect-endpoint-reference/
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'.
...
Looks like it does not.
for performance reasons.
@SpotifyQuery(`
{
me {
savedTracks(5) {
artists {
id
}
}
}
}
`)
function execute(artistsList, name) {
console.log(name);
return artistsList;
}
execute('hello').then((artistsList) => {
console.log(artistsList)
}, (error) => {
console.error(error)
});
// Output
// hello
// [ { id : 1, ... } ]
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..
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'.
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 uniquespotify: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
Allow to support this kind of query
query {
artist(name: "John Mayer") {
tracks {
name
}
}
}
for people that want to develop basic improvements on their own (schema improvements, etc)
me {
player {
timestamp
device
id
is_active
is_restricted2
name
type
volume_percent
},
progress_ms
is_playing
shuffle_state
repeat_state
context {
href
type
uri
}
}
}
https://developer.spotify.com/web-api/web-api-connect-endpoint-reference/
Remove custom GraphQL client and also drop spotify-web-api-node
(#47)
Looks like full
is only used as a Boolean. Also, it should be described in the schema. That description might've prevented charlypoly/spotify-api-graphql-console#26
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 🙂.
is there a way with this package to launch a graphiql server?
Thanks.
http://thefrench.house/spotify-graphql-console/ with :
make library usable from plain JS (ES5/ES6) for node.js
import SpotifyGraphQLClient from 'spotify-graphql'
is currently broken when using lib as NPM package..
TODO: list all missing endpoints
+ typings review of the schema
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
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?
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?
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:
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!
Find a way to make all errors reach top level reject handler.
See https://developer.spotify.com/web-api/object-model/#image-object
Add to given types :
playlist
album
user
(private and public)artist
Follow up to #62
use lib/utils/request.ts
instead !
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?
see https://david-dm.org/thefrenchhouse/spotify-graphql
graphql
-> 0.9.1
graphql-tools
-> 0.10.1
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.
me {
artists {
top_tracks {
name
}
}
}
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?
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).
Automate schema + resolvers generation using https://github.com/spotify/web-api/tree/master/specifications/raml + https://github.com/raml-org/raml-js-parser-2/blob/master/documentation/GettingStarted.md
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.