Javascript 放大未捕获的AppSync订阅(承诺中)
我正在尝试使用AWS amplify GraphQL订阅,如下所示Javascript 放大未捕获的AppSync订阅(承诺中),javascript,reactjs,graphql,aws-amplify,aws-appsync,Javascript,Reactjs,Graphql,Aws Amplify,Aws Appsync,我正在尝试使用AWS amplify GraphQL订阅,如下所示 import Amplify,{ API, Storage, graphqlOperation } from "aws-amplify"; import awsmobile from "../../aws-exports"; Amplify.configure(awsmobile); ... const notiSubscription = API.graphql(graphql
import Amplify,{ API, Storage, graphqlOperation } from "aws-amplify";
import awsmobile from "../../aws-exports";
Amplify.configure(awsmobile);
...
const notiSubscription = API.graphql(graphqlOperation(onCreateNotification)).subscribe({
next: (todoData) => {
console.log(todoData);
},
});
...
onCreateNotification Graphql为
subscription OnCreateNotification {
onCreateNotification {
id
}}
下面是我得到的错误
AWSAppSyncProvider.ts:204 Uncaught (in promise) undefined
rejected @ AWSAppSyncProvider.ts:204
Promise.then (async)
step @ AWSAppSyncProvider.ts:204
(anonymous) @ AWSAppSyncProvider.ts:204
push../node_modules/@aws-amplify/pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js.__awaiter @ AWSAppSyncProvider.ts:204
AWSAppSyncRealTimeProvider._startSubscriptionWithAWSAppSyncRealTime @ AWSAppSyncRealTimeProvider.ts:227
(anonymous) @ AWSAppSyncRealTimeProvider.ts:185
Subscription @ Observable.js:197
subscribe @ Observable.js:279
(anonymous) @ PubSub.ts:171
...
请在这方面帮助我,我的配置也是
"aws_project_region": "us-east-1",
"aws_appsync_graphqlEndpoint": "https://xxx.appsync-api.us-east-1.amazonaws.com/graphql",
"aws_appsync_region": "us-east-1",
"aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
"aws_appsync_apiKey": "xxxx",
您需要在
useffect()
hook中初始化订阅,然后取消订阅
useEffect(() => {
const subscription = API.graphql(graphqlOperation(onCreateNotification))
.subscribe({
next: todoData => {
console.log(todoData);
}
})
return () => subscription.unsubscribe()
}, [])