ws support for gql subscriptions

This commit is contained in:
2026-05-19 21:52:58 +03:30
parent 657dcb072d
commit bc23b3d478
5 changed files with 59 additions and 13 deletions

View File

@@ -1,21 +1,33 @@
import React from "react";
import ReactDOM from "react-dom/client";
import { GraphiQL } from "graphiql";
import { createGraphiQLFetcher } from "@graphiql/toolkit";
import { createClient } from "graphql-ws";
import "graphiql/graphiql.css";
const fetcher = async (params) => {
const res = await fetch(import.meta.env.VITE_GRAPHQL_ENDPOINT, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(params),
});
const wsClient = createClient({
url: import.meta.env.VITE_GRAPHQL_WS_ENDPOINT,
connectionParams: () => ({
Authorization: "Bearer " + localStorage.getItem("access_token"),
}),
});
return res.json();
};
const fetcher = createGraphiQLFetcher({
url: import.meta.env.VITE_GRAPHQL_ENDPOINT,
wsClient,
fetch: (url, opts) =>
fetch(url, {
...opts,
credentials: "include",
}),
websocketClientOptions: {
retryAttempts: 3,
lazy: true,
},
});
function App() {
return (