【发布时间】:2019-02-03 19:01:30
【问题描述】:
为此苦苦挣扎了一段时间,并且应用程序我将问题的查询名称更改为 getDeviceReadings,我一直在使用 getAllUserDevices(抱歉有任何混淆)
type Device {
id: String
device: String!
}
type Reading {
device: String
time: Int
}
type PaginatedDevices {
devices: [Device]
readings: [Reading]
nextToken: String
}
type Query {
getDevicesReadings(nextToken: String, count: Int): PaginatedDevices
}
然后我在查询 getDevicesReadings 上有一个解析器,它可以正常工作并返回用户迄今为止拥有的所有设备
{
"version": "2017-02-28",
"operation": "Query",
"query" : {
"expression": "id = :id",
"expressionValues" : {
":id" : { "S" : "${context.identity.username}" }
}
}
#if( ${context.arguments.count} )
,"limit": ${context.arguments.count}
#end
#if( ${context.arguments.nextToken} )
,"nextToken": "${context.arguments.nextToken}"
#end
}
现在我想根据源结果返回设备的所有读数,所以我有一个关于 getDevicesReadings/readings 的解析器
#set($ids = [])
#foreach($id in ${ctx.source.devices})
#set($map = {})
$util.qr($map.put("device", $util.dynamodb.toString($id.device)))
$util.qr($ids.add($map))
#end
{
"version" : "2018-05-29",
"operation" : "BatchGetItem",
"tables" : {
"readings": {
"keys": $util.toJson($ids),
"consistentRead": true
}
}
}
使用这样的响应映射..
$utils.toJson($context.result.data.readings)
我运行一个查询
query getShit{
getDevicesReadings{
devices{
device
}
readings{
device
time
}
}
}
这会返回以下结果
{
"data": {
"getAllUserDevices": {
"devices": [
{
"device": "123"
},
{
"device": "a935eeb8-a0d0-11e8-a020-7c67a28eda41"
}
],
"readings": [
null,
null
]
}
}
}
正如您在图像上看到的,主分区键是读数表上的设备,我查看了日志,我有以下内容
抱歉,如果您无法阅读日志,它基本上说有未处理的密钥
以及以下错误信息
"message": "The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 0H21LJE234CH1GO7A705VNQTJVVV4KQNSO5AEMVJF66Q9ASUAAJG)",
我猜我的映射不太正确,我将读数作为我的键传递?
非常感谢任何帮助
【问题讨论】:
标签: amazon-web-services graphql aws-appsync resolver