符合graphql位置滤波器变量swift中

发布于 2025-01-28 06:22:55 字数 1349 浏览 4 评论 0原文

我的查询在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不及他 2025-02-04 06:22:55

据我了解,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文