Closed hadifarnoud closed 6 years ago
In your config you have excludedRoutes: ["/*/*/comments", "/yoast/**", "/akismet/**", "/oembed/**", "/wp/v2/**"],
. This "/wp/v2/**"
will cause not fetching any wordpress endpoints - try removing that
@pieh I did not have them excluded before. I was trying to fix the errors so I added this. I get this error without having /wp/v2/**
GraphQL Error Field "author" must not have a selection since type "Int" has no subfields.
file: /Users/hadifarnoud/playground/new-landing-shop/src/pages/index.jsx
1 |
2 | query IndexQuery {
3 | allWordpressPost {
4 | edges {
5 | node {
6 | featured_media {
7 | source_url
8 | }
> 9 | author {
| ^
10 | name
11 | avatar_urls {
12 | wordpress_24
13 | wordpress_48
14 | wordpress_96
15 | }
16 | }
17 | date
18 | slug
19 | title
As I explained in the issue, removing author
won't help
I reproduced this locally and this comes from this:
=== [ Fetching wordpress__wp_users ] === http://blog.kamva.ir/wp-json/wp/v2/users
⠄ source and transform nodesThe server response was "401 Unauthorized"
Inner exception message : "متاسفانه شما اجازهی مرور کاربران را ندارید."
Fetching the wordpress__wp_users took: 279.523ms
(translation of error message - "Sorry, you do not have permission to browse users.")
We don't have access to list of users so we can't expand author field into object leaving user_id
(Int) in schema.
To get that list I think we would need to authenticate. @sebastienfi Do You have any experience with this?
It's probably a WordPress plugin that is blocking access to enumerating users. Some believe it's a security concern. The default for WordPress is to make users public:
https://json.wpengine.com/wp-json/wp/v2/users
The easiest solution would be to find the plugin blocking access to the users endpoint and disabling it.
You might be able to use a WP REST API basic auth plugin to put the endpoint behind auth and configure gatsby-source-wordpress to use those creds, but I don't have any experience with this.
The WordFence security plugin was blocking this for me. I unchecked the option:
Prevent discovery of usernames through '/?author=N' scans, the oEmbed API, and the WordPress REST API
still can't get this to work even though useACF: false,
GraphQL Error Unknown field `acf` on type `wordpress__POST`
file: /Users/hadifarnoud/playground/new-landing-shop/src/pages/index.jsx
13 | wordpress_48
14 | wordpress_96
15 | }
16 | }
17 | date
18 | slug
19 | title
20 | modified
21 | excerpt
22 | id
> 23 | acf {
| ^
24 | project
25 | date
26 | }
27 | categories {
28 | name
29 | }
30 | tags {
31 | name
32 | }
33 | content
success extract queries from components — 0.162 s
success run graphql queries — 0.020 s
success write out page data — 0.004 s
success write out redirect data — 0.001 s
success onPostBootstrap — 0.002 s
info bootstrap finished - 88.913 s
DONE Compiled successfully in 6369ms 17:34:15
Did you get this working? Looks like you need to remove the acf keys from your query in src/pages/index.jsx.
You need to attach an ACF field to post type "post" in ACF, and the WordPress plugin acf-to-rest-api
. Or remove the ACF field in your query as suggested.
if I remove acf from all queries, it throws these errors:
×
TypeError: Cannot read property 'date' of undefined
(anonymous function)
src/components/Posts/PostListing/PostListing.jsx:13
10 | path: postEdge.node.slug,
11 | cover: postEdge.node.cover,
12 | title: postEdge.node.title,
> 13 | date: postEdge.node.acf.date,
14 | excerpt: postEdge.node.excerpt,
15 | mainCategory: postEdge.node.categories[0].name,
16 | project: postEdge.node.acf.project,
View compiled
PostListing.getPostList
src/components/Posts/PostListing/PostListing.jsx:8
5 | class PostListing extends React.Component {
6 | getPostList() {
7 | const postList = []
> 8 | this.props.postEdges.forEach(postEdge => {
9 | postList.push({
10 | path: postEdge.node.slug,
11 | cover: postEdge.node.cover,
View compiled
PostListing.getPostList
node_modules/react-proxy/modules/createPrototypeProxy.js:44
PostListing.render
src/components/Posts/PostListing/PostListing.jsx:29
26 | }
27 |
28 | render() {
> 29 | const postList = this.getPostList()
30 | return (
31 | <div>
32 | {/* Your post list here. */
View compiled
▶ 45 stack frames were collapsed.
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.
I think this starter kit should work for standard Wordpress installation out of the box. If I have to go through all these to manage to get it to work, what's the point?
I got the same error. It feels like Gatsby + WP is not there yet.
@hadifarnoud @kilinkis Unfortunately there were some fairly simple issues like this with the Gatsby WordPress starter. It's a community starter, not officially part of Gatsby. We've taken over maintenance and have fixed most of the issues you've hit above. We've removed the acf requirements.
There are several different problems being discussed in this issue.
I'm going to close this issue now assuming these problems have been fixed, but please reopen the issue if not, or feel free to create a new issue here or on the starter repo and we'll do our best to help.
@hadifarnoud @kilinkis We welcome your help to create a starter kit for WordPress and Gatsby without ACF. Please create a PR. A good starting point would be to remove all mentions to ACF in the starter kit using-wordpress
and publish using-wordpress-raw
in the main repo!
@sebastienfi @hadifarnoud @kilinkis Just yesterday we started working on a Gatsby v2 WordPress starter. It doesn't have any reliance on ACF or other stuff. It's based on the Netlify CMS starter but ported to WordPress. Right now posts, categories, tags, and pages work. You can check it out here.
Thank you @chmac I'll check it ASAP!
Take of your env.*
. The API
needs to authorise. In my case the problem was that I only had .env.development
, and the token, and other stuff was not provided for prod
build.
Good luck!
I've created PR #17317 to update the documentation to recommend using the starter recommended by @chmac - gatsby-starter-wordpress - to work around this issue.
Wasted a whole day trying to make it work on XAMPP. I could easily play with the WP api using postman but gatsby-source-wordpress was not interested.
Searching Google for an answer wasn't really helpful either.
I like the idea. I love Gatsby and I like Wordpress...but I am not good enough at this to figure out how to fix a vexing problem on my own and there doesn't seem to be much support online either.
I'll check back in a year or so.
Summary
Cannot get wordpress plugin to work. I get errors about author, I deleted author section from graphql. then I got error about ACF, deleted that too. anything I do, it seems like there is something else broken. I feel like there is more serious issues. I followed official documentation.
ps: I'm using gatsby-starter-wordpress but don't believe that is the issue
Relevant information
Wordpress v4.8.7
$ gatsby develop
Environment
File contents (if changed)
gatsby-config.js
: