wp-graphql / wp-graphql-acf

WPGraphQL for Advanced Custom Fields
https://wpgraphql.com/acf
627 stars 124 forks source link

Option page ACF fields are null when using Graphiql in Gatsby #384

Open Mellis84 opened 3 months ago

Mellis84 commented 3 months ago

Hi There,

I created some ACF fields for option pages using ACF Pro's option page field group. I was able to view the data in Wordpress, in the GraphiQL IDE, but, trying to do the same in my Gatsby site, using the GraphiQL explorer, the fields return null.

My package.json


    "framer-motion": "^11.0.14",
    "gatsby": "^5.13.3",
    "gatsby-adapter-netlify": "^1.1.3",
    "gatsby-plugin-alias-imports": "^1.0.5",
    "gatsby-plugin-image": "^3.13.1",
    "gatsby-plugin-manifest": "^5.3.1",
    "gatsby-plugin-netlify": "^5.1.1",
    "gatsby-plugin-offline": "^6.3.1",
    "gatsby-plugin-react-helmet": "^6.3.0",
    "gatsby-plugin-sass": "^6.13.1",
    "gatsby-plugin-sharp": "^5.13.1",
    "gatsby-plugin-web-font-loader": "^1.0.4",
    "gatsby-source-filesystem": "^5.13.1",
    "gatsby-source-wordpress": "^7.10.1",
    "gatsby-transformer-sharp": "^5.13.1",
    "html-react-parser": "^5.1.8",
    "lodash": "^4.17.20",
    "postcss": "^8.2.10",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-helmet": "^6.1.0",
    "react-redux": "^9.1.0",
    "tua-body-scroll-lock": "^1.4.1"```

Not sure if this is an issue with the  gatsby-source-wordpress package or wp-graphql-acf plugin.
jasonbahl commented 3 months ago

@Mellis84 when using the GraphiQL IDE in the WordPress admin, can you query the data? if so, then WPGraphQL is working and this is likely an issue with Gatsby.

Also, what version of WPGraphQL for ACF are you using? This repo is for WPGraphQL for ACF v0.6.* and older and the new repo for the re-built plugin that is on WordPress.org and will be maintained and updated going forward is over here: https://github.com/wp-graphql/wpgraphql-acf

Mellis84 commented 3 months ago

Hi @jasonbahl So I figured out to an extent what was going on, I was originally using the new https://github.com/wp-graphql/wpgraphql-acf plugin (Version 2.2.0). Creating ACF flexible content created errors in Gatsby:

Missing onError handler for invocation 'extracting-queries', error was 'Error: Type WpAcfFieldGroup must define one or more fields.

Interface field WpAcfFlexibleContentAcfBlocks_Layout.fieldGroupName expected but WpAcfFlexibleContentAcfBlocksRichTextLayout_Fields does
not provide it.

If I downgrade to this wp-graphql-acf version, acf flexible content works fine, but options pages don't show in the schema, looks like you have to manually add them in the functions.php rather than switching the show in graphql button