![](/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.