Skip to content

Commit ccd771d

Browse files
committed
Setup router, apollo client and graphql
1 parent 20743b4 commit ccd771d

File tree

9 files changed

+340
-95
lines changed

9 files changed

+340
-95
lines changed

package-lock.json

Lines changed: 248 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@apollo/react-hooks": "^3.1.2",
7+
"apollo-boost": "^0.4.4",
68
"apollo-server-lambda": "2.9.3",
79
"encoding": "0.1.12",
8-
"graphql": "14.5.4",
10+
"graphql": "^14.5.4",
911
"graphql-tag-pluck": "0.8.4",
1012
"merge-graphql-schemas": "1.7.0",
1113
"netlify-lambda": "1.6.3",
1214
"react": "^16.9.0",
1315
"react-dom": "^16.9.0",
16+
"react-router-dom": "^5.1.2",
1417
"react-scripts": "3.1.1"
1518
},
1619
"scripts": {

src/App.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/App.css renamed to src/components/home.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
.App {
1+
.home {
22
text-align: center;
33
}
44

5-
.App-logo {
6-
animation: App-logo-spin infinite 20s linear;
5+
.home-logo {
6+
animation: home-logo-spin infinite 20s linear;
77
height: 40vmin;
88
pointer-events: none;
99
}
1010

11-
.App-header {
11+
.home-header {
1212
background-color: #282c34;
1313
min-height: 100vh;
1414
display: flex;
@@ -19,11 +19,11 @@
1919
color: white;
2020
}
2121

22-
.App-link {
22+
.home-link {
2323
color: #61dafb;
2424
}
2525

26-
@keyframes App-logo-spin {
26+
@keyframes home-logo-spin {
2727
from {
2828
transform: rotate(0deg);
2929
}

src/components/home.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import logo from '../logo.svg';
3+
import './home.css';
4+
5+
function Home(props) {
6+
7+
const { loading, error, data} = props;
8+
console.log(props)
9+
return (
10+
<div className="home">
11+
<header className="home-header">
12+
<img src={logo} className="home-logo" alt="logo" />
13+
<p>
14+
Edit <code>src/App.js</code> and save to reload.
15+
</p>
16+
<a
17+
className="home-link"
18+
href="https://reactjs.org"
19+
target="_blank"
20+
rel="noopener noreferrer"
21+
>
22+
Learn React
23+
</a>
24+
</header>
25+
</div>
26+
);
27+
}
28+
29+
export default Home;

src/containers/home.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from "react";
2+
import Home from "../components/home.js";
3+
import { useQuery } from "@apollo/react-hooks";
4+
import { EXCHANGE_RATES } from "../queries/foo";
5+
6+
function HomeContainer() {
7+
const { loading, error, data } = useQuery(EXCHANGE_RATES);
8+
9+
return <Home loading={loading} error={error} data={data} />;
10+
}
11+
12+
export default HomeContainer;

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import './index.css';
4-
import App from './App';
4+
import Routes from './router';
55
import * as serviceWorker from './serviceWorker';
66

7-
ReactDOM.render(<App />, document.getElementById('root'));
7+
ReactDOM.render(<Routes />, document.getElementById('root'));
88

99
// If you want your app to work offline and load faster, you can change
1010
// unregister() to register() below. Note this comes with some pitfalls.

src/queries/foo.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { gql } from 'apollo-boost';
2+
3+
4+
export const EXCHANGE_RATES = gql`
5+
{
6+
rates(currency: "USD") {
7+
currency
8+
rate
9+
}
10+
}
11+
`;

src/router.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from "react";
2+
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
3+
import HomeContainer from "./containers/home";
4+
import ApolloClient from "apollo-boost";
5+
import { ApolloProvider } from "@apollo/react-hooks";
6+
7+
// TODO: Move uri value to config file
8+
const client = new ApolloClient({
9+
uri: "https://48p1r2roz4.sse.codesandbox.io"
10+
});
11+
12+
const Routes = () => {
13+
return (
14+
<div>
15+
<ApolloProvider client={client}>
16+
<Router>
17+
<Switch>
18+
<Route path="/">
19+
<HomeContainer />
20+
</Route>
21+
</Switch>
22+
</Router>
23+
</ApolloProvider>
24+
</div>
25+
);
26+
};
27+
28+
export default Routes;

0 commit comments

Comments
 (0)