graphQL阿波罗库中的cache.writeFragment方法不起作用

时间:2020-01-08 15:49:02

标签: reactjs graphql apollo react-apollo apollo-client

我正在尝试向已在缓存中的对象添加属性。 我添加了本地解析器,并且正在执行此操作。

cache.writeFragment({
  id: gid.toString(),
  fragment: gql`
    fragment queues on Group {
      queuesList
    }
  `,
  data: {
    queuesList: ["test"],
    __typename: "Group"
  }
});

这将写入一个要缓存的对象,并且不向给定ID的对象添加属性。 我不知道片段在哪里失败。

1 个答案:

答案 0 :(得分:0)

好的,我做错了。 我给的片段ID错误,我不得不在缓存数据中传递对象密钥。 那是。 v12 = pygame.math.Vector2(x1-x2, y1-y2) distance = v12.length() hit_dist = 2*xR if distance <= hit_dist: # vector beteween center points nv = v12.normalize() # movement direction and combined relative movement d1 = pygame.math.Vector2(x1_dir, y1_dir) d2 = pygame.math.Vector2(x2_dir, y2_dir) dd = d1 - d2 if dd.length() == 0: # normalized movement and normal distances ddn = dd.normalize() dir_dist = ddn.dot(v12) norm_dist = pygame.math.Vector2(-ddn[0], ddn[1]).dot(v12) # minimum distance along the line of relative movement min_dist = math.sqrt(hit_dist*hit_dist - norm_dist*norm_dist) if dir_dist < min_dist: # update postions of the players so that the distance is 2*xR d1l, d2l = d1.length(), d2.length() d1n = d1/d1l if d1l > 0 else d1 d2n = d2/d2l if d2l > 0 else d2 x1 -= d1n.x * d1l / (d1l+d2l) y1 -= d1n.y * d1l / (d1l+d2l) x2 -= d2n.x * d2l / (d1l+d2l) y2 -= d2n.y * d2l / (d1l+d2l) # recalculate vector beteween center points v12 = pygame.math.Vector2(x1-x2, y1-y2) nv = v12.normalize() # reflect movement vectors rd1 = d1.reflect(nv) rd2 = d2.reflect(nv) len1, len2 = rd1.length(), rd2.length() if len1 > 0: rd1 = rd1 * len2 / len1 x1_dir, y1_dir = rd1.x, rd1.y else: x1_dir, y1_dir = -x2_dir, -y2_dir if len2 > 0: rd2 = rd2 * len1 / len2 x2_dir, y2_dir = rd2.x, rd2.y else: x2_dir, y2_dir = -x1_dir, -y1_dir

https://www.apollographql.com/docs/react/caching/cache-configuration/#generating-unique-identifiers

希望这对处于相同情况的人有所帮助。