Prace s mapou, refresh tokenu (tak nejak), uprava vypisu POI, pridani breadcrumbs
This commit is contained in:
+44
-9
@@ -1,19 +1,53 @@
|
||||
import {ApolloClient, ApolloLink, HttpLink, InMemoryCache} from '@apollo/client/core'
|
||||
import {ApolloClient, ApolloLink, fromPromise, HttpLink, InMemoryCache} from '@apollo/client/core'
|
||||
import {createApolloProvider} from "@vue/apollo-option";
|
||||
import { createUploadLink } from 'apollo-upload-client';
|
||||
import {createUploadLink} from 'apollo-upload-client';
|
||||
import {onError} from "@apollo/client/link/error";
|
||||
import {useUserStore} from "stores/User";
|
||||
import {useRouter} from "vue-router";
|
||||
|
||||
const httpLink = new HttpLink({
|
||||
uri: 'http://localhost:8000/graphql',
|
||||
credentials: 'include'
|
||||
})
|
||||
|
||||
const uploadLink = createUploadLink({
|
||||
uri: 'http://localhost:8000/graphql',
|
||||
credentials: 'include'
|
||||
})
|
||||
|
||||
|
||||
const errorLink = onError(
|
||||
({graphQLErrors, networkError, operation, forward}) => {
|
||||
if (networkError?.statusCode === 401) {
|
||||
return fromPromise(
|
||||
useUserStore().refreshAccessToken().catch((error) => {
|
||||
useRouter().push({to: "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 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([uploadLink]),
|
||||
link: ApolloLink.from([authLink, errorLink, uploadLink]),
|
||||
cache: new InMemoryCache(),
|
||||
connectToDevTools: true,
|
||||
})
|
||||
@@ -31,7 +65,8 @@ export const apolloWrapper = {
|
||||
})
|
||||
},
|
||||
|
||||
mutate(mutation, variables, onUpdate = () => {}) {
|
||||
mutate(mutation, variables, onUpdate = () => {
|
||||
}) {
|
||||
return apolloClient
|
||||
.mutate({
|
||||
mutation: mutation,
|
||||
|
||||
@@ -4,5 +4,7 @@ export const FRAGMENT_AIRPORT_INFO = gql`
|
||||
fragment airportInfo on Airport {
|
||||
name
|
||||
icaoCode
|
||||
gpsLatitude
|
||||
gpsLongitude
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -28,6 +28,8 @@ fragment flightFullInfo on Flight {
|
||||
pointOfInterest {
|
||||
id
|
||||
name
|
||||
gpsLatitude
|
||||
gpsLongitude
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import gql from "graphql-tag";
|
||||
import {FRAGMENT_FLIGHT_LIST_INFO} from "src/graphql/fragments/flight";
|
||||
|
||||
export const COPILOTS_LIST = gql`
|
||||
query copilotsList {
|
||||
@@ -14,6 +15,12 @@ query copilot($id: Int!) {
|
||||
copilot(id: $id) {
|
||||
id
|
||||
name
|
||||
|
||||
flights {
|
||||
...flightListInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
${FRAGMENT_FLIGHT_LIST_INFO}
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user