Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AWS Amplify React GraphQL客户端未触发订阅_Graphql_Aws Amplify_Aws Appsync_Amplifyjs - Fatal编程技术网

AWS Amplify React GraphQL客户端未触发订阅

AWS Amplify React GraphQL客户端未触发订阅,graphql,aws-amplify,aws-appsync,amplifyjs,Graphql,Aws Amplify,Aws Appsync,Amplifyjs,我正在使用Amplify/AppSync创建一个应用程序,我希望该应用程序能够随时刷新视频列表 这是我第一次使用GraphQL,所以我可能遗漏了一些东西,我已经在谷歌上搜索过类似的问题,但大多数问题实际上都没有答案。 我正在使用light AWS Amplify GraphQL客户端库,想知道是否值得迁移到AppSync/Apollo,但是,文档中指出,如果您不需要缓存/脱机功能,则不需要 我已经在AppSync上创建了我的应用程序,然后使用amplify codegen 我的订阅架构: typ

我正在使用Amplify/AppSync创建一个应用程序,我希望该应用程序能够随时刷新视频列表

这是我第一次使用GraphQL,所以我可能遗漏了一些东西,我已经在谷歌上搜索过类似的问题,但大多数问题实际上都没有答案。 我正在使用light AWS Amplify GraphQL客户端库,想知道是否值得迁移到AppSync/Apollo,但是,文档中指出,如果您不需要缓存/脱机功能,则不需要

我已经在AppSync上创建了我的应用程序,然后使用
amplify codegen

我的订阅架构:

type Subscription {
    onCreateVideoOnDemand(
        guid: String,
        thumbNailUrl: [String],
        startTime: String,
        workflowStatus: String,
        srcVideo: String
    ): VideoOnDemand
        @aws_subscribe(mutations: ["createVideoOnDemand"])
    onUpdateVideoOnDemand(
        guid: String,
        thumbNailUrl: [String],
        startTime: String,
        workflowStatus: String,
        srcVideo: String
    ): VideoOnDemand
        @aws_subscribe(mutations: ["updateVideoOnDemand"])
    onDeleteVideoOnDemand(
        guid: String,
        thumbNailUrl: [String],
        startTime: String,
        workflowStatus: String,
        srcVideo: String
    ): VideoOnDemand
        @aws_subscribe(mutations: ["deleteVideoOnDemand"])
}
然后在我的代码中执行以下操作:

import { Connect } from 'aws-amplify-react';
import { listVideoOnDemands } from './graphql/queries';
import { onCreateVideoOnDemand } from './graphql/subscriptions';

...

        <Connect
          query={graphqlOperation(listVideoOnDemands)}
          subscription={graphqlOperation(onCreateVideoOnDemand)}
          onSubscriptionMsg={(prev, { onCreateVideoOnDemand }) => {
            prev.listVideoOnDemands.items.push(onCreateVideoOnDemand);
            console.log(prev.listVideoOnDemands.items);
            return prev;
          }}
        >
          {({ data: { listVideoOnDemands }, loading, error }) => {
            if (loading) return "Loading"
            if (error) return "Error"
            return <List data={listVideoOnDemands.items} />
        </Connect>
从“aws放大反应”导入{Connect};
从“/graphql/querys”导入{listVideoOnDemands};
从“/graphql/subscriptions”导入{onCreateVideoOnDemand};
...
{
prev.ListVideoOnDemand.items.push(onCreateVideoOnDemand);
日志(上一个列表VideoOnDemands.items);
返回上一个;
}}
>
{({data:{listVideoOnDemands},正在加载,错误})=>{
如果(加载)返回“加载”
if(error)返回“error”
返回
列表显示正确,但在数据库上创建新项时不会更新(当然,如果手动刷新页面,它会工作)。 要在数据库上创建一个新项,我将转到AWS AppSync控制台->查询->然后在那里运行createVideoOnDemand…该行已成功添加到DynamoDB表中,但是,它不会触发我代码上的事件,
console.log(prev.listVideoOnDemands.items);
行永远不会被调用

我还尝试了不使用
,而是在useffect调用上使用
subscribe
方法(对于
组件willmount
事件),如图所示,没有任何区别

知道为什么会这样吗


PS:我还想在Connect上集成更多订阅,但我找不到关于是否可能的任何信息,这里只有一个问题,目前还没有答案。

您在浏览器开发工具的网络检查器中看到websocket连接吗?您在浏览器开发工具的网络检查器中看到websocket连接吗v工具?