![](/img/trans.png)
[英]`Duplex.from()` throws `The "iterable" argument must be an instance of Iterable. Received an instance of Object`
[英]apollo “Subscription field must return Async Iterable. Received: undefined”
我有一个触发通道事件'countIncr'的变体,但是我看不到活动有效负载对应的活动订阅事件。
更新:我对此发布内容进行了一些更新,现在我更改标题以更代表我的位置。
我收到了graphqlPlayground错误
"Subscription field must return Async Iterable. Received: undefined"
TGRstack复制我遇到了麻烦: https : //github.com/TGRstack/tgr-apollo-subscription-example-microservice/
在没有TGRstack的情况下进行工作复制: https : //github.com/Falieson/fullstack-apollo-subscription-example
前端: https : //github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-ui/src/app/routes/Home/HomePage.tsx
const COUNTER_SUBSCRIPTION = gql`
subscription onCountIncr {
count
}
`
const Counter = () => (
<Subscription
subscription={COUNTER_SUBSCRIPTION}
>
{({ data, loading }) => {
console.log({loading, data})
return loading
? <h1>Loading ...</h1>
: data.count
? <h2>Counter: {data.count}</h2>
: <h1>Counter Subscription Not Available</h1>
}}
</Subscription>
)
BE解析器: https : //github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-service/src/gql/Resolvers.ts
是模式: https : //github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-service/src/gql/Schema.ts
BE控制器: https : //github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-service/src/gql/Counter.ts
const count = {
resolve: data => {
console.log('CounterSub>', {data})
return data
},
subscribe: () => pubsub.asyncIterator(['countIncr'])
}
const CounterSubscriptions = {
count
}
async function countIncr(root: any, args: any, context: any) {
const count = Counter.increment()
await pubsub.publish('countIncr', count )
console.log('countIncr', '>>>', { count })
return count
}
阅读完Readme.md中的#入门指南后,这是服务日志
[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
更新
如果您尝试克隆存储库,并且在运行nps后无法正常运行,因为nps setup
缺少一个步骤。 我已经改进了nps setup
,将更新推送到了堆栈中。
更新2
每次最新提交时更新的代码和有问题的链接
更新3
有人建议pubsub
应该是单个导入。 我已经更新了代码,但这创建了一个新错误:
Error: Apollo Server requires either an existing schema, modules or typeDefs
更新4
许多次要尝试查找导入/导出错误(?)的小更改现在得到了错误。 我通过加强导入来解决了该错误(存在索引文件无法正确导出的问题)。
"message": "Subscription field must return Async Iterable. Received: undefined"
在没有TGRstack的情况下进行工作复制: https : //github.com/Falieson/fullstack-apollo-subscription-example
更新5
我对一堆东西进行了分解/分解,以便更轻松地跟踪正在发生的事情,但仍然遇到相同的错误
我在2个地方解决了这个问题
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,
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.