AWS AppSync 嵌套解析器 - 如何重用来自父级的参数
嘿哟。我有一个 AppSync 解析器,其中有一个附加到解析器的字段。查询接受的参数与内部解析器所需的参数相同。为了简洁起见,我想从上下文中将其传递下来,而不必指定它。解析器的数据源是 dynamoDB 表 假设架构看起来像
type Query {
getThings(key: String!): AResult!
}
type AResult {
getOtherThings(key: String!): String!
}
我可以构建这样的查询,
query Query {
getThings(key: "123") {
getOtherThings(key: "123")
}
}
这是笨拙且多余的。理想情况下,我只想创建一个如下所示的查询
query Query {
getThings(key: "123") {
getOtherThings
}
}
,并且解析器可以从请求的上下文中提取key
并重用它。 getOtherThings
解析器的请求模板如下所示:
{
"version": "2017-02-28",
"operation": "Query",
"query": {
"expression" : "key = :key",
"expressionValues" : {
":key" : $util.dynamodb.toDynamoDBJson($context.arguments.key)
}
}
}
但是 $context.guments.key
为 null
。 $context.args.key
和 $ctx.args.key
和 $ctx.arguments.key
也是如此。如果我在执行 getThings 时检查请求的日志,我可以看到预期的参数:
{
"logType": "RequestMapping",
"path": [
"getThings"
],
"fieldName": "getThings",
"context": {
"arguments": {
"key": "123"
},
"stash": {},
"outErrors": []
},
"fieldInError": false,
"errors": [],
"parentType": "Query"
}
因此我推测父解析器 (getThings
) 及其父解析器之间的上下文不会持续存在子解析器 (getOtherThings
),但我无法从日志中看出这一点。
这可能吗?我正在搜索 AWS 日志
Heyo. I've got an AppSync resolver with a field that is attached to a resolver. The query accepts an argument that is the same argument the inner resolver would need. For the sake of terseness, I'd like to just pass it down from context instead of having to specify it. The datasource for the resolver is a dynamoDB table
Say the schema looks like
type Query {
getThings(key: String!): AResult!
}
type AResult {
getOtherThings(key: String!): String!
}
I could construct a query as such
query Query {
getThings(key: "123") {
getOtherThings(key: "123")
}
}
Which is clumsy and redundant. Ideally, I'd just want to create a query that looks like
query Query {
getThings(key: "123") {
getOtherThings
}
}
And the resolver can pull key
from the context of the request and reuse it.
The request template for getOtherThings
resolver looks like:
{
"version": "2017-02-28",
"operation": "Query",
"query": {
"expression" : "key = :key",
"expressionValues" : {
":key" : $util.dynamodb.toDynamoDBJson($context.arguments.key)
}
}
}
But $context.guments.key
is null
. As is $context.args.key
and $ctx.args.key
and $ctx.arguments.key
. If I examine the logs from the request when executing getThings
I can see the expected arguments:
{
"logType": "RequestMapping",
"path": [
"getThings"
],
"fieldName": "getThings",
"context": {
"arguments": {
"key": "123"
},
"stash": {},
"outErrors": []
},
"fieldInError": false,
"errors": [],
"parentType": "Query"
}
So I surmise that the context does not persist between the parent resolver (getThings
) and its child resolver (getOtherThings
), but I can't make this out from the logs.
Is this even possible - I'm coming up dry on searching through AWS logs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案就在
ctx.source
中。 ctx.source 是父字段的映射,因此我可以从那里获取它。The answer lies in
ctx.source
.ctx.source
is a map of the parent field, so I can grab it from there.