remove absinthe package in frontend - #1814

This commit is contained in:
Laurent GAY
2025-11-22 12:24:07 +01:00
committed by setop
parent dc413e3800
commit c63ce29a33
9 changed files with 41 additions and 359 deletions

View File

@@ -1,25 +0,0 @@
import { Socket as PhoenixSocket } from "phoenix";
import { create } from "@framasoft/socket";
import { createAbsintheSocketLink } from "@framasoft/socket-apollo-link";
import { AUTH_ACCESS_TOKEN } from "@/constants";
import { GRAPHQL_API_ENDPOINT } from "@/api/_entrypoint";
const httpServer = GRAPHQL_API_ENDPOINT || "http://localhost:4000";
const webSocketPrefix = import.meta.env.PROD ? "wss" : "ws";
const wsEndpoint = `${webSocketPrefix}${httpServer.substring(
httpServer.indexOf(":")
)}/graphql_socket`;
const phoenixSocket = new PhoenixSocket(wsEndpoint, {
params: () => {
const token = localStorage.getItem(AUTH_ACCESS_TOKEN);
if (token) {
return { token };
}
return {};
},
});
const absintheSocket = create(phoenixSocket);
export default createAbsintheSocketLink(absintheSocket);

View File

@@ -1,20 +0,0 @@
import fetch from "unfetch";
import { createLink } from "apollo-absinthe-upload-link";
import { GRAPHQL_API_ENDPOINT, GRAPHQL_API_FULL_PATH } from "@/api/_entrypoint";
// Endpoints
const httpServer = GRAPHQL_API_ENDPOINT || "http://localhost:4000";
const httpEndpoint = GRAPHQL_API_FULL_PATH || `${httpServer}/api`;
const customFetch = async (uri: string, options: any) => {
const response = await fetch(uri, options);
if (response.status >= 400) {
return Promise.reject(response.status);
}
return response;
};
export const uploadLink = createLink({
uri: httpEndpoint,
fetch: customFetch,
});

View File

@@ -1,37 +1,18 @@
import { from, split } from "@apollo/client/core";
import { from } from "@apollo/client/core";
import { createHttpLink } from "@apollo/client";
import { RetryLink } from "@apollo/client/link/retry";
import { getMainDefinition } from "@apollo/client/utilities";
import absintheSocketLink from "./absinthe-socket-link";
import { authMiddleware } from "./auth";
import errorLink from "./error-link";
import { uploadLink } from "./absinthe-upload-socket-link";
import { removeTypenameFromVariables } from "@apollo/client/link/remove-typename";
import { authMiddleware } from "@/apollo/auth";
import errorLink from "@/apollo/error-link";
import { GRAPHQL_API_ENDPOINT, GRAPHQL_API_FULL_PATH } from "@/api/_entrypoint";
let link;
// Endpoints
const httpServer = GRAPHQL_API_ENDPOINT || "http://localhost:4000";
const httpEndpoint = GRAPHQL_API_FULL_PATH || `${httpServer}/api`;
// The Absinthe socket Apollo link relies on an old library
// (@jumpn/utils-composite) which itself relies on an old
// Babel version, which is incompatible with Histoire.
// We just don't use the absinthe apollo socket link
// in this case.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (!import.meta.env.VITE_HISTOIRE_ENV) {
// const absintheSocketLink = await import("./absinthe-socket-link");
link = split(
// split based on operation type
({ query }) => {
const definition = getMainDefinition(query);
return (
definition.kind === "OperationDefinition" &&
definition.operation === "subscription"
);
},
absintheSocketLink,
uploadLink
);
}
const uploadLink = createHttpLink({
uri: httpEndpoint,
});
const retryLink = new RetryLink();
@@ -40,5 +21,5 @@ export const fullLink = from([
retryLink,
errorLink,
authMiddleware,
link ?? uploadLink,
uploadLink,
]);

View File

@@ -1,5 +0,0 @@
declare module "@framasoft/socket";
declare module "@framasoft/socket-apollo-link";
declare module "apollo-absinthe-upload-link";

View File

@@ -1,7 +1,7 @@
import { ApolloClient, NormalizedCacheObject } from "@apollo/client/core";
import buildCurrentUserResolver from "@/apollo/user";
import { cache } from "./apollo/memory";
import { fullLink } from "./apollo/link";
import { cache } from "@/apollo/memory";
import { fullLink } from "@/apollo/link";
export const apolloClient = new ApolloClient<NormalizedCacheObject>({
cache,