-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
61 lines (54 loc) · 1.35 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
51
52
53
54
55
56
57
58
59
60
61
import React, { Component } from "react";
import { ApolloClient } from "apollo-client";
import { InMemoryCache } from "apollo-cache-inmemory";
import { HttpLink } from "apollo-link-http";
import { ApolloLink } from "apollo-link";
import { setContext } from "apollo-link-context";
import { ApolloProvider } from "react-apollo";
import { withClientState } from "apollo-link-state";
import KEYS from "./src/config/keys";
import routes from "./src/config/routes";
const RootStack = routes;
const cache = new InMemoryCache();
const stateLink = withClientState({
cache,
defaults: {
testing: {
__typename: "testing",
name: "",
age: 0
}
}
});
const authLink = setContext(async (_, { headers }) => {
// return the headers to the context so httpLink can read them
return {
headers: {
...headers
}
};
});
const client = new ApolloClient({
cache,
link: authLink.concat(
ApolloLink.from([
stateLink,
new HttpLink({ uri: `${KEYS.BASE_URL}/graphql` })
])
)
});
// make client to rewrite the defaults every time the store resets
client.onResetStore(stateLink.writeDefaults);
export default class App extends Component {
constructor(props) {
super(props);
}
componentDidMount() {}
render() {
return (
<ApolloProvider client={client}>
<RootStack />
</ApolloProvider>
);
}
}