Seeking assistance in setting up subscriptions on URQL Client with Apollo server. I am facing difficulty getting the web socket to function properly on the client-side. Any guidance or support would be greatly appreciated. It seems like there may be an issue with the client-side implementation rather than the communication between the server and client.
Here is the code snippet that I added to my client:
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;
I encountered the following error message (Server Error Error: Unable to find native implementation, or alternative implementation for WebSocket!). Additionally, I attempted using ws (not compatible with browsers) and WebSocket directly (unsure of correct usage), but have not been successful in resolving the issue.