From 019167f17ec264c5dad7d6872468925cd0a673c3 Mon Sep 17 00:00:00 2001 From: Peter Czibik Date: Mon, 23 Sep 2019 11:28:49 +0200 Subject: [PATCH] Task_4_Start --- src/fetcher.js | 46 +++++++------------------------------------ src/schema.js | 12 +---------- src/schema/weather.js | 25 +---------------------- 3 files changed, 9 insertions(+), 74 deletions(-) diff --git a/src/fetcher.js b/src/fetcher.js index 8b2b858..4406286 100644 --- a/src/fetcher.js +++ b/src/fetcher.js @@ -1,12 +1,7 @@ -const { URL } = require('url'); -const querystring = require('querystring'); - -const axios = require('axios'); const bcrypt = require('bcrypt'); const { get } = require('lodash'); const uuid = require('uuidv4').default; -const config = require('./config'); const db = require('./db'); @@ -130,40 +125,13 @@ const createComment = async (args) => { }; -async function getWeather() { - const city = 'London'; - const APPID = config.openWeatherMapAPIKey; - const query = querystring.stringify({ - q: city, - units: 'metric', - APPID, - }); - - const url = new URL('https://api.openweathermap.org/data/2.5/weather'); - url.search = query; - - const { data } = await axios - .get(url.toString()); - - const { - coord: { - lat, - lon, - }, - main: { - humidity, - temp, - pressure, - }, - } = data; - - return { - lat, - lon, - humidity, - pressure, - temp, - }; +// TODO fire a request to the open weather API to fetch the today's weather +// https://api.openweathermap.org/data/2.5/weather +// "config.openWeatherMapAPIKey" should contain your API key from the environment +// Make sure you only return items that you have declared in your schema! +function getWeather() { + // eslint-disable-next-line no-console + console.log('JS Conf Budapest 2019!'); } module.exports = { diff --git a/src/schema.js b/src/schema.js index b1b0689..6ab2f61 100644 --- a/src/schema.js +++ b/src/schema.js @@ -9,13 +9,9 @@ const { const { getHello, - getWeather, resolveQuery, signin, } = require('./fetcher'); -const { - Weather, -} = require('./schema/weather'); const { UserConnection, UserFieldFilter, UserFieldOrder, UserMutations, User, } = require('./schema/user'); @@ -41,14 +37,8 @@ const queryType = new GraphQLObjectType({ }, resolve: (_, args) => signin(args), }, + // TODO create a top level weather resolver that accepts a location parameter weather: { - type: Weather, - args: { - location: { - type: new GraphQLNonNull(GraphQLString), - }, - }, - resolve: () => getWeather(), }, users: { type: UserConnection, diff --git a/src/schema/weather.js b/src/schema/weather.js index 62e84e3..a170103 100644 --- a/src/schema/weather.js +++ b/src/schema/weather.js @@ -1,32 +1,9 @@ const { GraphQLObjectType, - GraphQLString, } = require('graphql'); +// TODO (1) Write the weather schema const Weather = new GraphQLObjectType({ - name: 'Weather', - fields: { - lat: { - type: GraphQLString, - description: 'The latitude of the requested location', - }, - lon: { - type: GraphQLString, - description: 'The longitute of the requested location', - }, - temp: { - type: GraphQLString, - description: 'Temperature in Celsius degrees', - }, - humidity: { - type: GraphQLString, - description: 'Humidity in %', - }, - pressure: { - type: GraphQLString, - description: 'Atmospheric pressure in hPa', - }, - }, }); module.exports = {