question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ACF Relationship Field throws an error in Gatsby

See original GitHub issue

I’m running into a problem, where a query throws an error, which works on the remote GraphiQL endpoint, when using an ACF Relationship field.

query {
  page(id: "730", idType: DATABASE_ID) {
    acf {
      content {
        ... on Page_Acf_Content_FeaturedNews {
          news {
            ... on NewsEntry {
              id
            }
          }
        }
      }
    }
  }
}

returns on the remote GraphiQL:

{
  "data": {
    "page": {
      "acf": {
        "content": [
          {
            "news": [
              {
                "id": "cG9zdDoyNjI4"
              },
              {
                "id": "cG9zdDoyNjMy"
              },
              {
                "id": "cG9zdDoyNjE3"
              }
            ]
          }
        ]
      }
    }
  }
}

but the same query throws an error in Gatsby:

query MyQuery {
  wpPage(databaseId: {eq: 730}) {
    acf {
      content {
        ... on WpPage_Acf_Content_FeaturedNews {
          news {
            ... on WpNewsEntry {
              id
            }
          }
        }
      }
    }
  }
}

result:

{
  "errors": [
    {
      "message": "Cannot read property 'id' of null",
      "locations": [
        {
          "line": 6,
          "column": 11
        }
      ],
      "path": [
        "wpPage",
        "acf",
        "content",
        5,
        "news"
      ],
      "stack": [
        "TypeError: Cannot read property 'id' of null",
        "    at reduce (~/node_modules/gatsby-source-wordpress-experimental/src/steps/create-schema-customization/transform-fields/transform-union.js:49:27)",
        "    at Array.reduce (<anonymous>)",
        "    at resolver (~/node_modules/gatsby-source-wordpress-experimental/src/steps/create-schema-customization/transform-fields/transform-union.js:46:28)",
        "    at wrappedTracingResolver (~/node_modules/gatsby/src/schema/resolvers.ts:518:14)",
        "    at resolveFieldValueOrError (~/node_modules/graphql/execution/execute.js:467:18)",
        "    at resolveField (~/node_modules/graphql/execution/execute.js:434:16)",
        "    at executeFields (~/node_modules/graphql/execution/execute.js:275:18)",
        "    at collectAndExecuteSubfields (~/node_modules/graphql/execution/execute.js:713:10)",
        "    at completeObjectValue (~/node_modules/graphql/execution/execute.js:703:10)",
        "    at completeAbstractValue (~/node_modules/graphql/execution/execute.js:660:10)",
        "    at completeValue (~/node_modules/graphql/execution/execute.js:585:12)",
        "    at completeValueCatchingError (~/node_modules/graphql/execution/execute.js:495:19)",
        "    at ~/node_modules/graphql/execution/execute.js:618:25",
        "    at Array.forEach (<anonymous>)",
        "    at forEach (~/node_modules/iterall/index.js:83:25)",
        "    at completeListValue (~/node_modules/graphql/execution/execute.js:614:24)",
        "    at completeValue (~/node_modules/graphql/execution/execute.js:573:12)",
        "    at ~/node_modules/graphql/execution/execute.js:492:16",
        "    at runMicrotasks (<anonymous>)",
        "    at processTicksAndRejections (internal/process/task_queues.js:93:5)",
        "    at async Promise.all (index 0)",
        "    at async Promise.all (index 0)",
        "    at async Promise.all (index 0)"
      ]
    }
  ],
  "data": {
    "wpPage": {
      "acf": {
        "content": [
          {
            "news": null
          }
        ]
      }
    }
  }
}

kolle-on-xps :: Development/ » npx gatsby info

System: OS: Linux 5.8 Ubuntu 20.10 (Groovy Gorilla) CPU: (8) x64 Intel® Core™ i7-10510U CPU @ 1.80GHz Shell: 5.8 - /usr/bin/zsh Binaries: Node: 14.15.1 - /usr/bin/node Yarn: 1.22.4 - ~/.npm-global/bin/yarn npm: 6.14.8 - ~/.npm-global/bin/npm Languages: Python: 2.7.18 - /usr/bin/python Browsers: Firefox: 83.0 npmPackages: gatsby: ^2.24.91 => 2.27.0 gatsby-image: ^2.6.0 => 2.6.0 gatsby-link: ^2.4.16 => 2.6.0 gatsby-plugin-advanced-sitemap: ^1.5.6 => 1.5.6 gatsby-plugin-manifest: ^2.4.37 => 2.7.0 gatsby-plugin-netlify: ^2.3.25 => 2.6.0 gatsby-plugin-react-helmet: ^3.3.14 => 3.5.0 gatsby-plugin-react-svg: ^3.0.0 => 3.0.0 gatsby-plugin-sharp: ^2.6.43 => 2.9.0 gatsby-plugin-styled-jsx: ^3.5.0 => 3.5.0 gatsby-source-filesystem: ^2.3.37 => 2.6.1 gatsby-source-wordpress-experimental: ^3.1.3 => 3.1.3 gatsby-transformer-sharp: ^2.5.20 => 2.7.0

using WPGraphQL: 1.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
upham-uicommented, Oct 20, 2021

It sure is…

2reactions
holliepearsoncommented, Feb 16, 2021

Did anything further ever happen with this? I’m having the same issue with a flexible content field

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gatsby source WordPress with ACF null field errors in build ...
The following example is with an object containing data from an ACF Repeater field query using Gatsby and WPGraphQL. Works in ...
Read more >
@kennethormandy/gatsby-source-wordpress | ...
GraphQL Error - Unknown Field on ACF. ACF returns false in cases where there is no data to be returned. This can cause...
Read more >
PageBuilder with ACF Flexible Content - Guide to Gatsby ...
Learn how to create a page builder like experience in @WordPress with Advanced Custom Field's (@wp_acf) Flexible Content field for your ...
Read more >
Relationship Field Fatal error on PHP 8.1 - ACF Support
Hi, after upgrading to PHP 8.1 my the ACF relationship field started failing. The problem seems to be inside the library itself, ...
Read more >
Headless WordPress: Set Up and Deploy a Gatsby Site in ...
You might find that the install process will throw up some ... If you receive errors such as gatsby: command not found ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found