├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── examples
├── config.example.json
├── config.example.ts
├── decoratorFetchTrack.ts
├── fetchArtistTopTracks.ts
├── fetchTrack.js
├── fetchTrack.ts
├── fetchUserPlaylists.ts
└── fetchUserSavedArtists.ts
├── package.json
└── tsconfig.json
/.gitignore:
--------------------------------------------------------------------------------
1 | examples/config.json
2 | examples/config.ts
3 | build
4 | node_modules
5 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 |
6 | ## [0.0.3](https://github.com/thefrenchhouse/spotify-graphql-examples/compare/v0.0.2...v0.0.3) (2017-01-26)
7 |
8 |
9 |
10 |
11 | ## [0.0.2](https://github.com/thefrenchhouse/spotify-graphql-examples/compare/v0.0.1...v0.0.2) (2016-11-30)
12 |
13 |
14 |
15 |
16 | ## 0.0.1 (2016-11-28)
17 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 The French House
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### Examples for [spotify-graphql](https://github.com/wittydeveloper/spotify-graphql) NPM package
2 |
3 |
4 | ### Node.js (v6)
5 |
6 | - Copy `examples/config.example.json` to `examples/config.json`
7 | - Edit `examples/config.json` with your application info (see [spotify doc](https://developer.spotify.com/my-applications))
8 |
9 | ```
10 | npm i
11 | nvm use 4.3.2
12 | node examples/fetchTracks.js
13 | ```
14 |
15 |
16 | ### TypeScript
17 |
18 | - Copy `examples/config.example.ts` to `examples/config.ts`
19 | - Edit `examples/config.ts` with your application info (see [spotify doc](https://developer.spotify.com/my-applications))
20 |
21 | ```
22 | npm i
23 | tsc
24 | nvm use 4.3.2
25 | node build/examples/fetchTracks.js
26 | ```
27 |
--------------------------------------------------------------------------------
/examples/config.example.json:
--------------------------------------------------------------------------------
1 | {
2 | "clientId" : "",
3 | "clientSecret" : "",
4 | "redirectUri" : "",
5 | "accessToken" : ""
6 | }
--------------------------------------------------------------------------------
/examples/config.example.ts:
--------------------------------------------------------------------------------
1 | export default {
2 | "clientId" : "",
3 | "clientSecret" : "",
4 | "redirectUri" : "",
5 | "accessToken" : ""
6 | }
--------------------------------------------------------------------------------
/examples/decoratorFetchTrack.ts:
--------------------------------------------------------------------------------
1 | import { SpotifyDecorators, SpotifyQueryDecorated, SpotifyGraphQLClient } from 'spotify-graphql';
2 | import config from './config';
3 |
4 | let client = SpotifyGraphQLClient(config);
5 | let { SpotifyQuery } = SpotifyDecorators(client);
6 |
7 | class Fetcher {
8 |
9 | @SpotifyQuery(`
10 | query getTrack($id: String!) {
11 | track(id: $id) {
12 | name
13 | artists {
14 | name
15 | }
16 | }
17 | }
18 | `)
19 | static getTrack (response?): SpotifyQueryDecorated {
20 | let track = response.track;
21 | return `the track ${track.name} was played by ${track.artists[0].name}`;
22 | }
23 | }
24 |
25 |
26 | Fetcher.getTrack({ id : '3W2ZcrRsInZbjWylOi6KhZ' }).then(sentence => {
27 | console.log(sentence);
28 | // output "the track You & Me - Flume Remix was played by Disclosure"
29 | }, error => { console.log(error) });
--------------------------------------------------------------------------------
/examples/fetchArtistTopTracks.ts:
--------------------------------------------------------------------------------
1 | import { SpotifyGraphQLClient } from 'spotify-graphql';
2 | import config from './config';
3 |
4 | SpotifyGraphQLClient(config).query(`
5 | {
6 | artist(id: "0oSGxfWSnnOXhD2fKuz2Gy") {
7 | name
8 | top_tracks {
9 | name
10 | }
11 | }
12 | }
13 | `).then(executionResult => {
14 | if (executionResult.errors) {
15 | console.log('error');
16 | console.error(JSON.stringify(executionResult.errors));
17 | } else {
18 | console.log('success');
19 | console.log(JSON.stringify(executionResult.data));
20 | }
21 | })
--------------------------------------------------------------------------------
/examples/fetchTrack.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | const spotify_graphql = require('spotify-graphql');
3 | const config = require('./config.json');
4 | spotify_graphql.SpotifyGraphQLClient(config).query(`
5 | {
6 | track(id: "3W2ZcrRsInZbjWylOi6KhZ") {
7 | name
8 | artists {
9 | name
10 | }
11 | album {
12 | name
13 | }
14 | }
15 | }
16 | `).then(executionResult => {
17 | if (executionResult.errors) {
18 | console.log('error');
19 | console.error(JSON.stringify(executionResult.errors));
20 | } else {
21 | console.log('success');
22 | console.log(JSON.stringify(executionResult.data));
23 | }
24 | })
25 |
--------------------------------------------------------------------------------
/examples/fetchTrack.ts:
--------------------------------------------------------------------------------
1 | import { SpotifyGraphQLClient } from 'spotify-graphql';
2 | import config from './config';
3 |
4 | SpotifyGraphQLClient(config).query(`
5 | {
6 | track(id: "3W2ZcrRsInZbjWylOi6KhZ") {
7 | name
8 | artists {
9 | name
10 | }
11 | album {
12 | name
13 | }
14 | }
15 | }
16 | `).then(executionResult => {
17 | if (executionResult.errors) {
18 | console.log('error');
19 | console.error(JSON.stringify(executionResult.errors));
20 | } else {
21 | console.log('success');
22 | console.log(JSON.stringify(executionResult.data));
23 | }
24 | })
--------------------------------------------------------------------------------
/examples/fetchUserPlaylists.ts:
--------------------------------------------------------------------------------
1 | import { SpotifyGraphQLClient } from 'spotify-graphql';
2 | import config from './config';
3 |
4 | SpotifyGraphQLClient(config).query(`
5 | {
6 | user(id: "11879785") {
7 | playlists {
8 | name
9 | tracks {
10 | track {
11 | id
12 | name
13 | }
14 | }
15 | }
16 | }
17 | }
18 | `).then(executionResult => {
19 | if (executionResult.errors) {
20 | console.log('error');
21 | console.error(JSON.stringify(executionResult.errors));
22 | } else {
23 | console.log('success');
24 | console.log(JSON.stringify(executionResult.data));
25 | }
26 | })
--------------------------------------------------------------------------------
/examples/fetchUserSavedArtists.ts:
--------------------------------------------------------------------------------
1 | import { SpotifyGraphQLClient } from 'spotify-graphql';
2 | import config from './config';
3 |
4 | SpotifyGraphQLClient(config).query(`
5 | {
6 | me {
7 | display_name
8 | tracks {
9 | track {
10 | artists {
11 | name
12 | }
13 | }
14 | }
15 | }
16 | }
17 | `).then(executionResult => {
18 | if (executionResult.errors) {
19 | console.log('error');
20 | console.error(JSON.stringify(executionResult.errors));
21 | } else {
22 | console.log('success');
23 | console.log(JSON.stringify(executionResult.data));
24 | }
25 | })
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "spotify-graphql-examples",
3 | "version": "0.0.3",
4 | "description": "Spotify GraphQL use cases",
5 | "main": "examples/fetchTrack.js",
6 | "scripts": {
7 | "release": "standard-version"
8 | },
9 | "author": "Charly POLY ",
10 | "license": "MIT",
11 | "dependencies": {
12 | "spotify-graphql": "1.1.2",
13 | "standard-version": "^4.0.0"
14 | },
15 | "devDependencies": {
16 | "@types/node": "^7.0.8"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es6",
4 | "module": "commonjs",
5 | "moduleResolution": "node",
6 | "sourceMap": false,
7 | "declaration": true,
8 | "noImplicitAny": false,
9 | "rootDir": ".",
10 | "outDir": "build",
11 | "allowSyntheticDefaultImports": true,
12 | "removeComments": true,
13 | "experimentalDecorators": true,
14 | "skipLibCheck": true
15 | },
16 | "include": [
17 | "examples/*.ts"
18 | ]
19 | }
20 |
--------------------------------------------------------------------------------