【发布时间】:2022-08-17 08:36:29
【问题描述】:
我刚刚开始学习 Expo 和 AWS Amplify,并将错误的来源缩小到我调用的 GraphQL 订阅。这给出了以下错误消息:
\"error\": Object {
\"errors\": Array [
Object {
\"message\": \"Connection failed: NetInfo must be passed to networkMonitor to enable reachability in React Native\",
},
],
},
和堆栈跟踪:
at node_modules\\expo\\build\\environment\\react-native-logs.fx.js:null in warn
at App.tsx:null in subscribe$argument_0.error
at node_modules\\zen-observable\\lib\\Observable.js:null in notifySubscription
at node_modules\\zen-observable\\lib\\Observable.js:null in onNotify
at node_modules\\zen-observable\\lib\\Observable.js:null in error
at node_modules\\@aws-amplify\\pubsub\\lib-esm\\PubSub.js:null in observable.subscribe$argument_0.error
at node_modules\\zen-observable\\lib\\Observable.js:null in notifySubscription
at node_modules\\zen-observable\\lib\\Observable.js:null in onNotify
at node_modules\\zen-observable\\lib\\Observable.js:null in error
at node_modules\\@aws-amplify\\pubsub\\lib-esm\\Providers\\AWSAppSyncRealTimeProvider\\index.js:null in __generator$argument_1
at node_modules\\@aws-sdk\\client-s3\\node_modules\\tslib\\tslib.js:null in step
at node_modules\\@aws-sdk\\client-s3\\node_modules\\tslib\\tslib.js:null in <anonymous>
at node_modules\\@aws-sdk\\client-s3\\node_modules\\tslib\\tslib.js:null in fulfilled
at node_modules\\promise\\setimmediate\\core.js:null in tryCallOne
at node_modules\\promise\\setimmediate\\core.js:null in setImmediate$argument_0
at node_modules\\react-native\\Libraries\\Core\\Timers\\JSTimers.js:null in _allocateCallback$argument_0
at node_modules\\react-native\\Libraries\\Core\\Timers\\JSTimers.js:null in _callTimer
at node_modules\\react-native\\Libraries\\Core\\Timers\\JSTimers.js:null in _callReactNativeMicrotasksPass
at node_modules\\react-native\\Libraries\\Core\\Timers\\JSTimers.js:null in callReactNativeMicrotasks
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:null in __callReactNativeMicrotasks
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:null in __guard$argument_0
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:null in __guard
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:null in flushedQueue
我觉得我到处都看了,什么都试过了,比如:
- 确保包版本正确(使用
expo install) - 清除纱线缓存并重新安装包
- 让其他人在他们的计算机上试用(仍然无效)
- 重构次数过多(包括使用 DataStore 订阅 API)
错误在这里生成:
React.useEffect(() => {
const query = API.graphql({
query: Queries.listMessages
}) as Promise<GraphQLResult<ListMessagesQuery>>
query
.then((result) => {
setMessages(uniqBy(sortBy(result.data?.listMessages?.items as Message[], \'createdAt\'), \'id\'))
})
.catch((error) => {
console.error(error)
})
const sub = (API.graphql({
query: Subscriptions.onMutateMessage,
variables: { roomId: \"1\" }
}) as unknown as Observable<SubscriptionValue<OnMutateMessageSubscription>>
).subscribe({
next: (resp: SubscriptionValue<OnMutateMessageSubscription>) => {
const msg: Msg = resp.value.data.onMutateMessage!
setMessages((msgs) => uniqBy(sortBy([...msgs, msg], \'createdAt\'), \'id\'))
},
error: (error: any) => console.warn(error)
})
return () => sub.unsubscribe()
}, [])
其余代码可以在this repo 中找到。
非常感谢此阶段的任何帮助。
标签: javascript react-native graphql expo aws-amplify