Skip to content

Commit

Permalink
Merge pull request #11 from ricardocasares/beta
Browse files Browse the repository at this point in the history
release
  • Loading branch information
ricardocasares authored Apr 15, 2019
2 parents 3194b9a + 7aca16d commit 5da4b99
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
17 changes: 12 additions & 5 deletions client.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const fetch = require("isomorphic-unfetch");

const URL = "http://www.radio-browser.info/webservice";
const BY_NAME = "/json/stations/byname";
const SERVICE = `${URL}/${BY_NAME}`;
const STATIONS = `/json/stations`;
const BY_ID = `${STATIONS}/byid`;
const BY_NAME = `${STATIONS}/byname`;

const cfg = {
method: "POST",
headers: {
Expand All @@ -13,10 +15,15 @@ const cfg = {
body: JSON.stringify({ order: "votes", reverse: "true", limit: 50 })
};

async function search(name) {
return fetch(`${SERVICE}/${name}`, cfg).then(res => res.json());
}
const get = async id =>
fetch(`${URL}${BY_ID}/${id}`, cfg)
.then(res => res.json())
.then(([station]) => station);

const search = async name =>
fetch(`${URL}${BY_NAME}/${name}`, cfg).then(res => res.json());

module.exports = {
get,
search
};
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions schema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { search } = require("./client");
const { get, search } = require("./client");
const {
GraphQLInt,
GraphQLList,
Expand Down Expand Up @@ -50,14 +50,19 @@ const schema = new GraphQLSchema({
name: "Query",
description: "Station",
fields: () => ({
station: {
type: StationType,
args: {
id: { type: new GraphQLNonNull(GraphQLInt) }
},
resolve: async (root, { id }) => get(id)
},
stations: {
type: new GraphQLList(StationType),
args: {
query: { type: new GraphQLNonNull(GraphQLString) }
},
resolve: async (root, { query }) => {
return search(query);
}
resolve: async (root, { query }) => search(query)
}
})
})
Expand Down

1 comment on commit 5da4b99

@vercel
Copy link

@vercel vercel bot commented on 5da4b99 Apr 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.