gpt4 book ai didi

apollo-client - Apollo 客户端错误 |类型 'RestLink' 不可分配给类型 'ApolloLink'

转载 作者:行者123 更新时间:2023-12-04 13:36:17 27 4
gpt4 key购买 nike

现在我试图在 typescript 中同时使用 apolloClient 和 graphql 和 rest api。

因此,我应用了 apollo-link-rest。但我得到了下面的错误。

./node_modules/apollo-link-rest/bundle.umd.js
找不到模块:无法解析“D:\forked\syntegrate_app_client\node_modules\apollo-link-rest”中的“graphql-anywhere/lib/async”

Type 'RestLink' is not assignable to type 'ApolloLink'.
Types of property 'split' are incompatible.
Type '(test: (op: import("d:/forked/syntegrate_app_client/node_modules/@apollo/client/link/core/types").Operation) => boolean, left: import("d:/forked/syntegrate_app_client/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink | import("d:/forked/syntegrate_app_client/node_modules/@apollo/client/link/core/types")....' is not assignable to type '(test: (op: import("d:/forked/syntegrate_app_client/node_modules/apollo-link/lib/types").Operation) => boolean, left: import("d:/forked/syntegrate_app_client/node_modules/apollo-link/lib/link").ApolloLink | import("d:/forked/syntegrate_app_client/node_modules/apollo-link/lib/types").RequestHandler, right?: import("d...'.
Types of parameters 'test' and 'test' are incompatible.
Types of parameters 'op' and 'op' are incompatible.
Property 'toKey' is missing in type 'import("d:/forked/syntegrate_app_client/node_modules/@apollo/client/link/core/types").Operation' but required in type 'import("d:/forked/syntegrate_app_client/node_modules/apollo-link/lib/types").Operation'.ts(2322)
types.d.ts(24, 5): 'toKey' is declared here.

这是我使用的代码。
const restLink = new RestLink({
uri: process.env.REST_API
});

const authLink = setContext((_, { headers }) => {
// get the authentication token from local storage if it exists
const token = getCookie("token");
// return the headers to the context so httpLink can read them
return {
headers: {
...headers,
STKN: token ? `${token}` : "",
},
};
});

const client = new ApolloClient({
// link: errorLink.concat(restLink).concat(authLink).concat(link),
link: ApolloLink.from([errorLink, restLink, authLink, link]),
cache,
resolvers,
});

enter image description here

这是我的@apollo/client 版本
"dependencies": {
"@apollo/client": "^3.0.0-beta.44",
"@apollo/link-context": "^2.0.0-beta.3",
"apollo-link": "^1.2.14",
"apollo-link-batch-http": "^1.2.13",
"apollo-link-http": "^1.5.16",
"apollo-link-rest": "^0.8.0-beta.0",

最佳答案

如果你想使用 apollo-link-rest,你将不得不使用 0.7.3 版本并使用 apollo-client 2.6.10,这为我解决了这个问题
0.8.0-beta.0 已经有一段时间没有更新了,目前还不清楚它是否会被维护以与 @apollo/client 3 一起正常工作

关于apollo-client - Apollo 客户端错误 |类型 'RestLink' 不可分配给类型 'ApolloLink',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61766686/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com