ws support for gql subscriptions
This commit is contained in:
34
main.jsx
34
main.jsx
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user