TylerBarnes / using-gatsby-source-wordpress-experimental

A starter for the upcoming gatsby-source-wordpress@v4
https://www.npmjs.com/package/gatsby-source-wordpress-experimental
MIT License
86 stars 29 forks source link

NPE on `paginatedWpNodeFetch` #6

Closed rburgstaller closed 4 years ago

rburgstaller commented 4 years ago

I am getting the following error in paginatedWpNodeFetch

  TypeError: Cannot set property 'type' of null

  - fetch-nodes-paginated.js:68 forEach
    [wordpress-v4]/[gatsby-source-wordpress-experimental]/src/steps/source-nodes/fe    tch-nodes/fetch-nodes-paginated.js:68:7

  - Array.forEach

  - fetch-nodes-paginated.js:67 paginatedWpNodeFetch
    [wordpress-v4]/[gatsby-source-wordpress-experimental]/src/steps/source-nodes/fe    tch-nodes/fetch-nodes-paginated.js:67:11

  - task_queues.js:93 processTicksAndRejections
    internal/process/task_queues.js:93:5

the fix is to add a check in https://github.com/TylerBarnes/gatsby/blob/feat/source-wordpress-v4/packages/gatsby-source-wordpress-experimental/src/steps/source-nodes/fetch-nodes/fetch-nodes-paginated.js#L68


  if (nodes && nodes.length) {
    nodes.forEach(node => {
      if (node) {
        node.type = nodeTypeName; // this is used to filter node interfaces by content types

        node.nodeType = nodeTypeName;
        allContentNodes.push(node);
      }
    });

I havent really analyzed why the nodes array contains all null values. But at least with this fix it works.

TylerBarnes commented 4 years ago

Huh 🤔 that's odd. I'll add the check in. Do you have a graphql endpoint I could use to reproduce this? This might indicate other problems that should be accounted for earlier.

rburgst commented 4 years ago

sorry, the endpoint is only available behind a vpn. If you give me hints where I could debug, I can try to analyze further back the call stack.

TylerBarnes commented 4 years ago

No worries, I figured it out! If you update to gatsby-source-wordpress-experimental@0.0.34 it's fixed. The problem was that some queries were returning a literal null in the response and I wasn't checking for that.