问题描述
我的 Apollo 版本是
"@apollo/client": "^3.3.11",
我正在使用
"apollo-link-ws": "^1.0.20","apollo-utilities": "^1.3.4",
根据请求的类型连接到不同的端点,如下所示。
const httpLink = new HttpLink({
uri: process.env.REACT_APP_GQL_ROOT,// Server URL (must be absolute)
credentials: 'same-origin',// Additional fetch() options like `credentials` or `headers`
headers: {
authorization: token ? `Bearer ${token}` : '',},})
// create a link for websocktes that directly contacts hasura hasura
const createWsLink = new WebSocketLink({
uri: process.env.REACT_APP_SUBSCRIPTION_ROOT,options: {
reconnect: true,lazy: true,connectionParams: {
authorization: token ? `Bearer ${token}` : '',})
// create a link for websockets for nest graphql subscriptions
const createnestWsLink = new WebSocketLink({
uri: process.env.REACT_APP_nesT_SUB_ROOT,})
// join the split links for a unified apollo client
const link = split(
// split based on operation type
({ query }) => {
const { kind,operation } = getMainDeFinition(query)
return kind === 'OperationDeFinition' && operation === 'subscription'
},// split websocket links based on operation name
split(({ operationName }) => operationName.startsWith('nesT_'),createnestWsLink,createWsLink),httpLink,)
const client = new ApolloClient({
uri: process.env.REACT_APP_GQL_ROOT,link,cache: new InMemoryCache(),})
但是我总是在控制台中收到错误消息 “加载时与“url”的连接中断”。 无论如何我都可以弄清楚为什么连接总是被中断。 如果没有,我有什么办法可以抑制这些错误?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)