Apollo-update()方法被两次调用,两次都使用乐观/伪数据 [英] Apollo - update() method getting called twice, both times with optimistic/fake data

查看:222
本文介绍了Apollo-update()方法被两次调用,两次都使用乐观/伪数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全陷入了阿波罗问题,为此我开了一个GitHub问题,对它的响应为零.

I'm completely stuck on an Apollo problem, for which I've opened a GitHub issue and had zero response on.

我正在使用optimisticResponse调用阿波罗突变.据我了解,它应该工作的方式是两次调用update():首先使用乐观数据,然后再次使用来自网络的实际数据.

I'm calling an Apollo mutation, using optimisticResponse. The way it's supposed to work, as I understand it, is that update() gets called twice: first with the optimistic data, then again with the actual data coming in from the network.

但是由于某种原因,我的代码无法像这样工作.我接到了两个update()电话,都带有乐观数据.

But for some reason, my code is not working like this. I'm getting two update() calls, both with the optimistic data.

这是一个演示此行为的存储库: https://github.com/ffxsam/apollo-更新错误

Here's a repo that demonstrates this behavior: https://github.com/ffxsam/apollo-update-bug

  1. 纱线&&纱线开发人员
  2. 在浏览器中打开,打开控制台
  3. 输入一些文字,然后按Enter键
  4. 在上方重复
  5. 请注意控制台中有关重复键的错误.发生这种情况是因为临时ID"??"没有被真正的UUID取代 (可选)您可以打开Vue DevTools(如果有)并检查数据以查看其不正确
  1. yarn && yarn dev
  2. Open in browser, open console
  3. Enter some text and hit enter
  4. Repeat above
  5. Notice the error in the console about duplicate keys. This is happening because the temporary ID "??" is not being replaced with the real UUID (optional) You can open Vue DevTools if available and inspect the data to see it's incorrect

推荐答案

我正在做一些挖掘工作,我认为我找到了问题的根源. 不幸的是,我没有解决方案.

I was doing some digging and I think I found the source of the problem. Unfortunately, I don't have a solution.

简而言之,问题可能出在aws-appsync使用的名为OfflineLink的网络链接上.

In short, the problem might be with a network link called OfflineLink that is used by aws-appsync.

aws-appsync有一个名为OfflineLink的ApolloLink,它可以插入request函数.

aws-appsync has an ApolloLink called OfflineLink that intervenes with the request function.

发生的事情是这样的:

  1. 您致电$apollo.mutate(...)
  2. ApolloClient.QueryManager使用乐观响应初始化第一次触发您的update的突变.这是在ApolloClient数据存储内部发生的, markMutationResult ,其中
  1. you call $apollo.mutate(...)
  2. ApolloClient.QueryManager initializes the mutation that triggers your update the first time with the optimistic response. That is happening inside ApolloClient data store, markMutationInit calls markMutationResult that calls your update.
  3. The graphql operation executes and reaches the OfflineLink in the network chain.
  4. OfflineLink creates a new observer and dispatches the mutation info as an action.
  5. The next line of OfflineLink calls the observer's next function with the optimisticResponse as if it was the execution result!
  6. This triggers your update the second time with the result which is actually the optimisticResponse.
  7. OfflineLink calls the observer's complete which resolves your promise.
  8. console.log('done!'...

与此同时,OfflineLink甚至阻止了原始变异发送请求,并且使用您提供的选项生成并发送了一个新变异.

Meanwhile, OfflineLink prevents the original mutation from even sending the request, and a new mutation is generated and sent with the options you've given it.

这篇关于Apollo-update()方法被两次调用,两次都使用乐观/伪数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆