简体   繁体   English

“订阅字段必须返回异步可迭代。 收到:未定义”

[英]apollo “Subscription field must return Async Iterable. Received: undefined”

I have a mutation that fires the channel event 'countIncr', but I don't see the active corresponding subscription fire with the event payload. 我有一个触发通道事件'countIncr'的变体,但是我看不到活动有效负载对应的活动订阅事件。

UPDATE: I've made several updates to this posting and now I'm changing the title to be more representative of where I am. 更新:我对此发布内容进行了一些更新,现在我更改标题以更代表我的位置。

I'm getting a graphqlPlayground error 我收到了graphqlPlayground错误

"Subscription field must return Async Iterable. Received: undefined"

TGRstack reproduction i'm having trouble with: https://github.com/TGRstack/tgr-apollo-subscription-example-microservice/ TGRstack复制我遇到了麻烦: https : //github.com/TGRstack/tgr-apollo-subscription-example-microservice/

Working Reproduction without TGRstack: https://github.com/Falieson/fullstack-apollo-subscription-example 在没有TGRstack的情况下进行工作复制: https : //github.com/Falieson/fullstack-apollo-subscription-example

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 Frontend: https://github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-ui/src/app/routes/Home/HomePage.tsx 前端: 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 Resolvers: https://github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-service/src/gql/Resolvers.ts BE解析器: https : //github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-service/src/gql/Resolvers.ts

BE Schema: https://github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-service/src/gql/Schema.ts 是模式: https : //github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-service/src/gql/Schema.ts

BE Controller: https://github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-service/src/gql/Counter.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
}

Here is the service log after you've run through the #getting started instructions in the Readme.md 阅读完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

UPDATE 更新

Incase you've tried to clone the repo and after running nps it didn't work its because there was a step missing in nps setup . 如果您尝试克隆存储库,并且在运行nps后无法正常运行,因为nps setup缺少一个步骤。 I've pushed an update to the stack with the nps setup improved. 我已经改进了nps setup ,将更新推送到了堆栈中。

UPDATE 2 更新2

updated code and links in question per latest commit 每次最新提交时更新的代码和有问题的链接

UPDATE 3 更新3

Some people have suggested that pubsub should be a single import. 有人建议pubsub应该是单个导入。 I've updated the code but this creates a new error: 我已经更新了代码,但这创建了一个新错误:

Error: Apollo Server requires either an existing schema, modules or typeDefs

UPDATE 4 更新4

numerous minor changes trying to hunt down import/export bugs(?) now getting the error. 许多次要尝试查找导入/导出错误(?)的小更改现在得到了错误。 I fixed this error by hardening imports (there was some issue w/ the index file not properly exporting). 我通过加强导入来解决了该错误(存在索引文件无法正确导出的问题)。

"message": "Subscription field must return Async Iterable. Received: undefined"

Working Reproduction without TGRstack: https://github.com/Falieson/fullstack-apollo-subscription-example 在没有TGRstack的情况下进行工作复制: https : //github.com/Falieson/fullstack-apollo-subscription-example

Update 5 更新5

I demodularized/decomposed a bunch of things to make it easier to trace whats going on but still getting the same error 我对一堆东西进行了分解/分解,以便更轻松地跟踪正在发生的事情,但仍然遇到相同的错误

I solved this issue in 2 places 我在2个地方解决了这个问题

  1. ApolloServer.installSubscriptionHandler() TEMPORARILY replacing middleware.apolloSubscriptions() . ApolloServer.installSubscriptionHandler() 暂时替换middleware.apolloSubscriptions()。 I configure the subscriptions middleware following this guide: https://www.apollographql.com/docs/graphql-subscriptions/express so I'm going to guess there's something messed up w/ the version of one of those packages or the guide itself. 我按照该指南配置了订阅中间件: https : //www.apollographql.com/docs/graphql-subscriptions/express,所以我猜想其中一些软件包的版本或指南本身有些混乱。

    ApolloServer.installSubscriptionHandlers(ws)

    const listener = ws.listen({port: config.PORT}, () => {
      middleware.apolloSubscriptions(ws)
      // middleware.apolloSubscriptions(ws)
  1. terminatingLink and getMainDefinition are necessary for the client https://github.com/TGRstack/tgr-apollo-subscription-example-microservice/commit/75b6165f2dc1d035a41f1129f7386a1e18c7ba53#diff-2c47ef33b8ed0e4c893cbc161bcf7814R37 客户端必须使用terminatedLink和getMainDefinition https://github.com/TGRstack/tgr-apollo-subscription-example-microservice/commit/75b6165f2dc1d035a41f1129f7386a1e18c7ba53#diff-2c47ef33b8ed0e4c893cbc161bcf7814R37
  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.

相关问题 `Duplex.from()` 抛出`“可迭代”参数必须是可迭代的实例。 接收到 Object 的实例 - `Duplex.from()` throws `The "iterable" argument must be an instance of Iterable. Received an instance of Object` 使普通对象可迭代。(javascript) - Making plain objects iterable.(javascript) ERROR 错误:未捕获(承诺):TypeError:this.products 不可迭代。 (但它是可迭代的) - ERROR Error: Uncaught (in promise): TypeError: this.products is not iterable. (but it is iterable) GraphQL、React、Apollo - 预期可迭代,但没有找到字段“...” - GraphQL, React, Apollo - Expected Iterable, but did not find one for field "..." 应用程序有效,但会产生错误:Connect(App)中的mapDispatchToProps()必须返回一个普通对象。 而是收到未定义 - Aplication works but generates an error: mapDispatchToProps() in Connect(App) must return a plain object. Instead received undefined 异步 function 返回未定义 - async function return undefined 返回promises的函数必须是异步的 - functions that return promises must be async Vue:Async Apollo mixin function 打印一个值,但返回 undefined - Vue: Async Apollo mixin function prints a value, but returns undefined 需要在react-apollo中使用从GraphQL订阅接收的数据的setstate() - Need to use setstate() of data received from GraphQL subscription in react-apollo React-Redux容器在Connect(ModalRoot)中抛出“ mapStateToProps()”时必须返回一个普通对象。 而是收到未定义的信息。” - React-Redux container throws “mapStateToProps() in Connect(ModalRoot) must return a plain object. Instead received undefined.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM