AWS Amplify GraphQL订阅过滤器返回全部数据,需额外配置吗?
AWS Amplify GraphQL订阅过滤器不生效,除了添加filter对象还需额外配置吗?
使用AWS Amplify GraphQL API时,订阅过滤器除了在订阅选项中添加filter对象外,是否需要额外配置?官方文档显示只需在订阅中添加过滤器即可,但实际测试下来过滤器并未生效。
我编写的订阅代码如下:
const subscribeDeviceState = () => { const sub = API.graphql( graphqlOperation(onUpdateDevice, { filter: { id: { eq: "abc-123" }, }, }) ).subscribe({ next: ({ provider, value }) => { console.log({ provider, value }); processDeviceData(value.data.onUpdateDevice); }, error: (error) => console.warn(error), }); return sub; };
我尝试了filter对象中的多个参数,但只要有任何Device条目更新,订阅都会返回该条目数据,即使过滤器条件不匹配。
我的schema为手动编写,后续通过Amplify推送操作生成了对应的GraphQL代码和操作:
schema.graphql
type Device @model @auth(rules: [{ allow: private, provider: userPools }]) { id: ID! name: String reported: AWSJSON features: AWSJSON }
Amplify自动生成的订阅操作代码如下:
export const onUpdateDevice = ` subscription OnUpdateDevice { onUpdateDevice { id name reported features createdAt updatedAt } } `;
内容的提问来源于stack exchange,提问作者Chris Baum
相关产品推荐
相关产品推荐

