Javascript “阿波罗”;订阅字段必须返回Async Iterable。收到:未定义;
我有一个触发通道事件“countIncr”的变异,但我没有看到激活的对应订阅触发事件负载 更新:我对这篇帖子做了几次更新,现在我正在更改标题,以便更能代表我所在的位置。 我得到一个图形错误Javascript “阿波罗”;订阅字段必须返回Async Iterable。收到:未定义;,javascript,reactjs,typescript,graphql,apollo,Javascript,Reactjs,Typescript,Graphql,Apollo,我有一个触发通道事件“countIncr”的变异,但我没有看到激活的对应订阅触发事件负载 更新:我对这篇帖子做了几次更新,现在我正在更改标题,以便更能代表我所在的位置。 我得到一个图形错误 "Subscription field must return Async Iterable. Received: undefined" TGRstack复制我遇到问题: 无TGRstack的工作复制: 前端: 这是您在Readme.md中运行#getting started(入门)说明后的服务日志 [
"Subscription field must return Async Iterable. Received: undefined"
TGRstack复制我遇到问题:
无TGRstack的工作复制:
前端:
这是您在Readme.md中运行#getting started(入门)说明后的服务日志
[FE] GET /favicon.ico 200 2.465 ms - 1551 # WEBCLIENT LOADED
[BE] CounterSub> { data: undefined } # SUBSCRIPTION REQUEST
[BE] { data: [Object: null prototype] { count: null } } # SUBSCRIPTION RESULT
[BE] POST / 200 21.254 ms - 24
[BE] 2019-05-10 11:37:20 [info]: HELLO # APOLLO CLIENT CONNECTED AGAIN (why always 2?)
[BE] countIncr >>> { count: 1 } # MUTATION REQUEST
[BE] { data: [Object: null prototype] { countIncr: 1 } } # MUTATION RESPONSE
[BE] POST / 200 13.159 ms - 25
[BE] countIncr >>> { count: 2 } # MUTATION REQUEST
[BE] { data: [Object: null prototype] { countIncr: 2 } } # MUTATION RESPONSE
[BE] POST / 200 4.380 ms - 25
更新
如果您试图克隆repo,但在运行nps后,由于nps设置中缺少一个步骤,它无法正常工作。我已通过改进的nps设置
将更新推送到堆栈中
更新2
每次最新提交更新的代码和相关链接
更新3
有些人建议将pubsub
作为单一导入。我已更新代码,但这会产生一个新错误:
Error: Apollo Server requires either an existing schema, modules or typeDefs
更新4
许多小的改变试图找出导入/导出错误(?)现在得到了错误。我通过强化导入修复了此错误(索引文件未正确导出时出现了一些问题)
无TGRstack的工作复制:
更新5
我解调/分解了一堆东西,以便更容易跟踪发生了什么,但仍然得到相同的错误我在两个地方解决了这个问题
ApolloServer.installSubscriptionHandler()临时替换中间件.apolloSubscriptions()。我按照这个指南配置订阅中间件:所以我猜可能是这些包的版本或指南本身出了问题
terminatingLink和getMainDefinition对于客户端是必需的
async function countIncr(root: any, args: any, context: any) {
const count = Counter.increment()
await pubsub.publish('countIncr', count )
console.log('countIncr', '>>>', { count })
return count
}
[FE] GET /favicon.ico 200 2.465 ms - 1551 # WEBCLIENT LOADED
[BE] CounterSub> { data: undefined } # SUBSCRIPTION REQUEST
[BE] { data: [Object: null prototype] { count: null } } # SUBSCRIPTION RESULT
[BE] POST / 200 21.254 ms - 24
[BE] 2019-05-10 11:37:20 [info]: HELLO # APOLLO CLIENT CONNECTED AGAIN (why always 2?)
[BE] countIncr >>> { count: 1 } # MUTATION REQUEST
[BE] { data: [Object: null prototype] { countIncr: 1 } } # MUTATION RESPONSE
[BE] POST / 200 13.159 ms - 25
[BE] countIncr >>> { count: 2 } # MUTATION REQUEST
[BE] { data: [Object: null prototype] { countIncr: 2 } } # MUTATION RESPONSE
[BE] POST / 200 4.380 ms - 25
Error: Apollo Server requires either an existing schema, modules or typeDefs
"message": "Subscription field must return Async Iterable. Received: undefined"
ApolloServer.installSubscriptionHandlers(ws)
const listener = ws.listen({port: config.PORT}, () => {
middleware.apolloSubscriptions(ws)
// middleware.apolloSubscriptions(ws)
private _terminatingLink = split(
({ query }) => {
const { kind, operation } = getMainDefinition(query)
return (
kind === 'OperationDefinition' && operation === 'subscription'
)
},
this._wsLink,
this._httpLink,
)