一个组件上的Apollo客户端查询触发另一个组件上的WatchQuery-如何停止它?

时间:2019-06-18 14:14:57

标签: graphql apollo apollo-client

这是Angular Apollo客户,但我对此表示怀疑。

我使用watchQuery在组件的数据表上显示数据库中的成员列表。效果很好。

如果我单击一个按钮在模式窗口,另一个组件中查看单个成员的个人资料详细信息,并将该个体的ID传递给查询,那么我将从数据库中收到该成员的对象,该对象包含的属性比成员列表更多在桌子上。这是我想要的结果。我不在内存缓存中使用。

查询的名称不同。

问题是模式窗口watchQuery导致列表组件的watchQuery再次运行,我不想对服务器造成不必要的影响。 (它没有为该watchQuery调用Angular函数。这不是Angular问题。我对此进行了测试。)

如果我在列表组件上使用apollo.query,则服务器没有其他命中。但是,我想使用watchQuery作为列表​​,但没有副作用。 (模态窗口的apollo.query没什么区别。)

fetchPolicy:模式查询中的“仅网络”似乎没用。

列表组件查询:

this.apollo
     .watchQuery({
        query: getAllMembers,
      })
      .valueChanges
      .pipe(
          tap(returnedData => {
            ... does some stuff to one of the returned properties...
          })
        )
      .subscribe(result => {
          this.dataSource.data = result.data['getMembers'];
          console.log('errors in getAllRecords', result.errors)
        });

模式窗口查询:

this.apollo
      .watchQuery({   // This watchQuery is somehow calling the list's 
            // watchQuery.  There is no code anywhere that does that and         
            // there were no problems with the original REST code.  This is 
            // a GraphQL thing.
        fetchPolicy: 'network-only',
        query: getMemberByID,
        variables: {
          member_id: member_id,
        },
      })
      .valueChanges
      .subscribe(result => {
          let data = result.data['getMember'];
          this.addData(data, skillNames);  // Call function below to populate modal.
          console.log('errors in view-member', result.errors);
        });

0 个答案:

没有答案
相关问题