问题描述
我在 Apollo 服务器上使用 URQL 客户端,现在我正在尝试处理 URQL 客户端上的订阅,但我似乎无法使网络套接字工作。希望有人能帮助我谢谢。我认为是客户端有问题,还不是服务器和客户端之间的通信。
import { SubscriptionClient } from "subscriptions-transport-ws";
const subscriptionClient = new SubscriptionClient(
"ws://localhost:4000/subscriptions",{
reconnect: true,}
);
const CreateUrqlClient = (ssrExchange: any,ctx: any) => {
let cookie = "";
if (isServer()) {
cookie = ctx?.req?.headers.cookie;
}
return {
url: process.env.NEXT_PUBLIC_API_URL,fetchOptions: {
credentials: "include" as const,headers: cookie
? {
cookie,}
: undefined,},exchanges: [
dedupExchange,subscriptionExchange({
forwardSubscription: (operation) =>
subscriptionClient.request(operation),}),cacheExchange,errorExchange,ssrExchange,fetchExchange,],};
};
export default CreateUrqlClient;
我遇到了以下错误(服务器错误错误:无法找到本机实现,或 WebSocket 的替代实现!)。因此,我也尝试添加 ws(不适用于浏览器)和 WebSocket 本身(不确定如何正确使用),但我仍然无法使其工作。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)