简体   繁体   English

Apollo 客户端错误 | “RestLink”类型不可分配给“ApolloLink”类型

[英]Apollo Client Error | Type 'RestLink' is not assignable to type 'ApolloLink'

Now I am trying to use apolloClient with both graphql and rest api in typescript.现在我正在尝试将 apolloClient 与 graphql 和 rest api 在 Z1E35BCBA05DBA10878CDF75 中一起使用。

Therefore, I applied apollo-link-rest.因此,我应用了 apollo-link-rest。 But I got the error below.但我得到了下面的错误。

./node_modules/apollo-link-rest/bundle.umd.js Module not found: Can't resolve 'graphql-anywhere/lib/async' in 'D:\forked\syntegrate_app_client\node_modules\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.

This is the code that I used.这是我使用的代码。

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,
});

在此处输入图像描述

and this is my version of @apollo/client这是我的@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",

If you want to use apollo-link-rest you will have to use version 0.7.3 and use apollo-client 2.6.10, this fixed the problem for me如果你想使用 apollo-link-rest,你必须使用 0.7.3 版本并使用 apollo-client 2.6.10,这解决了我的问题

The 0.8.0-beta.0 has not been updated in some time, and it's unclear if this will be maintained to work properly with @apollo/client 3 0.8.0-beta.0 已经有一段时间没有更新了,目前还不清楚这是否会被维护以与@apollo/client 3 一起正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ApolloLink 的 ApolloClient 类型错误 - ApolloClient Type errors for ApolloLink Apollo客户端:网络错误{“ type”:“ WriteError”} - Apollo Client: Network Error {“type”:“WriteError”} Apollo客户端Graphql查询变量类型错误 - Apollo client Graphql query variable type error 使用 ApolloLink.split 时处理 Apollo Client 的错误 - Handling errors for Apollo Client when using ApolloLink.split 打字稿中的 Apollo 客户端返回类型 - Apollo Client return type in Typescript 如何在 Flow 中正确键入 Apollo Client 实例? - How to correctly type an Apollo Client instance in Flow? Apollo 客户端和 graphQl 查询错误:变量 '$where' 类型的期望值 'OrganizationWhereUniqueInput - Apollo client and graphQl query error : Variable '$where' expected value of type 'OrganizationWhereUniqueInput 如何在 apollo 客户端中模拟联合类型 - How to mock a union type in apollo client Apollo Client:错误:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件) - Apollo Client: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) 如何正确输入 Apollo Client defaultOptions? - How do I correctly type the Apollo Client defaultOptions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM