import { GraphQLClient } from "graphql-request"; import { withRefreshTokenMiddleware } from "./graphql-refresh-middleware"; const endpoint = import.meta.env["VITE_SERVER_URL"] ? `${import.meta.env["VITE_SERVER_URL"]}/graphql` : "http://localhost:3000/graphql"; const baseFetcher = async ( query: string, variables?: TVariables, options?: RequestInit["headers"], ): Promise => { const client = new GraphQLClient(endpoint, { credentials: "include", headers: options as Record | undefined, }); return await client.request( query, variables as Record, ); }; const fetcherWithMiddleware = withRefreshTokenMiddleware(baseFetcher); export const graphQLFetcher = ( query: string, variables?: TVariables, options?: RequestInit["headers"], ) => async (): Promise => { return await fetcherWithMiddleware(query, variables, options); };