Skip to content

Commit 019167f

Browse files
committed
Task_4_Start
1 parent c0e1583 commit 019167f

File tree

3 files changed

+9
-74
lines changed

3 files changed

+9
-74
lines changed

src/fetcher.js

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
const { URL } = require('url');
2-
const querystring = require('querystring');
3-
4-
const axios = require('axios');
51
const bcrypt = require('bcrypt');
62
const { get } = require('lodash');
73
const uuid = require('uuidv4').default;
84

9-
const config = require('./config');
105
const db = require('./db');
116

127

@@ -130,40 +125,13 @@ const createComment = async (args) => {
130125
};
131126

132127

133-
async function getWeather() {
134-
const city = 'London';
135-
const APPID = config.openWeatherMapAPIKey;
136-
const query = querystring.stringify({
137-
q: city,
138-
units: 'metric',
139-
APPID,
140-
});
141-
142-
const url = new URL('https://api.openweathermap.org/data/2.5/weather');
143-
url.search = query;
144-
145-
const { data } = await axios
146-
.get(url.toString());
147-
148-
const {
149-
coord: {
150-
lat,
151-
lon,
152-
},
153-
main: {
154-
humidity,
155-
temp,
156-
pressure,
157-
},
158-
} = data;
159-
160-
return {
161-
lat,
162-
lon,
163-
humidity,
164-
pressure,
165-
temp,
166-
};
128+
// TODO fire a request to the open weather API to fetch the today's weather
129+
// https://api.openweathermap.org/data/2.5/weather
130+
// "config.openWeatherMapAPIKey" should contain your API key from the environment
131+
// Make sure you only return items that you have declared in your schema!
132+
function getWeather() {
133+
// eslint-disable-next-line no-console
134+
console.log('JS Conf Budapest 2019!');
167135
}
168136

169137
module.exports = {

src/schema.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ const {
99

1010
const {
1111
getHello,
12-
getWeather,
1312
resolveQuery,
1413
signin,
1514
} = require('./fetcher');
16-
const {
17-
Weather,
18-
} = require('./schema/weather');
1915
const {
2016
UserConnection, UserFieldFilter, UserFieldOrder, UserMutations, User,
2117
} = require('./schema/user');
@@ -41,14 +37,8 @@ const queryType = new GraphQLObjectType({
4137
},
4238
resolve: (_, args) => signin(args),
4339
},
40+
// TODO create a top level weather resolver that accepts a location parameter
4441
weather: {
45-
type: Weather,
46-
args: {
47-
location: {
48-
type: new GraphQLNonNull(GraphQLString),
49-
},
50-
},
51-
resolve: () => getWeather(),
5242
},
5343
users: {
5444
type: UserConnection,

src/schema/weather.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
const {
22
GraphQLObjectType,
3-
GraphQLString,
43
} = require('graphql');
54

5+
// TODO (1) Write the weather schema
66
const Weather = new GraphQLObjectType({
7-
name: 'Weather',
8-
fields: {
9-
lat: {
10-
type: GraphQLString,
11-
description: 'The latitude of the requested location',
12-
},
13-
lon: {
14-
type: GraphQLString,
15-
description: 'The longitute of the requested location',
16-
},
17-
temp: {
18-
type: GraphQLString,
19-
description: 'Temperature in Celsius degrees',
20-
},
21-
humidity: {
22-
type: GraphQLString,
23-
description: 'Humidity in %',
24-
},
25-
pressure: {
26-
type: GraphQLString,
27-
description: 'Atmospheric pressure in hPa',
28-
},
29-
},
307
});
318

329
module.exports = {

0 commit comments

Comments
 (0)