- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 TypeScript 创建 ApolloClient,但有一些我无法解决的类型错误。谁能指出我正确的方向该怎么做?
以下是用于创建客户端的示例代码(可与 JavaScript 一起使用):
import {
ApolloClient,
ApolloProvider,
InMemoryCache,
split
} from '@apollo/client';
import { setContext } from 'apollo-link-context';
import { createHttpLink } from 'apollo-link-http';
import { getMainDefinition } from '@apollo/client/utilities';
import { WebSocketLink } from '@apollo/link-ws';
const authLink = setContext((_, { headers }) => {
const token = localStorage.getItem('consequat-token');
return {
headers: {
...headers,
authorization: token ? `bearer ${token}` : null
}
};
});
const httpLink = createHttpLink({ uri: 'http://localhost:4000' });
const wsLink = new WebSocketLink({
uri: 'ws://localhost:4000/graphql',
options: { reconnect: true },
});
const splitLink = split(
({ query }) => {
const definition = getMainDefinition(query);
return (
definition.kind === 'OperationDefinition' &&
definition.operation === 'subscription'
);
},
wsLink,
authLink.concat(httpLink)
);
const client = new ApolloClient({
cache: new InMemoryCache(),
link: splitLink
});
问题是
authLink.concat(httpLink)
线路在提示:
Argument of type 'ApolloLink' is not assignable to parameter of type 'ApolloLink | RequestHandler | undefined'.
Type 'ApolloLink' is missing the following properties from type 'ApolloLink': onError, setOnError ts(2345)
我无法从 Apollo 文档或 Google 中找到任何答案。
最佳答案
回复我自己的帖子:
import {
ApolloClient,
ApolloProvider,
InMemoryCache,
split
} from '@apollo/client';
import { setContext } from 'apollo-link-context';
import { createHttpLink } from 'apollo-link-http';
import { getMainDefinition } from '@apollo/client/utilities';
import { WebSocketLink } from '@apollo/link-ws';
需要改为:
import {
ApolloClient,
ApolloProvider,
InMemoryCache,
HttpLink,
split
} from '@apollo/client';
import { setContext } from '@apollo/link-context';
import { getMainDefinition } from '@apollo/client/utilities';
import { WebSocketLink } from '@apollo/link-ws';
那些
@apollo/
和
apollo-
库不兼容。另外,
createHttpLink
替换为
HttpLink
进口自
@apollo/client
,它的用法:
const httpLink = createHttpLink({ uri: 'http://localhost:4000' });
变成:
const httpLink = new HttpLink({ uri: 'http://localhost:4000' });
关于reactjs - ApolloClient 类型错误 ApolloLink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62814083/
我正在使用 react 和 apollo 客户端建立一个新的 typescript 项目。我正在尝试像这样连接客户端: const client = new ApolloClient({ cach
感谢您来到这里!我是 React 和 Apollo 的新手,我会尽力解释我的情况。 现在,我使用 ApolloClient V3 实现了“无限”滚动到我的网站。这个无限卷轴可以看here .尝试时,您
我需要在运行“useQuery”时定义“client”,但我会无限循环。 我写的代码如下: const QueryKTP = gql` query { documents(transact
我的应用程序包含 本质上初始化客户端的组件。 const client = new ApolloClient({ link: new HttpLink({ // ... }), c
我正在尝试使用 TypeScript 创建 ApolloClient,但有一些我无法解决的类型错误。谁能指出我正确的方向该怎么做? 以下是用于创建客户端的示例代码(可与 JavaScript 一起使用
我正尝试使用 Apollo 为我的 Angular 项目连接到 AWSAppSync(Graphql)。 我做了什么: import AWSAppSyncClient from 'aws-appsyn
当 networkStatus 正在运行时,我试图显示预加载器。 我知道每个查询都会返回它自己的 networkStatus,但是在我的应用程序中有很多不同的查询。我想有一种方法可以在全局范围内处理所
我正在尝试使用此身份验证服务器示例来比较现实世界的应用程序,我从中获取一些数据。但自 Apollo Client 以来我无法捕获客户端错误将其自己的异常发送到控制台。 我的示例服务器将输入与“数据库”
因此,我无法在新的Web应用程序中处理内存泄漏。当然,它在本地开发时从未出现过。每隔18小时,运行一个Web客户端的Kubernetes容器将耗尽内存并重新启动。我已经考虑过这些工具,但是不确定哪一个
我正在关注 this tutorial并尝试实现 graphQl。以下行存在问题: const client = new ApolloClient(); 奇怪的是,我在 react-apollo Gi
我有一个有趣的情况。 我想使用 Apollo 本身发起刷新 token 请求(也称为调用突变) 有什么想法,如何实现这样的目标吗? export default new ApolloClient({
我同时使用 ApolloClient来自“apollo-client”和“apollo-boost”库,比如 const client = new ApolloClient({ uri: 'ht
在我的 main.js 中,我有一些代码可以检查是否存在 localStorage 项目。如果有,它将通过中间件向 ApolloClient 设置添加 Authorization header 。 但
我对 react 还比较陌生,似乎无法从上下文中导入 client 变量。我有一个名为 federation.tsx 的文件,其中包含一些代码,我认为这应该是相关部分: const link = cr
我目前正在使用 ApolloClient 连接到 AppSync GraphQL API。这一切都非常适合查询和突变,但我在订阅工作时遇到了一些麻烦。我遵循了 Apollo 文档,我的 App.js
我正在使用 ApolloGraphQL 实现 React 身份验证。 上下文: 在signin.js 中,当用户单击提交按钮并将其设置为本地存储时,我将生成 token 。 然后,我在 App.js
我想禁用缓存或将缓存限制为 24 小时。我的 ApolloClient 只在服务器端运行。 我的环境: apollo-boost 0.4.3 graphql 14.1.1 apollo-link-ba
我正在阅读有关如何使用订阅的 Appsync 文章并找到此链接:https://docs.aws.amazon.com/appsync/latest/devguide/real-time-data.h
我是 NextJS 和 GraphQL 的新手,我正在使用 MERN 堆栈和(NextJS 和 GraphQL)构建一个应用程序。 我只需要澄清一下我是否使用从 getStaticProps(next
我正在使用 ApolloClient 构建一个应用来查询 GraphQL 端点。我希望对普通查询使用“缓存和网络”获取策略,因为此特定策略仅适用于 watchQueries。我真正想要的是以下内容:
我是一名优秀的程序员,十分优秀!