Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-spotify

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-spotify - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

src/schema/Category.js

334

dist/lib.js

@@ -85,3 +85,3 @@ module.exports =

var _resolvers = __webpack_require__(14);
var _resolvers = __webpack_require__(19);

@@ -160,2 +160,22 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _Category = __webpack_require__(14);
var _Category2 = _interopRequireDefault(_Category);
var _RecommendationParameters = __webpack_require__(15);
var _RecommendationParameters2 = _interopRequireDefault(_RecommendationParameters);
var _RecommendationsResponse = __webpack_require__(16);
var _RecommendationsResponse2 = _interopRequireDefault(_RecommendationsResponse);
var _RecommendationsSeedObject = __webpack_require__(17);
var _RecommendationsSeedObject2 = _interopRequireDefault(_RecommendationsSeedObject);
var _RootQuery = __webpack_require__(18);
var _RootQuery2 = _interopRequireDefault(_RootQuery);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -170,36 +190,4 @@

const RootQuery = `
type RootQuery {
featuredPlaylists(limit: Int, offset: Int): Paging
"""
Returns the most recent 50 tracks played by a user
"""
recentlyPlayed: [PlayHistory]
"""
Get a playlist owned by a Spotify user
"""
playlist(userId: String!, playlistId: String!): Playlist
"""
Get an artist
"""
artist(artistId: String!): Artist
"""
Get audio features of a track
"""
audioFeatures(id: String!): AudioFeatures
"""
Get a track
"""
track(id: String!): Track
}
type Mutation {
"""
"""
saveTrack(trackId: String!): Track
}
`;
const typeDefs = [SchemaDefinition, _RootQuery2.default, _Playlist2.default, _Image2.default, _User2.default, _PlaylistTrack2.default, _Track2.default, _Album2.default, _Artist2.default, _Paging2.default, _AudioFeatures2.default, _PlayHistory2.default, _Category2.default, _RecommendationParameters2.default, _RecommendationsResponse2.default, _RecommendationsSeedObject2.default, _ExternalUrls2.default];
const typeDefs = [SchemaDefinition, RootQuery, _Playlist2.default, _Image2.default, _User2.default, _PlaylistTrack2.default, _Track2.default, _Album2.default, _Artist2.default, _Paging2.default, _AudioFeatures2.default, _PlayHistory2.default, _ExternalUrls2.default];
exports.default = typeDefs;

@@ -475,3 +463,3 @@

const Paging = `
union Item = Playlist | PlaylistTrack
union Item = Playlist | PlaylistTrack | Category
type Paging {

@@ -574,15 +562,172 @@ href: String

});
const Category = `
type Category {
"""
A link to the Web API endpoint returning full details of the category.
"""
href: String
icons: [Image]
id: String
name: String
}
`;
exports.default = Category;
/***/ }),
/* 15 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
// TODO after all parameters on targting attributes from https://beta.developer.spotify.com/documentation/web-api/reference/browse/get-recommendations/
const RecommendationParameters = `
input RecommendationParameters {
limit: Int
seed_artists: [String]
seed_genres: [String]
seed_tracks: [String]
}
`;
exports.default = RecommendationParameters;
/***/ }),
/* 16 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const RecommendationsResponse = `
type RecommendationsResponse {
seeds: [RecommendationsSeedObject]
"""
An array of track object (simplified) ordered according to the parameters supplied
"""
tracks: [Track]
}
`;
exports.default = RecommendationsResponse;
/***/ }),
/* 17 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const RecommendationsSeedObject = `
type RecommendationsSeedObject {
"""
The number of tracks available after min_* and max_* filters have been applied
"""
afterFilteringSize: Int
"""
The number of tracks available after relinking for regional availability.
"""
afterRelinkingSize: Int
"""
A link to the full track or artist data for this seed. For tracks this will be a link to a Track Object. For artists a link to an Artist Object. For genre seeds, this value will be null.
"""
href: String
"""
The id used to select this seed. This will be the same as the string used in the seed_artists , seed_tracks or seed_genres parameter
"""
id: String
"""
The number of recommended tracks available for this seed.
"""
initialPoolSize: Int
"""
The entity type of this seed. One of artist , track or genre
"""
type: String
}
`;
exports.default = RecommendationsSeedObject;
/***/ }),
/* 18 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const RootQuery = `
type RootQuery {
featuredPlaylists(limit: Int, offset: Int): Paging
"""
Returns the most recent 50 tracks played by a user
"""
recentlyPlayed: [PlayHistory]
"""
Get a playlist owned by a Spotify user
"""
playlist(userId: String!, playlistId: String!): Playlist
"""
Get an artist
"""
artist(artistId: String!): Artist
"""
Get audio features of a track
"""
audioFeatures(id: String!): AudioFeatures
"""
Get a track
"""
track(id: String!): Track
"""
https://beta.developer.spotify.com/documentation/web-api/reference/browse/get-list-categories/
Get a list of categories used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).
"""
categories(limit: Int, offset: Int): Paging
"""
"""
recommendations(parameters: RecommendationParameters): RecommendationsResponse
}
type Mutation {
"""
"""
saveTrack(trackId: String!): Track
}
`;
exports.default = RootQuery;
/***/ }),
/* 19 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.makeResolvers = makeResolvers;
var _SpotifyWebApi = __webpack_require__(15);
var _SpotifyWebApi = __webpack_require__(20);
function makeResolvers(token) {
const PlaylistLoader = (0, _SpotifyWebApi.makePlaylistLoader)(token);
const PlaylistTracksLoader = (0, _SpotifyWebApi.makePlaylistTracksLoader)(token);
const AlbumLoader = (0, _SpotifyWebApi.makeAlbumsLoader)(token);
const UserLoader = (0, _SpotifyWebApi.makeUserLoader)(token);
const ArtistLoader = (0, _SpotifyWebApi.makeArtistsLoader)(token);
const AudioFeatureLoader = (0, _SpotifyWebApi.makeAudioFeaturesLoader)(token);
const SavedContainsLoader = (0, _SpotifyWebApi.makeSavedContainsLoader)(token);
const TrackLoader = (0, _SpotifyWebApi.makeTracksLoader)(token);
const {
PlaylistLoader, PlaylistTracksLoader, AlbumsLoader, UserLoader, ArtistsLoader,
AudioFeaturesLoader, SavedContainsLoader, TracksLoader, CategoriesLoader, RecommendationsLoader
} = (0, _SpotifyWebApi.makeLoaders)(token);

@@ -603,9 +748,16 @@ const resolvers = {

artist: async (obj, { artistId }) => {
return await ArtistLoader.load(artistId);
return await ArtistsLoader.load(artistId);
},
track: async (obj, { id }) => {
return await TrackLoader.load(id);
return await TracksLoader.load(id);
},
audioFeatures: async (obj, { id }) => {
return await AudioFeatureLoader.load(id);
return await AudioFeaturesLoader.load(id);
},
categories: async (obj, args) => {
const res = await CategoriesLoader.load(args);
return res.categories;
},
recommendations: async (obj, args) => {
return await RecommendationsLoader.load(args.parameters);
}

@@ -665,15 +817,15 @@ },

followerCount: async ({ id }) => {
const artistFull = await ArtistLoader.load(id);
const artistFull = await ArtistsLoader.load(id);
return artistFull.followers.total;
},
images: async ({ id }) => {
const artistFull = await ArtistLoader.load(id);
const artistFull = await ArtistsLoader.load(id);
return artistFull.images;
},
popularity: async ({ id }) => {
const artistFull = await ArtistLoader.load(id);
const artistFull = await ArtistsLoader.load(id);
return artistFull.popularity;
},
genres: async ({ id }) => {
const artistFull = await ArtistLoader.load(id);
const artistFull = await ArtistsLoader.load(id);
return artistFull.genres;

@@ -685,19 +837,19 @@ }

genres: async object => {
const AlbumFull = await AlbumLoader.load(object.id);
const AlbumFull = await AlbumsLoader.load(object.id);
return AlbumFull.genres;
},
label: async object => {
const AlbumFull = await AlbumLoader.load(object.id);
const AlbumFull = await AlbumsLoader.load(object.id);
return AlbumFull.label;
},
popularity: async object => {
const AlbumFull = await AlbumLoader.load(object.id);
const AlbumFull = await AlbumsLoader.load(object.id);
return AlbumFull.popularity;
},
release_date: async object => {
const { release_date } = await AlbumLoader.load(object.id);
const { release_date } = await AlbumsLoader.load(object.id);
return release_date;
},
release_date_precision: async object => {
const { release_date_precision } = await AlbumLoader.load(object.id);
const { release_date_precision } = await AlbumsLoader.load(object.id);
return release_date_precision;

@@ -718,2 +870,3 @@ }

}
return 'Category';
}

@@ -726,3 +879,3 @@ }

/***/ }),
/* 15 */
/* 20 */
/***/ (function(module, exports, __webpack_require__) {

@@ -739,2 +892,4 @@

exports.getFeaturedPlaylists = getFeaturedPlaylists;
exports.getRecommendations = getRecommendations;
exports.getCategories = getCategories;
exports.getRecentlyPlayed = getRecentlyPlayed;

@@ -748,2 +903,3 @@ exports.getPlaylist = getPlaylist;

exports.getAudioFeatures = getAudioFeatures;
exports.makeLoaders = makeLoaders;
exports.makeUserLoader = makeUserLoader;

@@ -757,6 +913,8 @@ exports.makePlaylistLoader = makePlaylistLoader;

exports.makeAudioFeaturesLoader = makeAudioFeaturesLoader;
exports.makeCategoriesLoader = makeCategoriesLoader;
exports.makeRecommendationsLoader = makeRecommendationsLoader;
__webpack_require__(16);
__webpack_require__(21);
var _dataloader = __webpack_require__(17);
var _dataloader = __webpack_require__(22);

@@ -775,2 +933,6 @@ var _dataloader2 = _interopRequireDefault(_dataloader);

function cacheKeyFnForQueryKeys(key) {
return JSON.stringify(key);
}
function serializeToURLParameters(obj) {

@@ -807,2 +969,20 @@ return Object.entries(obj).map(([key, val]) => `${key}=${val}`).join('&');

async function getRecommendations(token, queryParams) {
let res = await fetch(`https://api.spotify.com/v1/recommendations?${serializeToURLParameters(queryParams)}`, {
method: 'GET',
headers: makeHeaders(token)
});
res = await res.json();
return res;
}
async function getCategories(token, queryParams = {}) {
let res = await fetch(`https://api.spotify.com/v1/browse/categories?${serializeToURLParameters(queryParams)}`, {
method: 'GET',
headers: makeHeaders(token)
});
res = await res.json();
return res;
}
async function getRecentlyPlayed(token) {

@@ -881,2 +1061,17 @@ const url = "https://api.spotify.com/v1/me/player/recently-played?limit=50";

function makeLoaders(token) {
return {
UserLoader: makeUserLoader(token),
PlaylistLoader: makePlaylistLoader(token),
PlaylistTracksLoader: makePlaylistTracksLoader(token),
AlbumsLoader: makeAlbumsLoader(token),
ArtistsLoader: makeArtistsLoader(token),
TracksLoader: makeTracksLoader(token),
SavedContainsLoader: makeSavedContainsLoader(token),
AudioFeaturesLoader: makeAudioFeaturesLoader(token),
CategoriesLoader: makeCategoriesLoader(token),
RecommendationsLoader: makeRecommendationsLoader(token)
};
}
function makeUserLoader(token) {

@@ -934,4 +1129,3 @@ const batchLoadFn = async ([key]) => {

const batchLoadFn = async keys => {
const saved = await getSavedContains(token, keys);
return saved;
return await getSavedContains(token, keys);
};

@@ -949,4 +1143,18 @@ return new _dataloader2.default(batchLoadFn, { maxBatchSize: 50 });

function makeCategoriesLoader(token) {
const batchLoadFn = async ([key]) => {
return [await getCategories(token, key)];
};
return new _dataloader2.default(batchLoadFn, { batch: false, cacheKeyFn: cacheKeyFnForQueryKeys });
}
function makeRecommendationsLoader(token) {
const batchLoadFn = async ([key]) => {
return [await getRecommendations(token, key)];
};
return new _dataloader2.default(batchLoadFn, { batch: false, cacheKeyFn: cacheKeyFnForQueryKeys });
}
/***/ }),
/* 16 */
/* 21 */
/***/ (function(module, exports) {

@@ -957,3 +1165,3 @@

/***/ }),
/* 17 */
/* 22 */
/***/ (function(module, exports) {

@@ -960,0 +1168,0 @@

7

package.json
{
"name": "graphql-spotify",
"version": "0.4.01",
"version": "0.4.2",
"description": "GraphQL Schema And Resolvers For Spotify Web API",

@@ -23,6 +23,3 @@ "main": "dist/lib.js",

"webpack-node-externals": "^1.6.0",
"graphql": "git://github.com/graphql/graphql-js.git#npm",
"dataloader": "^1.3.0",
"graphql-tools": "^2.18.0",
"isomorphic-fetch": "^2.2.1"
"graphql": "git://github.com/graphql/graphql-js.git#npm"
},

@@ -29,0 +26,0 @@ "peerDependencies": {

import {
getFeaturedPlaylists, getRecentlyPlayed, makePlaylistLoader, makePlaylistTracksLoader, makeAlbumsLoader,
makeUserLoader, makeArtistsLoader, makeAudioFeaturesLoader, saveTrackToLib, makeTracksLoader, makeSavedContainsLoader
getFeaturedPlaylists, getRecentlyPlayed, makeLoaders, saveTrackToLib
} from './SpotifyWebApi'
export function makeResolvers(token) {
const PlaylistLoader = makePlaylistLoader(token)
const PlaylistTracksLoader = makePlaylistTracksLoader(token)
const AlbumLoader = makeAlbumsLoader(token)
const UserLoader = makeUserLoader(token)
const ArtistLoader = makeArtistsLoader(token)
const AudioFeatureLoader = makeAudioFeaturesLoader(token)
const SavedContainsLoader = makeSavedContainsLoader(token)
const TrackLoader = makeTracksLoader(token)
const {
PlaylistLoader, PlaylistTracksLoader, AlbumsLoader, UserLoader, ArtistsLoader,
AudioFeaturesLoader, SavedContainsLoader, TracksLoader, CategoriesLoader, RecommendationsLoader
} = makeLoaders(token);

@@ -30,9 +25,16 @@ const resolvers = {

artist: async(obj, {artistId}) => {
return await ArtistLoader.load(artistId)
return await ArtistsLoader.load(artistId)
},
track: async(obj, {id}) => {
return await TrackLoader.load(id)
return await TracksLoader.load(id)
},
audioFeatures: async (obj, {id}) => {
return await AudioFeatureLoader.load(id)
return await AudioFeaturesLoader.load(id)
},
categories: async (obj, args) => {
const res = await CategoriesLoader.load(args)
return res.categories
},
recommendations: async (obj, args) => {
return await RecommendationsLoader.load(args.parameters)
}

@@ -92,15 +94,15 @@ },

followerCount: async ({ id }) => {
const artistFull = await ArtistLoader.load(id)
const artistFull = await ArtistsLoader.load(id)
return artistFull.followers.total
},
images: async ({ id }) => {
const artistFull = await ArtistLoader.load(id)
const artistFull = await ArtistsLoader.load(id)
return artistFull.images
},
popularity: async ({ id }) => {
const artistFull = await ArtistLoader.load(id)
const artistFull = await ArtistsLoader.load(id)
return artistFull.popularity
},
genres: async ({ id }) => {
const artistFull = await ArtistLoader.load(id)
const artistFull = await ArtistsLoader.load(id)
return artistFull.genres

@@ -112,19 +114,19 @@ },

genres: async (object) => {
const AlbumFull = await AlbumLoader.load(object.id)
const AlbumFull = await AlbumsLoader.load(object.id)
return AlbumFull.genres
},
label: async (object) => {
const AlbumFull = await AlbumLoader.load(object.id)
const AlbumFull = await AlbumsLoader.load(object.id)
return AlbumFull.label
},
popularity: async (object) => {
const AlbumFull = await AlbumLoader.load(object.id)
const AlbumFull = await AlbumsLoader.load(object.id)
return AlbumFull.popularity
},
release_date: async (object) => {
const { release_date } = await AlbumLoader.load(object.id)
const { release_date } = await AlbumsLoader.load(object.id)
return release_date
},
release_date_precision: async (object) => {
const { release_date_precision } = await AlbumLoader.load(object.id)
const { release_date_precision } = await AlbumsLoader.load(object.id)
return release_date_precision

@@ -145,2 +147,3 @@ }

}
return 'Category'
}

@@ -147,0 +150,0 @@ }

@@ -12,3 +12,9 @@ import Playlist from './Playlist'

import ExternalUrls from './ExternalUrls'
import Category from './Category'
import RecommendationParameters from './RecommendationParameters'
import RecommendationsResponse from './RecommendationsResponse'
import RecommendationsSeedObject from './RecommendationsSeedObject'
import RootQuery from './RootQuery'
const SchemaDefinition = `

@@ -21,37 +27,5 @@ schema {

const RootQuery = `
type RootQuery {
featuredPlaylists(limit: Int, offset: Int): Paging
"""
Returns the most recent 50 tracks played by a user
"""
recentlyPlayed: [PlayHistory]
"""
Get a playlist owned by a Spotify user
"""
playlist(userId: String!, playlistId: String!): Playlist
"""
Get an artist
"""
artist(artistId: String!): Artist
"""
Get audio features of a track
"""
audioFeatures(id: String!): AudioFeatures
"""
Get a track
"""
track(id: String!): Track
}
type Mutation {
"""
"""
saveTrack(trackId: String!): Track
}
`;
const typeDefs = [SchemaDefinition, RootQuery, Playlist, Image, User, PlaylistTrack, Track, Album, Artist, Paging,
AudioFeatures, PlayHistory, ExternalUrls];
AudioFeatures, PlayHistory, Category, RecommendationParameters, RecommendationsResponse, RecommendationsSeedObject, ExternalUrls];
export default typeDefs
const Paging = `
union Item = Playlist | PlaylistTrack
union Item = Playlist | PlaylistTrack | Category
type Paging {

@@ -4,0 +4,0 @@ href: String

@@ -12,2 +12,6 @@ import 'isomorphic-fetch'

function cacheKeyFnForQueryKeys(key) {
return JSON.stringify(key)
}
function serializeToURLParameters(obj) {

@@ -46,2 +50,22 @@ return Object.entries(obj).map(([key, val]) => `${key}=${val}`).join('&')

export async function getRecommendations(token, queryParams)
{
let res = await fetch(`https://api.spotify.com/v1/recommendations?${serializeToURLParameters(queryParams)}`, {
method: 'GET',
headers: makeHeaders(token)
});
res = await res.json();
return res;
}
export async function getCategories(token, queryParams = {})
{
let res = await fetch(`https://api.spotify.com/v1/browse/categories?${serializeToURLParameters(queryParams)}`, {
method: 'GET',
headers: makeHeaders(token)
});
res = await res.json();
return res;
}
export async function getRecentlyPlayed(token) {

@@ -127,2 +151,17 @@ const url = "https://api.spotify.com/v1/me/player/recently-played?limit=50"

export function makeLoaders(token) {
return {
UserLoader : makeUserLoader(token),
PlaylistLoader : makePlaylistLoader(token),
PlaylistTracksLoader: makePlaylistTracksLoader(token),
AlbumsLoader: makeAlbumsLoader(token),
ArtistsLoader: makeArtistsLoader(token),
TracksLoader: makeTracksLoader(token),
SavedContainsLoader: makeSavedContainsLoader(token),
AudioFeaturesLoader: makeAudioFeaturesLoader(token),
CategoriesLoader : makeCategoriesLoader(token),
RecommendationsLoader: makeRecommendationsLoader(token)
}
}
export function makeUserLoader(token) {

@@ -180,4 +219,3 @@ const batchLoadFn = async ([key]) => {

const batchLoadFn = async (keys) => {
const saved = await getSavedContains(token, keys)
return saved
return await getSavedContains(token, keys)
}

@@ -193,2 +231,16 @@ return new Dataloader(batchLoadFn, { maxBatchSize: 50 })

return new Dataloader(batchLoadFn, { maxBatchSize: 50 })
}
export function makeCategoriesLoader(token) {
const batchLoadFn = async ([key]) => {
return [await getCategories(token, key)]
}
return new Dataloader(batchLoadFn, { batch: false, cacheKeyFn: cacheKeyFnForQueryKeys })
}
export function makeRecommendationsLoader(token) {
const batchLoadFn = async ([key]) => {
return [await getRecommendations(token, key)]
}
return new Dataloader(batchLoadFn, { batch: false, cacheKeyFn: cacheKeyFnForQueryKeys })
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc