-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
52 lines (44 loc) · 1.32 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React, { useState, useEffect } from 'react';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { AuthContext } from './auth/context'
import Main from './main'
import { ApolloProvider } from 'react-apollo';
import ApolloClient from 'apollo-boost';
import NetworkError from './layouts/NetworkError'
export default function App(props) {
const [showErrorScreen, setShowErrorScreen] = useState(false)
const reset = () => {
setShowErrorScreen(false)
}
const client = new ApolloClient({
uri: 'http://beton-web.herokuapp.com/graphql',
onError: ({ response, operation, graphQLErrors, networkError }) => {
if (operation.operationName === "IgnoreErrorsQuery") {
response.errors = null;
}
if (graphQLErrors && graphQLErrors[0] && graphQLErrors[0].message) {
console.log("Graphql error: ", graphQLErrors)
}
if (networkError) {
setShowErrorScreen(true)
console.log("Network error")
} else {
setShowErrorScreen(false)
}
if (response?.errors) {
console.log("Response error")
}
}
})
return (
<>
{
!showErrorScreen ?
<ApolloProvider client={client}>
<Main />
</ApolloProvider> :
<NetworkError reset={reset} />
}
</>
);
}