Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
apollo-datasource-spotify
Advanced tools
Readme
Apollo Data Source Spotify encapsulates fetching data from the Spotify API.
npm install apollo-datasource-rest dataloader graphql
import { SpotifyAPI } from 'apollo-datasource-spotify';
const apollo = new ApolloServer({
context: ({ req }) => ({
authorization: req.headers.authorization,
}),
dataSources: () => ({
spotify: new SpotifyAPI(),
}),
});
export const resolvers = {
Query: {
me(root, args, context) {
return context.dataSources.spotify.me();
},
},
};
import { batch } from 'apollo-datasource-spotify';
const resolver = async (root, args, context) {
await batch({
limit: 2500,
request: (params) => dataSources.spotify.savedTracks(params),
callback: async (savedTracks) => {
console.log(savedTracks);
},
});
return;
};
If you run into issues with rate-limiting, try throttling requests with something like bottleneck.
npm install --save bottleneck
import SpotifyAPI from 'apollo-datasource-rest';
import Bottleneck from 'bottleneck';
class ThrottledSpotifyAPI extends SpotifyAPI {
constructor() {
super();
this.limiter = new Bottleneck({
reservoir: 100,
reservoirRefreshAmount: 100,
reservoirRefreshInterval: 60 * 1000,
maxConcurrent: 1,
minTime: 333,
});
this.get = this.limiter.wrap(this.get.bind(this));
this.post = this.limiter.wrap(this.post.bind(this));
this.put = this.limiter.wrap(this.put.bind(this));
this.delete = this.limiter.wrap(this.delete.bind(this));
}
}
To use the Spotify GraphQL schema implement your own
custom scalar
JSON type or use graphql-type-json
.
npm install --save graphql-type-json
import { ApolloServer, gql } from 'apollo-server';
import { SpotifyAPI, typeDefs, resolvers } from 'apollo-datasource-spotify';
import GraphQLJSON from 'graphql-type-json';
const apollo = new ApolloServer({
context: ({ req }) => ({
authorization: req.headers.authorization,
}),
dataSources: () => ({
spotify: new SpotifyAPI(),
}),
typeDefs: gql(typeDefs()),
resolvers: resolvers({ JSON: GraphQLJSON }),
});
query {
spotify {
getAlbum(id: "42j41uUwuHZT3bnedq2XtM") {
id
name
}
getAlbumsTracks(id: "42j41uUwuHZT3bnedq2XtM") {
items {
... on SimplifiedTrackObject {
id
name
preview_url
artists {
id
name
}
}
}
}
}
}
FAQs
RESTDataSource wrapper for the Spotify API
The npm package apollo-datasource-spotify receives a total of 22 weekly downloads. As such, apollo-datasource-spotify popularity was classified as not popular.
We found that apollo-datasource-spotify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.