2

为什么没有为我调用 updateQueries?我认为我正在按照文档所说的进行操作,并将我的代码与其他类似问题进行了比较。我错过了什么?

软件包版本:

apollo-angular@0.13.0
apollo-client@1.0.4

我的代码:

//same es6 module, above my class definition
const RecentSearchesQuery = gql`
  query recentSearch {
    recentSearch {
      id
      query
      lastUpdated
      userId
    }
  }
`;

const RecentSearchesMutation = gql`
  mutation recentSearchSave($query:String!) {
    recentSearchSave(query: $query)
  }
`;

...

//my class method
updateRecentSearches(query: string) {
const updateQueries: MutationQueryReducersMap = {
  RecentSearch: (prev: Object, {mutationResult}) => {
    //execution doesn't get here
    debugger;
    alert('updateQueries handler in RecentSearchesMutation mutation for recentSearch');
    ...
  }
};

return new Promise((resolve, reject) => {
  this.apollo.mutate<any>({
    mutation: RecentSearchesMutation,
    variables: {query},
    updateQueries
  })
  .subscribe({
    next: ({data}) => {
      resolve();
    },
    error: (error: ApolloError) => {
      reject(error);
    }
  });
});
4

1 回答 1

0

我从来没有开始updateQueries工作,但推荐的方法是现在使用update(也是一个突变选项)。使用update对我有用,这篇文章很有帮助:

https://dev-blog.apollodata.com/apollo-clients-new-imperative-store-api-6cb69318a1e3

于 2017-04-25T21:02:53.187 回答