【问题标题】:How to send a graphQl query to third party api如何将graphQl查询发送到第三方api
【发布时间】:2022-02-04 03:03:34
【问题描述】:

我有一个端点来获取数据。端点是

api.openweathermap.org/data/2.5/weather?q={city name}&appid={API key}

它发送的响应如下

{
  coord: { lon: 73.2145, lat: 34.1469 },
  weather: [
  { id: 801, main: 'Clouds', description: 'few clouds', icon: '02n' }
 ],
 base: 'stations',
 main: {
 temp: 277.91,
 feels_like: 277.91,
 temp_min: 277.91,
 temp_max: 277.91,
 pressure: 1011,
 humidity: 85,
 sea_level: 1011,
 grnd_level: 871
  },
 visibility: 10000,
 wind: { speed: 0.33, deg: 168, gust: 0.44 },
 clouds: { all: 20 },
 dt: 1643912333,
sys: {
type: 2,
id: 2007435,
country: 'PK',
sunrise: 1643853796,
sunset: 1643891911
},
 timezone: 18000,
 id: 1185056,

}

如果我要发送一个 graphQL 查询来获取 main 和 wind.How 将如何完成我正在使用 nestJs 一个 nodeJs 框架。

【问题讨论】:

    标签: node.js graphql nestjs


    【解决方案1】:

    从解析器返回整个 API 响应并从前端查询

    query {
     fetchWeather {
       main
       wind
     }
    }
    

    如果您使用 AWS,则可以使用应用同步及其响应映射模板。

    【讨论】:

      猜你喜欢
      • 2018-11-10
      • 2019-01-01
      • 2017-07-21
      • 1970-01-01
      • 1970-01-01
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      相关资源
      最近更新 更多