Additional package updates.
This commit is contained in:
@@ -3,11 +3,9 @@ import { setContext } from "@apollo/client/link/context";
|
||||
import { onError } from "@apollo/client/link/error";
|
||||
import { HttpLink } from "@apollo/client/link/http"; //"apollo-link-http";
|
||||
import { RetryLink } from "@apollo/client/link/retry";
|
||||
import { WebSocketLink } from "@apollo/client/link/ws";
|
||||
import { getMainDefinition } from "@apollo/client/utilities";
|
||||
import apolloLogger from "apollo-link-logger";
|
||||
import { auth } from "../firebase/firebase.utils";
|
||||
import { SentryLink } from "apollo-link-sentry";
|
||||
import { auth } from "../firebase/firebase.utils";
|
||||
|
||||
const errorLink = onError(({ graphQLErrors, networkError, operation, forward }) => {
|
||||
if (graphQLErrors)
|
||||
@@ -22,49 +20,49 @@ const httpLink = new HttpLink({
|
||||
uri: import.meta.env.VITE_APP_GRAPHQL_ENDPOINT
|
||||
});
|
||||
|
||||
const wsLink = new WebSocketLink({
|
||||
uri: import.meta.env.VITE_APP_GRAPHQL_ENDPOINT_WS,
|
||||
options: {
|
||||
lazy: true,
|
||||
reconnect: true,
|
||||
connectionParams: async () => {
|
||||
const token = auth.currentUser && (await auth.currentUser.getIdToken(true));
|
||||
if (token) {
|
||||
return {
|
||||
headers: {
|
||||
authorization: token ? `Bearer ${token}` : ""
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// const wsLink = new WebSocketLink({
|
||||
// uri: import.meta.env.VITE_APP_GRAPHQL_ENDPOINT_WS,
|
||||
// options: {
|
||||
// lazy: true,
|
||||
// reconnect: true,
|
||||
// connectionParams: async () => {
|
||||
// const token = auth.currentUser && (await auth.currentUser.getIdToken(true));
|
||||
// if (token) {
|
||||
// return {
|
||||
// headers: {
|
||||
// authorization: token ? `Bearer ${token}` : ""
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
const subscriptionMiddleware = {
|
||||
applyMiddleware: async (options, next) => {
|
||||
options.authToken = auth.currentUser && (await auth.currentUser.getIdToken(true));
|
||||
next();
|
||||
}
|
||||
};
|
||||
wsLink.subscriptionClient.use([subscriptionMiddleware]);
|
||||
// const subscriptionMiddleware = {
|
||||
// applyMiddleware: async (options, next) => {
|
||||
// options.authToken = auth.currentUser && (await auth.currentUser.getIdToken(true));
|
||||
// next();
|
||||
// }
|
||||
// };
|
||||
// wsLink.subscriptionClient.use([subscriptionMiddleware]);
|
||||
|
||||
const link = new HttpLink.split(
|
||||
// split based on operation type
|
||||
({ query }) => {
|
||||
const definition = getMainDefinition(query);
|
||||
// console.log(
|
||||
// "##Intercepted GQL Transaction : " +
|
||||
// definition.operation +
|
||||
// "|" +
|
||||
// definition.name.value +
|
||||
// "##",
|
||||
// query
|
||||
// );
|
||||
return definition.kind === "OperationDefinition" && definition.operation === "subscription";
|
||||
},
|
||||
wsLink,
|
||||
httpLink
|
||||
);
|
||||
// const link = new HttpLink.split(
|
||||
// // split based on operation type
|
||||
// ({ query }) => {
|
||||
// const definition = getMainDefinition(query);
|
||||
// // console.log(
|
||||
// // "##Intercepted GQL Transaction : " +
|
||||
// // definition.operation +
|
||||
// // "|" +
|
||||
// // definition.name.value +
|
||||
// // "##",
|
||||
// // query
|
||||
// // );
|
||||
// return definition.kind === "OperationDefinition" && definition.operation === "subscription";
|
||||
// },
|
||||
// wsLink,
|
||||
// httpLink
|
||||
// );
|
||||
|
||||
const authLink = setContext((_, { headers }) => {
|
||||
return (
|
||||
@@ -104,7 +102,7 @@ if (import.meta.env.DEV) {
|
||||
middlewares.push(apolloLogger);
|
||||
}
|
||||
|
||||
middlewares.push(sentryLink.concat(retryLink.concat(errorLink.concat(authLink.concat(link)))));
|
||||
middlewares.push(sentryLink.concat(retryLink.concat(errorLink.concat(authLink.concat(httpLink)))));
|
||||
|
||||
const cache = new InMemoryCache({});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user