Reorganizace skeletonu, aktualizace app-vite a quasaru

This commit is contained in:
Michal Kváček
2023-12-10 10:19:03 +01:00
parent 68659ca924
commit 71389caecc
87 changed files with 1666 additions and 1368 deletions
+14 -8
View File
@@ -1,18 +1,19 @@
import {ApolloClient, ApolloLink, fromPromise, InMemoryCache} from '@apollo/client/core'
import {createUploadLink} from 'apollo-upload-client';
import {onError} from "@apollo/client/link/error";
import {useUserStore} from "stores/User";
import {useAppStore} from "stores/App";
import {Notify} from "quasar";
import {errorObject, warningObject} from "src/composables/dialog";
import {createUploadLink} from "apollo-upload-client";
// import createUploadLink from "apollo-upload-client/createUploadLink.mjs";
const handleRefreshToken = (store, forward, operation) => {
const handleRefreshToken = (store, router, forward, operation) => {
if (!operation.query?._refreshUnauthorizedUser) return;
return fromPromise(useUserStore(store).refreshAccessToken()
.catch((error) => {
Notify.create(warningObject("Tvoje přihlášení vypřešlo. Přihlaš se prosím znovu."));
if (window) window.location = "/login";
router.push({name: "login"})
}))
.filter((value) => Boolean(value))
.flatMap((accessToken) => {
@@ -30,7 +31,7 @@ const handleRefreshToken = (store, forward, operation) => {
}
export const apolloWrapper = {};
export default (({store}) => {
export default (({store, router}) => {
const uploadLink = createUploadLink({
uri: process.env.API_URL + '/graphql',
})
@@ -47,8 +48,9 @@ export default (({store}) => {
});
const errorLink = onError(({graphQLErrors, networkError, operation, forward}) => {
console.log(networkError, graphQLErrors);
if (networkError?.statusCode === 401) {
return handleRefreshToken(store, forward, operation);
return handleRefreshToken(store, router, forward, operation);
}
if (graphQLErrors) {
@@ -56,7 +58,7 @@ export default (({store}) => {
if (error.message === "Not found") {
useAppStore(store).appStatus = 404;
} else if (error.message.includes("401") || error.message.includes("Not authorized")) {
return handleRefreshToken(store, forward, operation);
return handleRefreshToken(store, router, forward, operation);
} else {
Notify.create(errorObject("API error: " + error.message));
}
@@ -70,7 +72,9 @@ export default (({store}) => {
apolloWrapper.query = (query, variables = {}) => {
return apolloClient.query({
query: query, fetchPolicy: 'no-cache', variables: variables
query: query,
fetchPolicy: 'no-cache',
variables: variables
})
.then((response) => response)
.catch(err => {
@@ -82,7 +86,9 @@ export default (({store}) => {
apolloWrapper.mutate = (mutation, variables) => {
return apolloClient
.mutate({
mutation: mutation, fetchPolicy: 'no-cache', variables: variables,
mutation: mutation,
fetchPolicy: 'no-cache',
variables: variables,
})
.then((response) => response)
.catch(err => {