gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.28k stars 10.31k forks source link

gatsby-source-wordpress: WP categories return undefined #34939

Closed opr-inzn closed 2 years ago

opr-inzn commented 2 years ago

Description

There seems to be an error in the Gatsby WPGraphQL Plugin. In GraphQL under localhost:8000/___graphql I get my categories name and id returned for a post with the following query:

query MyQuery {
  wpPost(title: { regex: "/Works/" }) {
    categories {
      nodes {
        id
      }
    }
  }
}
Screenshot 2022-02-27 at 12 19 40 PM

However, in Gatsby the same query does not return anything, when I say

<p>{data.wpPost.categories.nodes.id}</p>

there is no error and the paragraph element get's rendered but without any content. I have also tried it with name, slug and basically any other of the available elements in "category" with the same result: an empty element.

Any help would be greatly appreciated!

Expected Result

<p>dGVybTo3OQ==</p>

Actual Result

<p></p>

Environment

System:
    OS: macOS 12.2.1
    CPU: (10) arm64 Apple M1 Pro
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.5.0 - /opt/homebrew/bin/node
    npm: 8.4.1 - /opt/homebrew/bin/npm
  Languages:
    Python: 2.7.18 - /usr/bin/python
  Browsers:
    Chrome: 98.0.4758.109
    Safari: 15.3
  npmPackages:
    gatsby: ^4.0.0 => 4.8.0
    gatsby-plugin-image: ^2.0.0 => 2.8.0
    gatsby-plugin-manifest: ^4.0.0 => 4.8.0
    gatsby-plugin-offline: ^5.0.0 => 5.8.0
    gatsby-plugin-react-helmet: ^5.0.0 => 5.8.0
    gatsby-plugin-sharp: ^4.0.0 => 4.8.0
    gatsby-source-filesystem: ^4.0.0 => 4.8.0
    gatsby-source-wordpress: ^6.0.0 => 6.8.0
    gatsby-transformer-sharp: ^4.0.0 => 4.8.0
  npmGlobalPackages:
    gatsby-cli: 4.8.0

Config Flags

No response

ekon97 commented 2 years ago

Could you try data.wpPost.categories.nodes[0].id ?

opr-inzn commented 2 years ago

I was totally stupid, that fixed it! Thanks a lot!!