Skip to content

Commit 8582a9a

Browse files
authored
docs: GQL Blog Example (TanStack#1144)
* added an example repo using React Query to manage the data comming from a GQL back end to serve content * removed * readded without .git
1 parent 8585a17 commit 8582a9a

23 files changed

+693
-0
lines changed

examples/gql-blog/.gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

examples/gql-blog/README.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `yarn start`
8+
9+
Runs the app in the development mode.<br />
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.<br />
13+
You will also see any lint errors in the console.
14+
15+
### `yarn test`
16+
17+
Launches the test runner in the interactive watch mode.<br />
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `yarn build`
21+
22+
Builds the app for production to the `build` folder.<br />
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.<br />
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29+
30+
### `yarn eject`
31+
32+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33+
34+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35+
36+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37+
38+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39+
40+
## Learn More
41+
42+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43+
44+
To learn React, check out the [React documentation](https://reactjs.org/).
45+
46+
### Code Splitting
47+
48+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49+
50+
### Analyzing the Bundle Size
51+
52+
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53+
54+
### Making a Progressive Web App
55+
56+
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57+
58+
### Advanced Configuration
59+
60+
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61+
62+
### Deployment
63+
64+
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65+
66+
### `yarn build` fails to minify
67+
68+
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

examples/gql-blog/package.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "blog-query",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@fortawesome/fontawesome-svg-core": "^1.2.32",
7+
"@fortawesome/free-solid-svg-icons": "^5.15.1",
8+
"@fortawesome/react-fontawesome": "^0.1.11",
9+
"@testing-library/jest-dom": "^4.2.4",
10+
"@testing-library/react": "^9.3.2",
11+
"@testing-library/user-event": "^7.1.2",
12+
"graphql": "^15.3.0",
13+
"graphql-request": "^3.1.0",
14+
"react": "^16.13.1",
15+
"react-dom": "^16.13.1",
16+
"react-markdown": "^4.3.1",
17+
"react-query": "^2.23.1",
18+
"react-query-devtools": "^2.5.1",
19+
"react-router": "^5.2.0",
20+
"react-router-dom": "^5.2.0",
21+
"react-scripts": "3.4.3",
22+
"react-syntax-highlighter": "^15.1.0",
23+
"sriracha-ui": "^1.8.3"
24+
},
25+
"scripts": {
26+
"start": "react-scripts start",
27+
"build": "react-scripts build",
28+
"test": "react-scripts test",
29+
"eject": "react-scripts eject"
30+
},
31+
"eslintConfig": {
32+
"extends": "react-app"
33+
},
34+
"browserslist": {
35+
"production": [
36+
">0.2%",
37+
"not dead",
38+
"not op_mini all"
39+
],
40+
"development": [
41+
"last 1 chrome version",
42+
"last 1 firefox version",
43+
"last 1 safari version"
44+
]
45+
}
46+
}
Loading
Loading
18.6 KB
Loading
847 Bytes
Loading
2.15 KB
Loading

examples/gql-blog/public/favicon.ico

15 KB
Binary file not shown.

examples/gql-blog/public/index.html

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<title>React Query GQL Blog</title>
6+
<meta charSet="utf-8" />
7+
<meta name="viewport"
8+
content="initial-scale=1.0, width=device-width" />
9+
<link rel="apple-touch-icon" sizes="180x180"
10+
href="/apple-touch-icon.png" />
11+
<link rel="icon" type="image/png" sizes="32x32"
12+
href="/favicon-32x32.png" />
13+
<link rel="icon" type="image/png" sizes="16x16"
14+
href="/favicon-16x16.png" />
15+
<link rel="manifest" href="/site.webmanifest" />
16+
<link rel="mask-icon" href="/safari-pinned-tab.svg"
17+
color="#5bbad5" />
18+
<meta name="msapplication-TileColor" content="#ffc40d" />
19+
<meta name="theme-color" content="#fafafa" />
20+
</head>
21+
22+
<body>
23+
<noscript>You need to enable JavaScript to run this
24+
app.</noscript>
25+
<div id="root"></div>
26+
<!--
27+
This HTML file is a template.
28+
If you open it directly in the browser, you will see an empty page.
29+
30+
You can add webfonts, meta tags, or analytics to this file.
31+
The build step will place the bundled scripts into the <body> tag.
32+
33+
To begin the development, run `npm start` or `yarn start`.
34+
To create a production bundle, use `npm run build` or `yarn build`.
35+
-->
36+
</body>
37+
38+
</html>

examples/gql-blog/public/robots.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "",
3+
"short_name": "",
4+
"icons": [{
5+
"src": "/android-chrome-192x192.png",
6+
"sizes": "192x192",
7+
"type": "image/png"
8+
}, {
9+
"src": "/android-chrome-512x512.png",
10+
"sizes": "512x512",
11+
"type": "image/png"
12+
}],
13+
"theme_color": "#ffffff",
14+
"background_color": "#ffffff",
15+
"display": "standalone"
16+
}

examples/gql-blog/src/App.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from "react";
2+
3+
import { Switch, Route } from "react-router";
4+
import Layout from "./components/Layout";
5+
import Home from "./pages/Home";
6+
import Blog from "./pages/Blog";
7+
8+
import { AppContainer, useDarkMode } from "sriracha-ui";
9+
10+
import { library } from "@fortawesome/fontawesome-svg-core";
11+
import { faMoon, faSun, faSpinner } from "@fortawesome/free-solid-svg-icons";
12+
import About from "./pages/About";
13+
14+
library.add(faMoon, faSun, faSpinner);
15+
16+
function App() {
17+
const { themeString, toggleTheme } = useDarkMode();
18+
19+
return (
20+
<AppContainer themeString={themeString} toggleTheme={toggleTheme}>
21+
<Layout>
22+
<Switch>
23+
<Route exact path="/" component={Home} />
24+
<Route exact path="/about" component={About} />
25+
<Route exact path="/:slug" component={Blog} />
26+
</Switch>
27+
</Layout>
28+
</AppContainer>
29+
);
30+
}
31+
32+
export default App;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from "react";
2+
import { Flex, Text } from "sriracha-ui";
3+
import { Link } from "react-router-dom";
4+
5+
export default function NavLink({ link }) {
6+
return (
7+
<Flex aic wrap="true" pointer>
8+
<Link to={link === "Home" ? "/" : `/${link.toLowerCase()}`}>
9+
<Text lf pointer color="gray9" hvrColor="gray5">
10+
{link}
11+
</Text>
12+
</Link>
13+
</Flex>
14+
);
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
import { Box } from "sriracha-ui";
3+
import NavLink from "./NavLink";
4+
5+
export default function NavLinks() {
6+
const links = ["Home", "About"];
7+
return (
8+
<>
9+
{links.map((link) => (
10+
<React.Fragment key={link}>
11+
<NavLink link={link} />
12+
<Box w="2rem" />
13+
</React.Fragment>
14+
))}
15+
</>
16+
);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import React from "react";
2+
import {
3+
Wrapper,
4+
NavBar,
5+
Box,
6+
Flex,
7+
Cabinet,
8+
useCabinet,
9+
useTheme,
10+
} from "sriracha-ui";
11+
import NavLinks from "./NavLinks";
12+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
13+
14+
const navHeight = "5rem";
15+
16+
export default function Layout({ children }) {
17+
const { isCabinet, toggleCabinet } = useCabinet();
18+
const { toggleTheme, themeString, lightTheme } = useTheme();
19+
const { colors } = lightTheme;
20+
return (
21+
<Wrapper>
22+
<header>
23+
<NavBar w="100%" bg="gray0" drape shadow={3} radius="0 0 0.4rem 0.4rem">
24+
<Flex w="100%" jcb aic h={navHeight}>
25+
<Box
26+
className="nav-cabinet-menu"
27+
m="0 0 0 2rem"
28+
pointer
29+
onClick={toggleCabinet}
30+
>
31+
<Flex drape w="2.2rem">
32+
<Box h="0.2rem" w="2rem" bg="gray9" />
33+
<Box h="0.5rem" />
34+
<Box h="0.2rem" w="2rem" bg="gray9" />
35+
<Box h="0.5rem" />
36+
<Box h="0.2rem" w="2rem" bg="gray9" />
37+
</Flex>
38+
</Box>
39+
<Box className="nav-link-list">
40+
<Flex m="0 0 0 2rem">
41+
<NavLinks />
42+
</Flex>
43+
</Box>
44+
<Flex
45+
as="button"
46+
onClick={toggleTheme}
47+
jcv
48+
aic
49+
p={1}
50+
mr={3}
51+
bg="none"
52+
radius="0.5rem"
53+
hvrBg="gray2"
54+
>
55+
{themeString === "dark" ? (
56+
<FontAwesomeIcon icon="sun" color={colors.amber3} size="lg" />
57+
) : (
58+
<FontAwesomeIcon icon="moon" color={colors.purple7} size="lg" />
59+
)}
60+
</Flex>
61+
</Flex>
62+
</NavBar>
63+
</header>
64+
<Cabinet active={isCabinet} toggle={toggleCabinet} shade>
65+
<Flex drape h="15rem" jcv>
66+
<NavLinks toggleCabinet={toggleCabinet} />
67+
</Flex>
68+
</Cabinet>
69+
<Flex drape stretch>
70+
<Box h={navHeight} />
71+
<Box />
72+
{children}
73+
</Flex>
74+
</Wrapper>
75+
);
76+
}

examples/gql-blog/src/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import App from "./App";
4+
import { BrowserRouter as Router } from "react-router-dom";
5+
import "./styles.css";
6+
7+
ReactDOM.render(
8+
<React.StrictMode>
9+
<Router>
10+
<App />
11+
</Router>
12+
</React.StrictMode>,
13+
document.getElementById("root")
14+
);

examples/gql-blog/src/pages/About.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from "react";
2+
import { Card, Text } from "sriracha-ui";
3+
4+
export default function About() {
5+
return (
6+
<Card maxW={9} w="96%" shade>
7+
<Text color="red6" size="5xl" as="h1" tac font="Raleway">
8+
About page
9+
</Text>
10+
<Text as="p">
11+
This is a simple blog created using React Query to manage all of our
12+
server state from Best Markdown Editor.
13+
</Text>
14+
</Card>
15+
);
16+
}

0 commit comments

Comments
 (0)