我正在尝试使用Angular中的GraphQL和Apollo向HERE API发出GET请求,但是我不知道如何构造端点,因为使用API REST,它看起来像这样:
https://geocoder.api.here.com/6.2/geocode.json?app_id{YOUR_APP_ID}&app_code{YOUR_APP_CODE}&searchtext=425+W+Randolph+Chicago
并返回以下内容:
"MetaInfo": {"Timestamp": "2016-11-02T13:24:11.575+0000"},
"View": [{
"_type": "SearchResultsViewType",
"ViewId": 0,
"Result": [{
"Relevance": 1,
"MatchLevel": "houseNumber",
"MatchQuality": {
"City": 1,
"Street": [0.9],
"HouseNumber": 1
},
"MatchType": "pointAddress",
"Location": {
"LocationId": "NT_Opil2LPZVRLZjlWNLJQuWB_0ITN",
"LocationType": "point",
"DisplayPosition": {
"Latitude": 41.88432,
"Longitude": -87.6387699
},
"NavigationPosition": [{
"Latitude": 41.88449,
"Longitude": -87.6387699
}],
"MapView": {
"TopLeft": {
"Latitude": 41.8854442,
"Longitude": -87.6402799
},
"BottomRight": {
"Latitude": 41.8831958,
"Longitude": -87.6372599
}
},
"Address": {
"Label": "425 W Randolph St, Chicago, IL 60606, United States",
"Country": "USA",
"State": "IL",
"County": "Cook",
"City": "Chicago",
"District": "West Loop",
"Street": "W Randolph St",
"HouseNumber": "425",
"PostalCode": "60606",
"AdditionalData": [
{
"value": "United States",
"key": "CountryName"
},
{
"value": "Illinois",
"key": "StateName"
},
{
"value": "Cook",
"key": "CountyName"
},
{
"value": "N",
"key": "PostalCodeType"
}
]
}
}
}]
}]
}}
这是正确的,但是使用GraphQL会返回以下内容:
TypeError: Failed to fetch.
下一个是我的代码
constructor(private apollo: Apollo, private httpLink: HttpLink) {
apollo.create({
link: httpLink.create({ uri: '' }),
cache: new InMemoryCache()
})
}
假定端点位于uri中,但我不知道应如何使用GraphQL构造它。
如果您能帮助我,我将不胜感激。