Thư viện QueriesLấy dữ liệu dự báo thời tiết Mỹ cho nhiều địa điểm
Lấy dữ liệu dự báo thời tiết Mỹ cho nhiều địa điểm
Query này kết nối với API của Cơ quan Thời tiết Quốc gia Mỹ và lấy dữ liệu dự báo thời tiết cho nhiều địa điểm với tọa độ được cung cấp (thông qua biến $coordinatesList, đây là danh sách các đối tượng JSON với các trường lat và long).
query GenerateLocationURLs(
# List of JSON objects with entries `lat` and `long`
# eg: [ { "lat": 39.7456, "long": -97.0892 }, { "lat": 34.7456, "long": -77.0892 } ]
$coordinatesList: [JSONObject!]!
) {
coordinatesList: _echo(value: $coordinatesList)
@underEachArrayItem(
passValueOnwardsAs: "coordinates"
affectDirectivesUnderPos: [1, 2, 3, 4]
)
@applyField(
name: "_objectProperty",
arguments: {
by: { key: "lat" }
object: $coordinates
},
passOnwardsAs: "lat"
)
@applyField(
name: "_objectProperty",
arguments: {
by: { key: "long" }
object: $coordinates
},
passOnwardsAs: "long"
)
@applyField(
name: "_sprintf",
arguments: {
string: "https://api.weather.gov/points/%s,%s",
values: [$lat, $long]
}
passOnwardsAs: "locationURL"
)
@applyField(
name: "_echo",
arguments: {
value: {
url: $locationURL
}
}
setResultInResponse: true
)
@export(as: "coordinatesListInput")
}
query FetchUSWeatherDataForLocations
@depends(on: "GenerateLocationURLs")
{
_sendJSONObjectItemHTTPRequests(inputs: $coordinatesListInput)
}