Swift 中内容丰富的 Graphql 位置过滤变量

问题描述 投票:0回答:1

我的查询在使用 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)
                        
                    }
                }
            }
        }
    }
swift apollo contentful
1个回答
0
投票

据我了解,

location_within_circle
是一个属性,属于GraphQL的具体Contentful实现。

您不能指望在其他实现中也能使用它。

例如,8base 的实现使用完全不同的语法。

© www.soinside.com 2019 - 2024. All rights reserved.