apollo.watchQuery导致'ERROR TypeError:Object(...)不是函数'

Mar*_*cel 5 rxjs apollo graphql angular

我目前正在研究Angular(5)和GraphQL的一些基本内容,我遇到了调用watchQuery方法的一些问题.一旦我调用该方法,我的组件崩溃并返回以下错误:

ERROR TypeError: Object(...) is not a function

我在网上搜索了一个解决方案,但我找不到合适的解决方案.我的环境包含以下库:

  • apollo-angular:^ 1.1.0
  • apollo-angular-link-http:^ 1.1.0
  • apollo-cache-inmemory:^ 1.2.2
  • apollo-client:^ 2.3.2
  • graphql:^ 0.13.2
  • graphql-tag:^ 2.9.2
  • rxjs:^ 5.5.6

我有一个带有一些导入和链接的sharedModule:

export class SharedModule {
  constructor(apollo: Apollo, httpLink: HttpLink) {
    apollo.create({
      link: httpLink.create({uri: 'baseUri/graphql'}),
      cache: new InMemoryCache()
    });
  }
}
Run Code Online (Sandbox Code Playgroud)

我在列表组件中有以下代码:

getMovies() {
  this.movies = this.apollo.watchQuery<Query>({    // <= where my error occurs
    query: gql`
      query {
        movies {
          id
          title
          genres
        }
      }
    `
  })
    .valueChanges
    .pipe(map((result) => result.data.movies));
}
Run Code Online (Sandbox Code Playgroud)

完整错误包含以下代码行:

ERROR TypeError: Object(...) is not a function
   at new QueryRef (QueryRef.js:6)
   at ApolloBase.watchQuery (Apollo.js:30)
   at MovieListComponent.getMovies (movie-list.component.ts:37)
   at MovieListComponent.ngOnInit (movie-list.component.ts:29)
Run Code Online (Sandbox Code Playgroud)

如果有人有任何建议或问题,请告诉我.

小智 0

您应该尝试降级grapqhgraphql-tag