符合graphql位置滤波器变量swift中
我的查询在GraphIQL中使用内容为API有效,但是当我使用Swift传递相同的变量和结构时,它将无法正常工作。我如何将lat,lon,半径传到查询中?
查询
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)
}
}
}
}
}
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)
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,
location_within_circle
是属于GraphQl的特定内容实现的属性。您不能指望在其他实现中可以使用它。
例如, 8base的实现一个完全不同的语法。
As far as I understand,
location_within_circle
is an attribute that belongs to the specific Contentful implementation of GraphQL.You cannot expect to have it available in other implementations.
For example, 8base's implementation uses a whole different syntax.