Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task_4_Start #13

Open
wants to merge 1 commit into
base: Task_3_Done
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 7 additions & 39 deletions src/fetcher.js
Original file line number Diff line number Diff line change
@@ -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');


Expand Down Expand Up @@ -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 = {
Expand Down
12 changes: 1 addition & 11 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand Down
25 changes: 1 addition & 24 deletions src/schema/weather.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down