我正在尝试使用apollo websockets检查互联网连接,这样做的目的是在没有连接时显示一条“you‘s disconnected”消息,以防止用户键入并假定更改已保存(更改应保存在type中),以下是apollo link-ws设置的一部分
const wsLink = new WebSocketLink({
uri: `ws://${hostname}${port ? `:${port}` : ''}/subscriptions`,
options: {
reconnect: true,
connectionParams: () => ({
authorization: localStorage.getItem('accelerator-token')
})
}
});
和
const hasSubscriptionOperation = ({ query: { definitions } }) =>
definitions.some(
({ kind, operation }) =>
kind === 'OperationDefinition' && operation === 'subscription'
);
下面是客户端配置:
const client = new ApolloClient({
link: ApolloLink.split(
hasSubscriptionOperation,
wsLink,
ApolloLink.from([
cleanTypenameLink,
authMiddleware,
errorLink,
stateLink,
createUploadLink()
])
),
cache
});
https://stackoverflow.com/questions/50887793
复制相似问题