├── .gitignore
├── README.md
├── build
├── index.asset.php
├── index.js
└── index.js.map
├── functions.php
├── images
└── graphiql.png
├── package-lock.json
├── package.json
├── page-react.php
├── src
├── components
│ ├── post-w-votes
│ │ └── index.js
│ ├── posts
│ │ └── index.js
│ └── votes
│ │ └── index.js
└── index.js
├── style.css
└── webpack.config.js
/.gitignore:
--------------------------------------------------------------------------------
1 | composer.lock
2 | /node_modules/
3 | /vendor/
4 | /logs/
5 | /reports/
6 |
7 | .DS_Store
8 | .DS_Store?
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Twenty Twenty React Theme
2 | A Twenty Twenty Child WordPress Theme demonstrating how to load React on the front end of a theme.
3 |
--------------------------------------------------------------------------------
/build/index.asset.php:
--------------------------------------------------------------------------------
1 | array('wp-element', 'wp-polyfill'), 'version' => '62323e39c466b33087b243150f38640b');
--------------------------------------------------------------------------------
/functions.php:
--------------------------------------------------------------------------------
1 | get('Version')
13 | );
14 |
15 | wp_enqueue_script(
16 | 'my-theme-frontend',
17 | get_stylesheet_directory_uri() . '/build/index.js',
18 | ['wp-element', 'wp-components'],
19 | time(), //For production use wp_get_theme()->get('Version')
20 | true
21 | );
22 |
23 | }
24 |
25 | // Add Votes to Custom Meta Fields
26 | add_action( 'graphql_register_types', function() {
27 | register_graphql_field( 'Post', 'votes', [
28 | 'type' => 'Number',
29 | 'description' => __( 'The number of votes', 'wp-graphql' ),
30 | 'resolve' => function( $post ) {
31 | $votes = get_post_meta( $post->ID, 'votes', true );
32 | return ! empty( $votes ) ? $votes : 0;
33 | }
34 | ] );
35 | } );
--------------------------------------------------------------------------------
/images/graphiql.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zgordon/twentytwenty-react/b99a7fee5a475f940de4d049cb327cdee75e1ac2/images/graphiql.png
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "twentytwenty-react",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "devDependencies": {
7 | "@wordpress/scripts": "^5.1.0"
8 | },
9 | "scripts": {
10 | "build": "wp-scripts build",
11 | "check-engines": "wp-scripts check-engines",
12 | "check-licenses": "wp-scripts check-licenses",
13 | "lint:css": "wp-scripts lint-style",
14 | "lint:js": "wp-scripts lint-js",
15 | "lint:pkg-json": "wp-scripts lint-pkg-json",
16 | "start": "wp-scripts start",
17 | "test:e2e": "wp-scripts test-e2e",
18 | "test:unit": "wp-scripts test-unit-js"
19 | },
20 | "author": "",
21 | "license": "ISC",
22 | "dependencies": {
23 | "@apollo/react-hooks": "^3.1.3",
24 | "apollo-boost": "^0.4.4",
25 | "graphql": "^14.5.8"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/page-react.php:
--------------------------------------------------------------------------------
1 |
7 |
8 |
Loading posts...
; 23 | if (error) returnError :(
; 24 | 25 | // const [posts, setPosts] = useState([]); 26 | 27 | // const posts = [...data.posts.nodes]; 28 | 29 | // const sortedPosts = data.posts.nodes 30 | // .sort((a, b) => a.votes < b.votes) 31 | // .map(({ id, title, votes }) => ( 32 | //Loading posts...
; 21 | if (error) returnError :(
; 22 | 23 | return posts.map(({ postId, title }) =>15 | 16 |
17 |My First Apollo Theme!
17 |