我的查询在使用 Contentful API 的 GraphiQL 中是有效的,但是当我使用 Swift 传递相同的变量和结构时,它将不起作用。如何将纬度、经度、半径传递到查询中?
查询
query MapQuery($circle: Circle) {
mapCollection(
where: { location_within_circle: $circle }
) {
items {
title
subtitle
location {
lat
lon
}
}
}
}
变量:
{
"circle": {
"lat" : 11.11,
"lon": -111.11,
"radius": 100,
}
}
快速代码
let circle: String = """
{
"circle": {
"lat" : 11.11,
"lon": -111.11,
"radius": 100,
}
}
"""
func queryPlaces() async throws -> GraphQLResult<MapQueryQuery.Data>? {
return await withCheckedContinuation { continuation in
Network.shared.apollo.fetch(query: MapQueryQuery(circle: circle)) { result in
switch result {
case .success(let graphQLResult):
continuation.resume(returning: graphQLResult)
case .failure(let error):
if let error = error as? Never {
continuation.resume(throwing: error)
}
}
}
}
}