'Contentful Graphql Location Filter Variables in Swift
My Query is valid in GraphiQL using the Contentful API but when I pass in the same variables and structure using Swift it won't work. How do I pass lat, lon, radius into the query?
Query
query MapQuery($circle: Circle) {
mapCollection(
where: { location_within_circle: $circle }
) {
items {
title
subtitle
location {
lat
lon
}
}
}
}
Variables:
{
"circle": {
"lat" : 11.11,
"lon": -111.11,
"radius": 100,
}
}
Swift Code
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)
}
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
