JSON Scalar 在 iOS apollo 客户端中抛出 JSONDecondingError.couldNotConvert
我们有一个名为 JSON 的自定义标量类型,当我们想要发送非结构化数据时使用它。 当尝试使用 Apollo 访问该字段(甚至只是尝试打印它)时,我们收到以下错误:
Apollo.GraphQLResultError(path: productRequests.collection.0.item.businessKey,
underlying: Apollo.JSONDecodingError.couldNotConvert(value: {
group = POL;
item = “32-43-1839TT40”;
prefix = MB;
warehouse = RAD;
}, to: Swift.String)))
我不确定为什么转换为字符串时会出现问题。另外,我们如何获取字典值而不是字符串?
这可能有点类似于#23。我在那里尝试了建议的解决方案(只是将 JSON 别名为 [String : Any?]),但它给出了一堆编译错误。
以下是我的询问和回复。
query ProductTable($pageInfo: PageInfo!)
{
productRequests(pageInfo: $pageInfo) {
collection {
id
item {
id
businessKey
}
}
}
}
Response :
{
"data": {
"productRequests": {
"collection ": [{
"id": "0",
"item": {
"businessKey": {
"group": "POL",
"warehouse": "RAD",
"prefix": "MB",
"item": "33 - 44 - 1939 TT40"
}
}
}]
}
}
}
如何解决解码问题,有人可以帮忙解决吗?
提前致谢。
We have a custom scalar type called JSON, which is used when we want to send unstructured data.
When trying to access the field using Apollo (even just trying to print it), we get the following error:
Apollo.GraphQLResultError(path: productRequests.collection.0.item.businessKey,
underlying: Apollo.JSONDecodingError.couldNotConvert(value: {
group = POL;
item = “32-43-1839TT40”;
prefix = MB;
warehouse = RAD;
}, to: Swift.String)))
I'm not sure why it would have a problem converting to a String. Also, how can we get the Dictionary value rather than a String?
This may be somewhat similar to #23. I tried the proposed solution there (just aliasing JSON to [String : Any?]) but it gave a bunch of compile errors.
Below is my query and response.
query ProductTable($pageInfo: PageInfo!)
{
productRequests(pageInfo: $pageInfo) {
collection {
id
item {
id
businessKey
}
}
}
}
Response :
{
"data": {
"productRequests": {
"collection ": [{
"id": "0",
"item": {
"businessKey": {
"group": "POL",
"warehouse": "RAD",
"prefix": "MB",
"item": "33 - 44 - 1939 TT40"
}
}
}]
}
}
}
How to resolve the decoding issue, can any one help on this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 GitHub 中发现了一个类似的问题,其中包含一个解决方案:https: //github.com/apollographql/apollo-ios/issues/36#issuecomment-452515484
这是一个相当过时的线程,但认为它可以为您提供一些如何继续的方向。
I found a similar issue in GitHub that includes a workaround solution here: https://github.com/apollographql/apollo-ios/issues/36#issuecomment-452515484
This is a fairly dated thread but thought it could give you some direction on how to proceed.