From f1f9dcb031b5b0c6dfc79e3831594737b0c4e99d Mon Sep 17 00:00:00 2001 From: Bel Curcio Date: Thu, 2 Jun 2022 14:31:14 +0200 Subject: [PATCH 1/7] Updating dependencies, adding image domains, error handling and more --- examples/cms-wordpress/lib/api.js | 7 ++++--- examples/cms-wordpress/next.config.js | 10 +++++++++- examples/cms-wordpress/package.json | 10 +++++----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/examples/cms-wordpress/lib/api.js b/examples/cms-wordpress/lib/api.js index cabad8f8113fb..93e98c2a4b3ef 100644 --- a/examples/cms-wordpress/lib/api.js +++ b/examples/cms-wordpress/lib/api.js @@ -1,6 +1,6 @@ const API_URL = process.env.WORDPRESS_API_URL -async function fetchAPI(query, { variables } = {}) { +async function fetchAPI(query="", { variables } = {}) { const headers = { 'Content-Type': 'application/json' } if (process.env.WORDPRESS_AUTH_REFRESH_TOKEN) { @@ -9,9 +9,10 @@ async function fetchAPI(query, { variables } = {}) { ] = `Bearer ${process.env.WORDPRESS_AUTH_REFRESH_TOKEN}` } - const res = await fetch(API_URL, { - method: 'POST', + // WPGraphQL Plugin must be enabled + const res = await fetch(`${API_URL}/graphql`, { headers, + method: 'POST', body: JSON.stringify({ query, variables, diff --git a/examples/cms-wordpress/next.config.js b/examples/cms-wordpress/next.config.js index de6202d75136e..913deb813f94b 100644 --- a/examples/cms-wordpress/next.config.js +++ b/examples/cms-wordpress/next.config.js @@ -1,7 +1,15 @@ +if (!process.env.WORDPRESS_API_URL) { + throw new Error(` + Please provide a valid Wordpres Instance URL. + Add to your enviorment variables WORDPRESS_API_URL. + `) +} + module.exports = { images: { domains: [ - // "[yourapp].wpengine.com" (Update this to be your Wordpress application name in order to load images connected to your posts) + process.env.WORDPRESS_API_URL.match(/(http(?:s)?:\/\/)(.*)/)[2], // Valid WP Image domain. + '2.gravatar.com', 'secure.gravatar.com', ], }, diff --git a/examples/cms-wordpress/package.json b/examples/cms-wordpress/package.json index daf83ed66dafe..bc75320d79849 100644 --- a/examples/cms-wordpress/package.json +++ b/examples/cms-wordpress/package.json @@ -9,12 +9,12 @@ "classnames": "2.3.1", "date-fns": "2.28.0", "next": "latest", - "react": "^17.0.2", - "react-dom": "^17.0.2" + "react": "^18.1.0", + "react-dom": "^18.1.0" }, "devDependencies": { - "autoprefixer": "10.4.2", - "postcss": "8.4.5", - "tailwindcss": "^3.0.15" + "autoprefixer": "10.4.7", + "postcss": "8.4.14", + "tailwindcss": "^3.0.24" } } From dd28817a6537fe37c79282f5583b5661a62f5f97 Mon Sep 17 00:00:00 2001 From: Bel Curcio Date: Thu, 2 Jun 2022 14:50:21 +0200 Subject: [PATCH 2/7] Updating dependencies, adding image domains, error handling and more --- examples/cms-wordpress/.env.local.example | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/cms-wordpress/.env.local.example b/examples/cms-wordpress/.env.local.example index da7755db65688..ed43c5cffd7ef 100644 --- a/examples/cms-wordpress/.env.local.example +++ b/examples/cms-wordpress/.env.local.example @@ -1,5 +1,6 @@ WORDPRESS_API_URL= + # Only required if you want to enable preview mode # WORDPRESS_AUTH_REFRESH_TOKEN= # WORDPRESS_PREVIEW_SECRET= \ No newline at end of file From 3280475fd0740512b26b1875f4ec07d7854fd1ac Mon Sep 17 00:00:00 2001 From: Bel Curcio Date: Thu, 2 Jun 2022 15:20:25 +0200 Subject: [PATCH 3/7] Updating dependencies, adding image domains, error handling and more --- examples/cms-wordpress/package.json | 3 ++- examples/cms-wordpress/pages/index.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/cms-wordpress/package.json b/examples/cms-wordpress/package.json index bc75320d79849..8715585cc30a3 100644 --- a/examples/cms-wordpress/package.json +++ b/examples/cms-wordpress/package.json @@ -3,7 +3,8 @@ "scripts": { "dev": "next", "build": "next build", - "start": "next start" + "start": "next start", + "lint": "next lint" }, "dependencies": { "classnames": "2.3.1", diff --git a/examples/cms-wordpress/pages/index.js b/examples/cms-wordpress/pages/index.js index 02f5a7471980d..de90321f36326 100644 --- a/examples/cms-wordpress/pages/index.js +++ b/examples/cms-wordpress/pages/index.js @@ -39,5 +39,6 @@ export async function getStaticProps({ preview = false }) { return { props: { allPosts, preview }, + revalidate: 10, } } From ab9be64bd7688d44dc380b58eabd53421f72172c Mon Sep 17 00:00:00 2001 From: Bel Curcio Date: Thu, 2 Jun 2022 15:52:24 +0200 Subject: [PATCH 4/7] Updating dependencies, adding image domains, error handling and more --- examples/cms-wordpress/pages/posts/[slug].js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/cms-wordpress/pages/posts/[slug].js b/examples/cms-wordpress/pages/posts/[slug].js index dc06089f58310..0060fb88d848a 100644 --- a/examples/cms-wordpress/pages/posts/[slug].js +++ b/examples/cms-wordpress/pages/posts/[slug].js @@ -70,6 +70,7 @@ export async function getStaticProps({ params, preview = false, previewData }) { post: data.post, posts: data.posts, }, + revalidate: 10, // In seconds } } From d7d8e1861fdbffe311240c09b5ccf0136dfada68 Mon Sep 17 00:00:00 2001 From: Bel Curcio Date: Thu, 2 Jun 2022 15:57:24 +0200 Subject: [PATCH 5/7] typo --- examples/cms-wordpress/pages/posts/[slug].js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/cms-wordpress/pages/posts/[slug].js b/examples/cms-wordpress/pages/posts/[slug].js index 0060fb88d848a..ec8ca926f23ae 100644 --- a/examples/cms-wordpress/pages/posts/[slug].js +++ b/examples/cms-wordpress/pages/posts/[slug].js @@ -70,7 +70,7 @@ export async function getStaticProps({ params, preview = false, previewData }) { post: data.post, posts: data.posts, }, - revalidate: 10, // In seconds + revalidate: 10, } } From d8a4c5ecfa46e90b069766668a387fefaa736990 Mon Sep 17 00:00:00 2001 From: Lee Robinson Date: Thu, 2 Jun 2022 09:02:44 -0500 Subject: [PATCH 6/7] Apply suggestions from code review --- examples/cms-wordpress/next.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cms-wordpress/next.config.js b/examples/cms-wordpress/next.config.js index 913deb813f94b..25f6638616860 100644 --- a/examples/cms-wordpress/next.config.js +++ b/examples/cms-wordpress/next.config.js @@ -1,7 +1,7 @@ if (!process.env.WORDPRESS_API_URL) { throw new Error(` - Please provide a valid Wordpres Instance URL. - Add to your enviorment variables WORDPRESS_API_URL. + Please provide a valid WordPress instance URL. + Add to your environment variables WORDPRESS_API_URL. `) } From cd236d6ad91577841346be1f75ed60ba92ab77ac Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 3 Jun 2022 02:26:58 -0400 Subject: [PATCH 7/7] lint-fix --- examples/cms-wordpress/lib/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/cms-wordpress/lib/api.js b/examples/cms-wordpress/lib/api.js index 93e98c2a4b3ef..6f3cb8131bf90 100644 --- a/examples/cms-wordpress/lib/api.js +++ b/examples/cms-wordpress/lib/api.js @@ -1,6 +1,6 @@ const API_URL = process.env.WORDPRESS_API_URL -async function fetchAPI(query="", { variables } = {}) { +async function fetchAPI(query = '', { variables } = {}) { const headers = { 'Content-Type': 'application/json' } if (process.env.WORDPRESS_AUTH_REFRESH_TOKEN) {