Guest User

Untitled

a guest
Aug 20th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. const schemaExtensionResolvers = {
  2. user: {
  3. city_weather: async (parent, args, context, info) => {
  4. const cityDetails = await getWoeid(parent.city);
  5. if (!cityDetails) {
  6. return null;
  7. }
  8. const weather = await getWeather(cityDetails);
  9. if (!weather) {
  10. return null;
  11. }
  12. let consolidated_weather = weather.consolidated_weather;
  13. // check for args applicable_date to apply filter
  14. consolidated_weather = args.applicable_date ? consolidated_weather.find(item => item.applicable_date === args.applicable_date) : consolidated_weather[0];
  15. const respObj = {'temp': consolidated_weather.the_temp.toString(), 'min_temp': consolidated_weather.min_temp.toString(), 'max_temp': consolidated_weather.max_temp.toString(), 'city_name': weather.title, 'applicable_date': consolidated_weather.applicable_date};
  16. return respObj;
  17. }
  18. }
  19. };
Add Comment
Please, Sign In to add comment