Coder Social home page Coder Social logo

goldensunliu / graphql-spotify Goto Github PK

View Code? Open in Web Editor NEW
59.0 3.0 10.0 60 KB

GraphQL Schema And Resolvers For Spotify Web API

License: MIT License

JavaScript 100.00%
spotify graphql graphql-tools graphql-js graphql-server dataloader graphql-schema spotify-api graphql-spotify resolver

graphql-spotify's Introduction

GraphQL Spotify: Spotify API GraphQL Schema and Resolvers Built with GraphQL.js

npm version

Refer to src/schema/RootQuery.js for operations currently supported.


Blog on Why

Check out the blog on why graphql-spotify was built.

Demo

Deployed Example App Powered By GraphQL Spotify And Its Source Code Repo

Getting started

import { makeSchema } from "graphql-spotify"
let token;
//... somewhere the Spotify token is gotten from the context
const schema = makeSchema(token)
// pass the schema to your favorite server that accepts GraphQL.js Schemas

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, graphiqlExpress } from 'apollo-server-express';
import express from 'express';
import bodyParser from 'body-parser'
// Initialize the app
const port = parseInt(process.env.PORT, 10) || 3000
const app = express();
// bodyParser is needed just for POST.
app.use(
    '/graphql',
    bodyParser.json(),
    graphqlExpress(req => {
        let token;
        //... somewhere the spotify token is gotten from the context
        const schema = makeSchema(token)
        return { schema }
    }));
// GraphiQL, a visual editor for queries
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 graphiqlExpress = require('apollo-server-express').graphiqlExpress;
const express = require('express');
const bodyParser = require('body-parser')
// Initialize the app
const port = parseInt(process.env.PORT, 10) || 3000
const app = express();
// bodyParser is needed just for POST.
app.use(
    '/graphql',
    bodyParser.json(),
    graphqlExpress(req => {
        let token;
        //... somewhere the spotify token is gotten from the context
        const schema = makeSchema(token)
        return { schema }
    }));
// GraphiQL, a visual editor for queries
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!

Used By

Created By

Sitian Liu

graphql-spotify's People

Contributors

goldensunliu avatar soroushchehresa 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

Watchers

 avatar  avatar  avatar

graphql-spotify's Issues

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.