A Spotify API GraphQL Schema Implementation Built with GraphQL.js
Refer to src/schema/RootQuery.js
for operations currently supported.
Getting started
import { makeSchema } from "graphql-spotify"
let token;
const schema = makeSchema(token)
Make sure the token obtained has the correct scope, certain queries and mutations require different scopes from Spotify
Getting started with apollo-server-express
npm install --save graphql dataloader graphql-tools isomorphic-fetch body-parser apollo-server-express express graphql-spotify
ES6
import { makeSchema } from "graphql-spotify";
import { graphqlExpress } from 'apollo-server-express';
import express from 'express';
import bodyParser from 'body-parser'
const port = parseInt(process.env.PORT, 10) || 3000
const app = express();
app.use(
'/graphql',
bodyParser.json(),
graphqlExpress(req => {
let token;
const schema = makeSchema(token)
return { schema }
}));
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
app.listen(port, (err) => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}/graphql`)
})
ES5
const makeSchema = require("graphql-spotify").makeSchema;
const graphqlExpress = require('apollo-server-express').graphqlExpress;
const express = require('express');
const bodyParser = require('body-parser')
const port = parseInt(process.env.PORT, 10) || 3000
const app = express();
app.use(
'/graphql',
bodyParser.json(),
graphqlExpress(req => {
let token;
const schema = makeSchema(token)
return { schema }
}));
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
app.listen(port, (err) => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}/graphql`)
})
Contribute
Anyone is welcome! Take a look at Roadmap.md for PR ideas and file some issues!