Ne uplne otestovany prepis storu

This commit is contained in:
Michal Kváček
2023-11-19 00:44:01 +01:00
parent e65491e00b
commit f9d70a5d57
76 changed files with 1445 additions and 1463 deletions
-109
View File
@@ -1,109 +0,0 @@
import {ApolloClient, ApolloLink, fromPromise, InMemoryCache} from '@apollo/client/core'
import {createApolloProvider} from "@vue/apollo-option";
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";
const uploadLink = createUploadLink({
uri: process.env.API_URL + '/graphql',
})
const handleRefreshToken = (forward, operation) => {
return fromPromise(
useUserStore().refreshAccessToken()
.catch((error) => {
Notify.create(warningObject("Tvoje přihlášení vypřešlo. Přihlaš se prosím znovu."));
window.location = "/login";
})
)
.filter((value) => Boolean(value))
.flatMap((accessToken) => {
const oldHeaders = operation.getContext().headers;
operation.setContext({
headers: {
...oldHeaders,
authorization: `Bearer ${accessToken}`,
},
});
// retry the request, returning the new observable
return forward(operation);
});
}
const errorLink = onError(
({graphQLErrors, networkError, operation, forward}) => {
if (networkError?.statusCode === 401) {
return handleRefreshToken(forward, operation);
}
if (graphQLErrors) {
for (const error of graphQLErrors) {
if (error.message === "Not found") {
useAppStore().appStatus = 404;
} else if (error.message.includes("401") || error.message.includes("Not authorized")) {
return handleRefreshToken(forward, operation);
} else {
Notify.create(errorObject("API error: " + error.message));
}
}
}
});
const authLink = new ApolloLink((operation, forward) => {
const accessToken = useUserStore().getAccessToken();
if (accessToken) {
operation.setContext({
headers: {"Authorization": `Bearer ${accessToken}`},
});
}
return forward(operation);
});
export const apolloClient = new ApolloClient({
link: ApolloLink.from([authLink, errorLink, uploadLink]),
cache: new InMemoryCache(),
connectToDevTools: true,
})
export const apolloWrapper = {
query(query, variables = {}) {
return apolloClient.query({
query: query,
fetchPolicy: 'no-cache',
variables: variables
})
.then((response) => response)
.catch(err => {
console.error("Error during query: ", err)
return err;
})
},
mutate(mutation, variables, onUpdate = () => {
}) {
return apolloClient
.mutate({
mutation: mutation,
fetchPolicy: 'no-cache',
variables: variables,
update: () => {
onUpdate();
},
})
.then((response) => response)
.catch(err => {
console.error("Error during mutation: ", err);
})
},
}
// @see https://v4.apollo.vuejs.org/migration/
export const apolloProvider = createApolloProvider({
defaultClient: apolloClient,
})
+4 -3
View File
@@ -4,11 +4,12 @@ import {FRAGMENT_FLIGHT_FULL_INFO} from "src/graphql/fragments/flight";
export const CREATE_FLIGHT = gql`
mutation createFlight($input: CreateFlightInput!) {
createFlight(input: $input) {
id
...flightFullInfo
}
}
`
// ^^ nesmim se tu ptat na aircraft, jinak mi to upadne
${FRAGMENT_FLIGHT_FULL_INFO}
`;
export const EDIT_FLIGHT = gql`
mutation editFlight($id: Int!, $input: EditFlightInput!) {
editFlight(id: $id, input: $input) {
+9 -17
View File
@@ -7,7 +7,6 @@ export const CREATE_ORGANIZATION = gql`
...organizationFullInfo
}
}
${FRAGMENT_ORGANIZATION_FULL_INFO}
`;
@@ -17,33 +16,26 @@ mutation editOrganization($id: Int!, $input: EditOrganizationInput!) {
...organizationFullInfo
}
}
${FRAGMENT_ORGANIZATION_FULL_INFO}
${FRAGMENT_ORGANIZATION_FULL_INFO}
`;
export const ADD_USER_TO_ORGANIZATION = gql`
mutation addToOrganization($organizationId: Int!) {
addToOrganization(organizationId: $organizationId) {
users {
id
name
email
avatarImageUrl
}
...organizationFullInfo
}
}`;
}
${FRAGMENT_ORGANIZATION_FULL_INFO}
`;
export const REMOVE_USER_FROM_ORGANIZATION = gql`
mutation removeFromOrganization($organizationId: Int!) {
removeFromOrganization(organizationId: $organizationId) {
users {
id
name
email
avatarImageUrl
}
...organizationFullInfo
}
}`;
}
${FRAGMENT_ORGANIZATION_FULL_INFO}
`;
// export const DELETE_ORGANIZATION = gql`
// mutation deleteOrganization($id: Int!) {