From c10c59b8977d5847955d2297c64057952460d321 Mon Sep 17 00:00:00 2001 From: Jack Clark Date: Mon, 11 Mar 2019 15:40:10 +0000 Subject: [PATCH 1/3] chore: add example create-react-app app --- examples/create-react-app/README.md | 68 ++++++++++++++++++ examples/create-react-app/package.json | 27 +++++++ examples/create-react-app/public/favicon.ico | Bin 0 -> 3870 bytes examples/create-react-app/public/index.html | 45 ++++++++++++ .../create-react-app/public/manifest.json | 15 ++++ examples/create-react-app/src/App.js | 17 +++++ .../src/components/CreatePost.js | 24 +++++++ .../src/components/CreatePostForm.js | 35 +++++++++ .../create-react-app/src/components/Posts.js | 43 +++++++++++ examples/create-react-app/src/index.css | 14 ++++ examples/create-react-app/src/index.js | 7 ++ lerna.json | 6 +- 12 files changed, 297 insertions(+), 4 deletions(-) create mode 100644 examples/create-react-app/README.md create mode 100644 examples/create-react-app/package.json create mode 100644 examples/create-react-app/public/favicon.ico create mode 100644 examples/create-react-app/public/index.html create mode 100644 examples/create-react-app/public/manifest.json create mode 100644 examples/create-react-app/src/App.js create mode 100644 examples/create-react-app/src/components/CreatePost.js create mode 100644 examples/create-react-app/src/components/CreatePostForm.js create mode 100644 examples/create-react-app/src/components/Posts.js create mode 100644 examples/create-react-app/src/index.css create mode 100644 examples/create-react-app/src/index.js diff --git a/examples/create-react-app/README.md b/examples/create-react-app/README.md new file mode 100644 index 00000000..9d9614c4 --- /dev/null +++ b/examples/create-react-app/README.md @@ -0,0 +1,68 @@ +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.
+You will also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.
+See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.
+It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.
+Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +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. + +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. + +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. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting + +### Analyzing the Bundle Size + +This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size + +### Making a Progressive Web App + +This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app + +### Advanced Configuration + +This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration + +### Deployment + +This section has moved here: https://facebook.github.io/create-react-app/docs/deployment + +### `npm run build` fails to minify + +This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify diff --git a/examples/create-react-app/package.json b/examples/create-react-app/package.json new file mode 100644 index 00000000..4c6306e8 --- /dev/null +++ b/examples/create-react-app/package.json @@ -0,0 +1,27 @@ +{ + "name": "create-react-app", + "version": "0.1.0", + "private": true, + "dependencies": { + "graphql-hooks": "3.3.0", + "graphql-hooks-memcache": "1.1.0", + "react": "16.8.4", + "react-dom": "16.8.4", + "react-scripts": "2.1.8" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": "react-app" + }, + "browserslist": [ + ">0.2%", + "not dead", + "not ie <= 11", + "not op_mini all" + ] +} diff --git a/examples/create-react-app/public/favicon.ico b/examples/create-react-app/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..a11777cc471a4344702741ab1c8a588998b1311a GIT binary patch literal 3870 zcma);c{J4h9>;%nil|2-o+rCuEF-(I%-F}ijC~o(k~HKAkr0)!FCj~d>`RtpD?8b; zXOC1OD!V*IsqUwzbMF1)-gEDD=A573Z-&G7^LoAC9|WO7Xc0Cx1g^Zu0u_SjAPB3vGa^W|sj)80f#V0@M_CAZTIO(t--xg= z!sii`1giyH7EKL_+Wi0ab<)&E_0KD!3Rp2^HNB*K2@PHCs4PWSA32*-^7d{9nH2_E zmC{C*N*)(vEF1_aMamw2A{ZH5aIDqiabnFdJ|y0%aS|64E$`s2ccV~3lR!u<){eS` z#^Mx6o(iP1Ix%4dv`t@!&Za-K@mTm#vadc{0aWDV*_%EiGK7qMC_(`exc>-$Gb9~W!w_^{*pYRm~G zBN{nA;cm^w$VWg1O^^<6vY`1XCD|s_zv*g*5&V#wv&s#h$xlUilPe4U@I&UXZbL z0)%9Uj&@yd03n;!7do+bfixH^FeZ-Ema}s;DQX2gY+7g0s(9;`8GyvPY1*vxiF&|w z>!vA~GA<~JUqH}d;DfBSi^IT*#lrzXl$fNpq0_T1tA+`A$1?(gLb?e#0>UELvljtQ zK+*74m0jn&)5yk8mLBv;=@}c{t0ztT<v;Avck$S6D`Z)^c0(jiwKhQsn|LDRY&w(Fmi91I7H6S;b0XM{e zXp0~(T@k_r-!jkLwd1_Vre^v$G4|kh4}=Gi?$AaJ)3I+^m|Zyj#*?Kp@w(lQdJZf4 z#|IJW5z+S^e9@(6hW6N~{pj8|NO*>1)E=%?nNUAkmv~OY&ZV;m-%?pQ_11)hAr0oAwILrlsGawpxx4D43J&K=n+p3WLnlDsQ$b(9+4 z?mO^hmV^F8MV{4Lx>(Q=aHhQ1){0d*(e&s%G=i5rq3;t{JC zmgbn5Nkl)t@fPH$v;af26lyhH!k+#}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F`*7#ecO7I)Q$uZsV+xS4E7aUn+U(K baj7?x%VD!5Cxk2YbYLNVeiXvvpMCWYo=by@ literal 0 HcmV?d00001 diff --git a/examples/create-react-app/public/index.html b/examples/create-react-app/public/index.html new file mode 100644 index 00000000..eba56131 --- /dev/null +++ b/examples/create-react-app/public/index.html @@ -0,0 +1,45 @@ + + + + + + + + + + + + Postie - A graphql-hooks example + + + +
+ + + diff --git a/examples/create-react-app/public/manifest.json b/examples/create-react-app/public/manifest.json new file mode 100644 index 00000000..8858deb4 --- /dev/null +++ b/examples/create-react-app/public/manifest.json @@ -0,0 +1,15 @@ +{ + "short_name": "React App", + "name": "Postie", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/examples/create-react-app/src/App.js b/examples/create-react-app/src/App.js new file mode 100644 index 00000000..3b59e8ed --- /dev/null +++ b/examples/create-react-app/src/App.js @@ -0,0 +1,17 @@ +import React from 'react' +import { GraphQLClient, ClientContext } from 'graphql-hooks' + +import Posts from './components/Posts' + +const client = new GraphQLClient({ + url: 'https://api.graph.cool/simple/v1/cjs4qo29b2w0c0130tfx6maca' +}) + +export default function App() { + return ( + +

Postie

+ +
+ ) +} diff --git a/examples/create-react-app/src/components/CreatePost.js b/examples/create-react-app/src/components/CreatePost.js new file mode 100644 index 00000000..4ad349df --- /dev/null +++ b/examples/create-react-app/src/components/CreatePost.js @@ -0,0 +1,24 @@ +import React from 'react' +import { useMutation } from 'graphql-hooks' + +import CreatePostForm from './CreatePostForm' + +const createPostMutation = ` + mutation CreatePost($title: String!, $url: String!) { + createPost(title: $title, url: $url) { + id + } + } +` +export default function CreatePost({ onSuccess }) { + const [createPost, { loading, error }] = useMutation(createPostMutation) + + async function handleSubmit({ title, url }) { + await createPost({ variables: { title, url } }) + onSuccess() + } + + return ( + + ) +} diff --git a/examples/create-react-app/src/components/CreatePostForm.js b/examples/create-react-app/src/components/CreatePostForm.js new file mode 100644 index 00000000..524b79c0 --- /dev/null +++ b/examples/create-react-app/src/components/CreatePostForm.js @@ -0,0 +1,35 @@ +import React, { useState } from 'react' + +export default function CreatePostForm({ loading, error, onSubmit }) { + const [title, setTitle] = useState('') + const [url, setUrl] = useState('') + + function handleSubmit(e) { + e.preventDefault() + onSubmit({ title, url }) + } + + return ( +
+ + setTitle(e.currentTarget.value)} + /> + + setUrl(e.currentTarget.value)} + /> + + {error &&

Oh no! There was an error when adding this post.

} +
+ ) +} diff --git a/examples/create-react-app/src/components/Posts.js b/examples/create-react-app/src/components/Posts.js new file mode 100644 index 00000000..3d84704e --- /dev/null +++ b/examples/create-react-app/src/components/Posts.js @@ -0,0 +1,43 @@ +import React from 'react' +import { useQuery } from 'graphql-hooks' + +import CreatePost from './CreatePost' + +export const allPostsQuery = ` + query { + allPosts(orderBy: createdAt_DESC, first: 20) { + id + title + url + } + } +` + +export default function Posts() { + const { loading, data, error, refetch } = useQuery(allPostsQuery) + + return ( + <> +

Add post

+ +

Posts

+ + + ) +} + +function PostList({ loading, error, data }) { + if (loading) return 'Loading...' + if (error) return 'There was an error loading the posts :(' + if (!data || !data.allPosts || !data.allPosts.length) return 'No posts' + + return ( +
+ ) +} diff --git a/examples/create-react-app/src/index.css b/examples/create-react-app/src/index.css new file mode 100644 index 00000000..0dd8db93 --- /dev/null +++ b/examples/create-react-app/src/index.css @@ -0,0 +1,14 @@ +body { + margin: 10px; + padding: 10px; + font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', + 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', + 'Helvetica Neue', sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; +} diff --git a/examples/create-react-app/src/index.js b/examples/create-react-app/src/index.js new file mode 100644 index 00000000..0d5d632e --- /dev/null +++ b/examples/create-react-app/src/index.js @@ -0,0 +1,7 @@ +import React from 'react' +import ReactDOM from 'react-dom' + +import App from './App' +import './index.css' + +ReactDOM.render(, document.getElementById('root')) diff --git a/lerna.json b/lerna.json index f850e601..5ccdf684 100644 --- a/lerna.json +++ b/lerna.json @@ -2,9 +2,6 @@ "packages": ["packages/*", "examples/*"], "version": "independent", "command": { - "bootstrap": { - "npmClientArgs": ["--no-package-lock"] - }, "publish": { "conventionalCommits": true, "message": "chore(release): :rocket:" @@ -13,7 +10,8 @@ "conventionalCommits": true }, "bootstrap": { - "hoist": ["react", "react-dom"] + "hoist": ["react", "react-dom"], + "npmClientArgs": ["--no-package-lock"] } } } From 71309971dc79fcbe707c032c4ecef43b8a0871fd Mon Sep 17 00:00:00 2001 From: Jack Clark Date: Mon, 11 Mar 2019 17:04:33 +0000 Subject: [PATCH 2/3] chore: add prop type defs to example app --- examples/create-react-app/package.json | 4 +--- examples/create-react-app/src/components/CreatePost.js | 7 ++++++- .../create-react-app/src/components/CreatePostForm.js | 7 +++++++ examples/create-react-app/src/components/Posts.js | 9 +++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/examples/create-react-app/package.json b/examples/create-react-app/package.json index 4c6306e8..85168361 100644 --- a/examples/create-react-app/package.json +++ b/examples/create-react-app/package.json @@ -5,6 +5,7 @@ "dependencies": { "graphql-hooks": "3.3.0", "graphql-hooks-memcache": "1.1.0", + "prop-types": "15.7.2", "react": "16.8.4", "react-dom": "16.8.4", "react-scripts": "2.1.8" @@ -15,9 +16,6 @@ "test": "react-scripts test", "eject": "react-scripts eject" }, - "eslintConfig": { - "extends": "react-app" - }, "browserslist": [ ">0.2%", "not dead", diff --git a/examples/create-react-app/src/components/CreatePost.js b/examples/create-react-app/src/components/CreatePost.js index 4ad349df..803e3be0 100644 --- a/examples/create-react-app/src/components/CreatePost.js +++ b/examples/create-react-app/src/components/CreatePost.js @@ -1,4 +1,5 @@ import React from 'react' +import PropTypes from 'prop-types' import { useMutation } from 'graphql-hooks' import CreatePostForm from './CreatePostForm' @@ -15,10 +16,14 @@ export default function CreatePost({ onSuccess }) { async function handleSubmit({ title, url }) { await createPost({ variables: { title, url } }) - onSuccess() + onSuccess && onSuccess() } return ( ) } + +CreatePost.propTypes = { + onSuccess: PropTypes.func +} diff --git a/examples/create-react-app/src/components/CreatePostForm.js b/examples/create-react-app/src/components/CreatePostForm.js index 524b79c0..378d9b8b 100644 --- a/examples/create-react-app/src/components/CreatePostForm.js +++ b/examples/create-react-app/src/components/CreatePostForm.js @@ -1,4 +1,5 @@ import React, { useState } from 'react' +import PropTypes from 'prop-types' export default function CreatePostForm({ loading, error, onSubmit }) { const [title, setTitle] = useState('') @@ -33,3 +34,9 @@ export default function CreatePostForm({ loading, error, onSubmit }) { ) } + +CreatePostForm.propTypes = { + loading: PropTypes.bool, + error: PropTypes.bool, + onSubmit: PropTypes.func.isRequired +} diff --git a/examples/create-react-app/src/components/Posts.js b/examples/create-react-app/src/components/Posts.js index 3d84704e..8cb115da 100644 --- a/examples/create-react-app/src/components/Posts.js +++ b/examples/create-react-app/src/components/Posts.js @@ -1,4 +1,5 @@ import React from 'react' +import PropTypes from 'prop-types' import { useQuery } from 'graphql-hooks' import CreatePost from './CreatePost' @@ -41,3 +42,11 @@ function PostList({ loading, error, data }) { ) } + +PostList.propTypes = { + loading: PropTypes.bool, + error: PropTypes.bool, + data: PropTypes.shape({ + allPosts: PropTypes.array + }) +} From 47af9c1cdbbdc2e2d7bcba2ffb05421bc6a60c7f Mon Sep 17 00:00:00 2001 From: Joe Warren Date: Tue, 12 Mar 2019 10:03:04 +0000 Subject: [PATCH 3/3] Update examples/create-react-app/package.json Co-Authored-By: jackdclark <1485654+jackdclark@users.noreply.github.com> --- examples/create-react-app/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/create-react-app/package.json b/examples/create-react-app/package.json index 85168361..44c931f7 100644 --- a/examples/create-react-app/package.json +++ b/examples/create-react-app/package.json @@ -11,7 +11,7 @@ "react-scripts": "2.1.8" }, "scripts": { - "start": "react-scripts start", + "start": "SKIP_PREFLIGHT_CHECK=true react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject"