【问题标题】:Migrating from Angular 5 to Angular 6 i got these error TypeError: You provided an invalid object where a stream was expected从 Angular 5 迁移到 Angular 6 我得到了这些错误 TypeError: You provide an invalid object where a stream is expected
【发布时间】:2018-10-19 01:25:17
【问题描述】:

这些代码在 Angular 5 中可以正常工作,但是在迁移到 Angular 6 时,我收到了错误消息:

ERROR Error: Uncaught (in promise): TypeError: You provide an invalid 期望流的对象。你可以提供一个 Observable, 承诺、数组或可迭代。 TypeError:您在预期流的位置提供了无效对象。您可以提供 Observable、Promise、Array 或 Iterable。 在 subscribeTo (subscribeTo.js:41) 从 (from.js:17) 在新的 QueryRef (QueryRef.js:6) 在 Apollo.push../node_modules/apollo-angular/Apollo.js.ApolloBase.watchQuery (Apollo.js:29) 在contacts.service.ts:75

Here is the code

我真的很感激一些可能导致此错误的指示

【问题讨论】:

    标签: angular typescript apollo apollo-client angular6


    【解决方案1】:

    我刚刚遇到了同样的错误。 我通过将 watchQuery 的用法替换为 query 来修复它。

    旧代码示例:

    return this.apollo
      .watchQuery<GetPartnerCollectionsQuery>({
        query: getPartnerCollectionsQuery,
        variables,
      })
      .valueChanges.pipe(
        map(result => {
          return result.data.getPartnerCollections.collections;
        })
      );
    

    示例新代码:

    return this.apollo
      .query<GetPartnerCollectionsQuery>({
        query: getPartnerCollectionsQuery,
        variables,
      })
      .pipe(
        map(result => {
          return result.data.getPartnerCollections.collections;
        })
      );
    

    有点奇怪,watchQuery 似乎不再起作用,因为它似乎是“正确”的查询类型,但希望这只是一个临时错误。

    编辑:刚刚找到了这个错误的官方票:

    https://github.com/apollographql/apollo-angular/issues/545

    编辑 2::找到官方解决方案,将您的软件包更新到修复此错误的新版本:

    "apollo-angular": "^1.1.0-rc.0",
    "apollo-angular-link-http": "^1.1.0-rc.0",
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-19
      • 2023-04-08
      • 2018-10-18
      • 2019-09-24
      • 1970-01-01
      • 1970-01-01
      • 2019-03-26
      相关资源
      最近更新 更多