Apollo-link-rest: 残破的React-Apollo示例

创建于 2018-06-07  ·  6评论  ·  资料来源: apollographql/apollo-link-rest

你好:

我刚刚开始使用apollo-link-rest $$$$并在react-apollo codesandbox中进行基本配置。

界面未显示电视节目列表,而是显示以下错误: : Network error: Failed to execute 'fetch' on 'Window': Invalid credentials mode

在我自己的create-react-app环境中复制该代码时,在Apollo DevTools上运行请求时,我还捕获到以下错误:

{
  "errors": [
    {
      "message": "forward is not a function",
      "locations": [
        "TypeError: forward is not a function\n    at RestLink../node_modules/apollo-link-rest/bundle.umd.js.RestLink.request (http://localhost:3000/static/js/bundle.js:21028:20)\n    at http://localhost:3000/static/js/bundle.js:19809:33\n    at ApolloLink.request (http://localhost:3000/static/js/bundle.js:17407:12)\n    at ApolloLink.request 
    }
  ]
}

非常感谢您在此链接上所做的工作! 通过为坚持使用REST API的我们带来那些类似于GraphQL的功能,它使REST的工作变得更加易于管理。

help wanted 🛠 question❔

最有用的评论

应该在v0.3.1中修复-现在可用!

所有6条评论

@sinisterra当我们在应用程序中看到forward is not a function时,通常是因为我们忘记了其中一个节点上的@client@rest(…)指令。 是这样吗?

关于fetch -您正在使用哪种浏览器进行测试?

@fbartho不,我正在运行与示例完全相同的查询,正确应用了@rest指令。 我正在使用Google Chrome 67.0.3396.62。 当我尝试在Firefox 60.0.1中运行该示例时,它也失败了,但出现了另一个错误: Network error: 'credentials' member of RequestInit 'null' is not a valid value for enumeration RequestCredentials.

这不仅仅是关于坏掉的例子! 我认为这个问题非常关键。
我现在在生产环境中也遇到了同样的错误,在过去的几个月中使用apollo-link-rest可以正常工作。 我想这一定是由于浏览器更新引起的吗?
我正在使用Chrome Version 67.0.3396.79 (Official Build) (64-bit)

Safari和Firefox中也发生了同样的问题。.我完全没有得到它。

尽管我已经配置了customFetch fn,但仅在我对apollo-link-rest进行的请求中才发生这种情况。 ¯_(ツ)_ /¯

当我删除customFetch配置时,我也遇到同样的错误。

我实际上发现了问题。
我正在使用customFetch函数,该函数由apollo-link-rest与选项参数credentials: null调用。 这会导致所有浏览器(包括新版本的chrome)出现此错误。

由于未使用凭据,因此对自定义提取功能的快速修复如下:

export function fetchWithAuth(url, options = {}) {
  // this fixes apollo-link-rest providing credentials: null options
  const { credentials, ...opt } = options
  return fetch(url, getOptions(opt));
}

我还把头撞在墙上,遇到“网络错误:无法提取”的问题,甚至无法使用apollo-link-rest执行查询。 @JuHwon是正确的,这似乎与RestLink构造函数上的凭据选项有关。 虽然以前根据文档它是可选的,但现在只有在包含如下所示的选项之后,我才能使其工作:

const restLink = new RestLink({  
  uri: ${process.env.REACT_APP_API_URL}/,  
  credentials: 'same-origin',  // eg. or credentials: 'omit', etc
});

应该在v0.3.1中修复-现在可用!

此页面是否有帮助?
0 / 5 - 0 等级