AWS Appsync GraphQL订阅事件中的空数据
我有一个使用AWS AppSync服务提供的GraphQL API的应用程序。它使用GraphQL订阅来接近实时发送不同客户端之间的消息。有一个突变pushItems
配置有解析器,该解析器具有“无”数据源,并将请求数据未修改的请求数据转发至subscription OnIteMchange
。
该应用程序已经有几年没有使用了,现在当我尝试触发订阅事件时,我会在订阅客户端上遇到错误。以前这无问题。
{
"data": {
"onItemChange": null
},
"errors": [
{
"message": "Cannot return null for non-nullable type: 'ID' within parent 'Item' (/onItemChange/id)",
"path": [
"onItemChange",
"id"
]
}
]
}
错误消息建议item
对象中的属性id
是无效的,但是当我从AWS Appsync Web控制台发送带有硬编码字符串的突变时ID,即使突变响应包含应将应该转发给订阅客户端的正确数据,我仍然会遇到相同的问题。
我在AWS AppSync中创建了最小的配置来重现该问题,如下所述。 AppSync服务是否有可能改变了过去几年处理订阅数据的方式?
GraphQL架构
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
type Query {
getItem(id: ID!): Item
}
type Mutation {
pushItems(
items: [ItemInput]
): [Item]}
type Subscription {
onItemChange: Item
@aws_subscribe(
mutations: [
"pushItems"
]
)
}
type Item {
id: ID!
}
input ItemInput {
id: ID!
}
解析器映射用于突变pushItems
请求:
{
"version" : "2017-02-28",
"payload": $util.toJson($context.arguments.items)
}
响应:
$util.toJson($context.result)
示例查询
以下查询可用于在AWS Appsync Web控制台中重现该问题。首先,订阅onIteMchange
:
subscription MySubscription {
onItemChange {
id
}
}
然后(在其他浏览器选项卡中)将一些数据发送到pushitems
:
mutation MyMutation {
pushItems(items: [{id: "foo"}]) {
id
}
}
I have an application that uses a GraphQL API, provided by the AWS AppSync service. It uses GraphQL subscriptions to send messages between different clients in near real time. There is a mutation pushItems
that's configured with a resolver, which has a 'none' data source and forwards the request data unmodified to the subscription onItemChange
.
The app hasn't been used for a couple of years, and now when I attempt to trigger a subscription event, I get an error on the subscribed client. Previously this worked without issues.
{
"data": {
"onItemChange": null
},
"errors": [
{
"message": "Cannot return null for non-nullable type: 'ID' within parent 'Item' (/onItemChange/id)",
"path": [
"onItemChange",
"id"
]
}
]
}
The error message suggests that the property id
within the Item
object is null, however when I send a mutation from the AWS AppSync web console with a hard-coded string for the item ID, I still get the same issue, even though the mutation response contains the correct data that should be forwarded to the subscribed client.
I've created a minimal configuration in AWS AppSync to reproduce the issue, which is detailed below. Is it possible that the AppSync service has changed the way it handles subscription data in the last few years?
GraphQL schema
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
type Query {
getItem(id: ID!): Item
}
type Mutation {
pushItems(
items: [ItemInput]
): [Item]}
type Subscription {
onItemChange: Item
@aws_subscribe(
mutations: [
"pushItems"
]
)
}
type Item {
id: ID!
}
input ItemInput {
id: ID!
}
Resolver mappings for mutation pushItems
Request:
{
"version" : "2017-02-28",
"payload": $util.toJson($context.arguments.items)
}
Response:
$util.toJson($context.result)
Example queries
The following queries can be used to reproduce the issue in the AWS AppSync web console. First, subscribe to onItemChange
:
subscription MySubscription {
onItemChange {
id
}
}
Then (in a different browser tab) send some data to pushItems
:
mutation MyMutation {
pushItems(items: [{id: "foo"}]) {
id
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在返回突变中的一组项目,因此您应该将订阅返回类型更新为[项目]
You are returning Set of items in the mutation so you should update subscription return type to [Item]