Skip to content

Commit 4681ed9

Browse files
author
Turbo
committed
Test husky
1 parent 8380d0f commit 4681ed9

14 files changed

+258
-86
lines changed

package.json

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"@babel/preset-react": "^7.0.0",
2727
"@babel/register": "^7.0.0",
2828
"@babel/runtime": "^7.2.0",
29+
"apollo-cache-inmemory": "^1.3.12",
30+
"apollo-client": "^2.4.8",
31+
"apollo-link-http": "^1.5.9",
2932
"babel-loader": "^8.0.4",
3033
"babel-plugin-inline-dotenv": "^1.2.0",
3134
"babel-plugin-module-resolver": "^3.1.1",
@@ -37,12 +40,16 @@
3740
"express": "^4.16.4",
3841
"express-static-gzip": "^1.1.3",
3942
"file-loader": "^3.0.1",
43+
"graphql": "^14.0.2",
44+
"graphql-tag": "^2.10.0",
4045
"import": "0.0.6",
4146
"isomorphic-fetch": "^2.2.1",
47+
"isomorphic-unfetch": "^3.0.0",
4248
"markdown-with-front-matter-loader": "^0.1.0",
4349
"node-noop": "^1.0.0",
4450
"prop-types": "^15.6.2",
4551
"react": "^16.7.0",
52+
"react-apollo": "^2.3.3",
4653
"react-dom": "^16.7.0",
4754
"react-helmet": "^5.2.0",
4855
"react-hot-loader": "^4.6.3",

src/App/AppWrapper.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { ThemeProvider } from 'styled-components';
44

5+
import { ApolloProvider } from 'react-apollo';
6+
57
import theme from 'src/styles/theme';
68
import GlobalizeStyle from 'src/styles/global-styles';
79
import App from 'src/App';
10+
import apolloClient from 'src/data';
811

912
const AppWrapper = ({ lang }) => (
10-
<ThemeProvider theme={theme}>
11-
<React.Fragment>
12-
<GlobalizeStyle />
13-
<App lang={lang} />
14-
</React.Fragment>
15-
</ThemeProvider>
13+
<ApolloProvider client={apolloClient}>
14+
<ThemeProvider theme={theme}>
15+
<React.Fragment>
16+
<GlobalizeStyle />
17+
<App lang={lang} />
18+
</React.Fragment>
19+
</ThemeProvider>
20+
</ApolloProvider>
1621
);
1722

1823
AppWrapper.propTypes = {

src/Components/Head/index.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { Helmet } from 'react-helmet';
33
import PropTypes from 'prop-types';
4+
import favicon from 'src/assets/images/favicon.png';
45

56
const isProd = process.env.NODE_ENV === 'production';
67

@@ -14,13 +15,9 @@ const Head = ({
1415
<meta property="og:title" content={title} />
1516
<meta property="og:description" content={desc} />
1617
<meta property="og:image" content={image} />
17-
<link
18-
rel="shortcut icon"
19-
type="image/x-icon"
20-
href="https://i.imgur.com/mMOR6Y7.png"
21-
/>
22-
<link rel="icon" sizes="192x192" href="https://i.imgur.com/mMOR6Y7.png" />
23-
<link rel="apple-touch-icon-precomposed" href="https://i.imgur.com/mMOR6Y7.png" />
18+
<link rel="shortcut icon" type="image/x-icon" href={favicon} />
19+
<link rel="icon" sizes="192x192" href={favicon} />
20+
<link rel="apple-touch-icon-precomposed" href={favicon} />
2421
<link
2522
rel="manifest"
2623
href={`${isProd ? 'https://production/' : 'http://localhost:8080/'}manifest.json`}

src/Pages/Books/index.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
import React from 'react';
2+
import { Query } from 'react-apollo';
3+
import gql from 'graphql-tag';
24
import PropTypes from 'prop-types';
5+
36
import { fetchAllBooks } from 'src/helpers/loadData';
47
import Head from 'src/Components/Head';
58
import FlexBox from 'src/Components/FlexBox';
69
import { H3 } from 'src/Components/Typo';
710

11+
const queryBooks = gql`
12+
{
13+
books {
14+
id
15+
title
16+
authors {
17+
id
18+
username
19+
}
20+
}
21+
}
22+
`;
823

924
class Books extends React.Component {
1025
// Check if staticContext exists
@@ -36,7 +51,21 @@ class Books extends React.Component {
3651
return (
3752
<React.Fragment>
3853
<Head title="Books" />
39-
<FlexBox width={1/2} mx="auto" flexDirection="column" alignItems="flex-start">
54+
<Query query={queryBooks}>
55+
{({ loading, error, data }) => {
56+
if (loading) return <p>Loading...</p>;
57+
if (error) return <p>Error :(</p>;
58+
59+
return (
60+
<FlexBox width={1 / 2} mx="auto" flexDirection="column" alignItems="flex-start">
61+
{
62+
data.books.map(book => <H3 key={book.id}>{book.title}</H3>)
63+
}
64+
</FlexBox>
65+
);
66+
}}
67+
</Query>
68+
<FlexBox width={1 / 2} mx="auto" flexDirection="column" alignItems="flex-start">
4069
{
4170
books.map(book => <H3 key={book.id}>{book.title}</H3>)
4271
}
-57.5 KB
Binary file not shown.
-95.5 KB
Binary file not shown.
-10.6 KB
Binary file not shown.
-16.3 KB
Binary file not shown.
-96 KB
Binary file not shown.
-358 KB
Binary file not shown.

src/data/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ApolloClient } from 'apollo-client';
2+
import { HttpLink } from 'apollo-link-http';
3+
import { InMemoryCache } from 'apollo-cache-inmemory';
4+
5+
const brightizenBeUri = 'http://localhost:3001/graphql';
6+
7+
const client = new ApolloClient({
8+
link: new HttpLink({ uri: brightizenBeUri }),
9+
cache: new InMemoryCache(),
10+
});
11+
12+
export default client;

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { hydrate } from 'react-dom';
33
import { AppContainer } from 'react-hot-loader';
4+
45
import Client from './App/Client';
56

67
const render = (Component) => {

src/server/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
require('isomorphic-unfetch');
12
require('@babel/register');
23
require('./express');

0 commit comments

Comments
 (0)