在自定义获取中设置 header apollo 客户端

set header apollo client in custom fetch

我尝试根据 response.status 在获取 属性 中的 apollo 客户端上更新缓存控件 header,我有一个自定义获取方法,但是当我使用 headers.set()

TypeError: Failed to execute 'set' on 'Headers': Headers are immutable

const customFetch = (uri, options) => {
  options.headers['Cache-Control'] = 'no-cache';
  return fetch(uri, options).then(response => {
    console.log(response.headers.get('cache-control'));
    try {
      if(response.status !== 301)
      response.headers.set('Cache-Control', getNewCacheValue());
    } catch (e) {
      console.log(e);
    }

  return new BatchHttpLink({
    fetch: customFetch,
    uri: uri
  });

您无法更改回复中的 headers。另一种方法是使用未使用的参数发出请求,您可以在其中控制缓存。

let url = 'www.google.com?xxx=' + getNewCacheValue()

您也可以在状态为 301

时使用 xxx 参数再次发出请求