Merge Complete

This commit is contained in:
Luis Fernando Molina committed 2020-11-20 20:28:04 +01:00
1 parent 482ef7a81a
commit dabe23d505
6483 files changed

No files matched your search

@@ -0,0 +1,121 @@
import gql from 'graphql-tag'
export const ECOSYSTEM_QUERY = gql`
query {
web_GetEcosystem {
id
devTeams {
codeName
displayName
host {
url
storage
container
accessKey
}
bots {
codeName
displayName
type
profilePicture
repo
configFile
products{
codeName
displayName
description
dataSets{
codeName
type
validPeriods
filePath
fileName
dataRange{
filePath
fileName
}
}
exchangeList{
name
}
plotter{
devTeam
codeName
moduleName
repo
}
}
}
plotters {
codeName
displayName
modules{
codeName
moduleName
description
profilePicture
panels{
codeName
moduleName
event
}
}
repo
configFile
}
}
hosts {
codeName
displayName
host {
url
storage
container
accessKey
}
competitions {
codeName
displayName
description
startDatetime
finishDatetime
formula
plotter{
devTeam
codeName
host{
url
storage
container
accessKey
}
moduleName
repo
}
rules
prizes
participants
repo
configFile
}
plotters {
codeName
displayName
modules{
codeName
moduleName
description
profilePicture
panels{
codeName
moduleName
event
}
}
repo
configFile
}
}
}
}
`
@@ -0,0 +1,92 @@
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { ApolloLink, Observable } from 'apollo-link'
import { onError } from 'apollo-link-error'
import { setContext } from 'apollo-link-context'
import { getItem } from '../utils/local-storage'
const httpLink = new HttpLink({ uri: process.env.PLATFORM_API_URL })
const authRetryLink = onError(
({ graphQLErrors, networkError, operation, forward }) => {
if (graphQLErrors) {
// User access token has expired
// console.log('authLink: ', graphQLErrors) // check for error message to intercept and resend with Auth0 access token
if (graphQLErrors[0].message === 'Context creation failed: jwt expired') {
window.localStorage.removeItem('access_token')
window.localStorage.removeItem('user')
window.localStorage.removeItem('name')
location.reload()
} else if (graphQLErrors[0].message === 'Not logged in') {
// We assume we have auth0 access token needed to run the async request
// Let's refresh token through async request
return new Observable(observer => {
getItem('access_token')
.then(accessToken => {
operation.setContext(({ headers = {} }) => ({
headers: {
// Re-add old headers
...headers,
// Switch out old access token for new one
Authorization: `Bearer ${accessToken}` || null
}
}))
})
.then(() => {
const subscriber = {
next: observer.next.bind(observer),
error: observer.error.bind(observer),
complete: observer.complete.bind(observer)
}
// Retry last failed request
forward(operation).subscribe(subscriber)
// TODO improve with redux
location.reload()
})
.catch(error => {
// No auth0 access token available, we force user to login
observer.error(error)
})
})
}
}
}
)
const authLink = setContext((_, { headers }) => {
// get the authentication token from local storage if it exists
const token = localStorage.getItem('access_token')
return {
headers: {
...headers,
Authorization: token ? `Bearer ${token}` : ``
}
}
})
const cache = new InMemoryCache({ addTypename: false }).restore(window.__APOLLO_STATE__)
const defaultOptions = {
watchQuery: {
fetchPolicy: 'cache-and-network',
errorPolicy: 'all'
},
query: {
fetchPolicy: 'network-only',
errorPolicy: 'all'
},
mutate: {
errorPolicy: 'all'
}
}
export const client = new ApolloClient({
link: ApolloLink.from([authRetryLink, authLink, httpLink]), // replaced link with httpLink
cache,
defaultOptions,
connectToDevTools: true
})