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

我有一个触发频道事件'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

http://img3.mukewang.com/60af410c0001a9c617980353.jpg

http://img.mukewang.com/60af41150001998814320295.jpg

http://img2.mukewang.com/60af411f0001d90304840195.jpg

http://img1.mukewang.com/60af41280001b55215860096.jpg

http://img3.mukewang.com/60af41320001102c04900170.jpg

http://img.mukewang.com/60af413d0001179a16650509.jpg

前端: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

}


拉丁的传说
浏览 114回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript