Gatsby: The createNode API does not produce all node links

Created on 11 Sep 2018  路  6Comments  路  Source: gatsbyjs/gatsby

Description

We're a headless CMS vendor and we've developed a source plugin for our SaaS service. Our source plugin supports creating links of 4 different kinds among data retrieved from our public API. We use the (yet not documented) ___NODE convention to let Gatsby create link fields. One of the four kinds of relationships exhibits a strange behavior--always only one node has this kind of relationship properly created. Other nodes have this relationship fields null.

Steps to reproduce

  1. Clone https://github.com/Kentico/cloud-gatsby.
  2. Run the project.
  3. If a GraphQL error occurs, build the project again.
  4. Open the project in an IDE, place a breakpoint where the createNode is called and start a debug session.
  5. Verify that all JavaScript objects that are passed onto createNode have their summary_nodes___NODE properties properly populated of id values (GUIDs) of related nodes (previously created with createNodeId).
  6. Pass the breakpoint and let the project run.
  7. Navigate to the GraphiQL environment.
  8. Run the Modular content relationships in rich text example query.
  9. Inspect the summary_nodes properties in all nodes in the output. Notice that there will be nodes that represent three content items, all of them being translated to three languages, totalling to 9 nodes.

Expected result

All summary_nodes properties should be populated.

Actual result

In each of the 3 languages in the output, there's only one node with summary_nodes populated in each language.

Environment

System:
OS: Windows 10
CPU: x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
Binaries:
npm: 5.6.0 - C:Program Filesnodejsnpm.CMD
Browsers:
Edge: 40.15063.674.0
npmPackages:
gatsby: ^1.9.277 => 1.9.277
gatsby-link: ^1.6.46 => 1.6.46
gatsby-plugin-react-helmet: ^2.0.11 => 2.0.11

error The system cannot find the path specified.

Error: The system cannot find the path specified.

  • envinfo.js:1 Function.e.exports.sync
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:7778

  • envinfo.js:1 Object.copySync
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:104976

  • envinfo.js:1 Object.t.writeSync.e [as writeSync]
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:123499

  • envinfo.js:1
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:124274

  • envinfo.js:1 Promise.all.then.e
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:124289

  • From previous event:

  • envinfo.js:1 p
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:123986

  • envinfo.js:1 Object.run
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:125487

  • create-cli.js:181 Object.handler
    [npm]/[gatsby-cli]/lib/create-cli.js:181:17

  • command.js:235 Object.runCommand
    [npm]/[gatsby-cli]/[yargs]/lib/command.js:235:44

  • yargs.js:1046 Object.parseArgs [as _parseArgs]
    [npm]/[gatsby-cli]/[yargs]/yargs.js:1046:30

  • yargs.js:551 Object.parse
    [npm]/[gatsby-cli]/[yargs]/yargs.js:551:25

  • create-cli.js:242 module.exports
    [npm]/[gatsby-cli]/lib/create-cli.js:242:157

  • index.js:126 Object.
    [npm]/[gatsby-cli]/lib/index.js:126:1

  • bootstrap_node.js:187 startup
    bootstrap_node.js:187:16

  • bootstrap_node.js:608
    bootstrap_node.js:608:3

error UNHANDLED REJECTION

Error: The system cannot find the path specified.

  • envinfo.js:1 Function.e.exports.sync
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:7778

  • envinfo.js:1 Object.copySync
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:104976

  • envinfo.js:1 Object.t.writeSync.e [as writeSync]
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:123499

  • envinfo.js:1
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:124274

  • envinfo.js:1 Promise.all.then.e
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:124289

  • From previous event:

  • envinfo.js:1 p
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:123986

  • envinfo.js:1 Object.run
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:125487

  • create-cli.js:181 Object.handler
    [npm]/[gatsby-cli]/lib/create-cli.js:181:17

  • command.js:235 Object.runCommand
    [npm]/[gatsby-cli]/[yargs]/lib/command.js:235:44

  • yargs.js:1046 Object.parseArgs [as _parseArgs]
    [npm]/[gatsby-cli]/[yargs]/yargs.js:1046:30

  • yargs.js:551 Object.parse
    [npm]/[gatsby-cli]/[yargs]/yargs.js:551:25

  • create-cli.js:242 module.exports
    [npm]/[gatsby-cli]/lib/create-cli.js:242:157

  • index.js:126 Object.
    [npm]/[gatsby-cli]/lib/index.js:126:1

  • bootstrap_node.js:187 startup
    bootstrap_node.js:187:16

  • bootstrap_node.js:608
    bootstrap_node.js:608:3

Most helpful comment

Hi @JanLenoch, we'll look into this.

All 6 comments

Hi @JanLenoch, we'll look into this.

I took a look and it seems like nodes that miss summary_nodes in graphql output just don't have summary_nodes___NODE defined when creating them - I've added some debugging helper code:

  const nameToSummaryNodes = {}
  const interestingNodes = getNodes().filter(
    node => node.internal.type === `KenticoCloudItemBlogpostReference`
  )

  interestingNodes.forEach(node => {
    nameToSummaryNodes[`${node.system.name} - [${node.fields.languageStep1}]`] =
      node.summary_nodes___NODE
  })

and result is:
screen shot 2018-09-12 at 12 30 48

Which match output from graphql (those are nodes that You create in plugin and not graphql results)

Hi @pieh ,

Thanks for looking into it! The fields aren't there but still, this is not the root cause.

That absence of the summary_node____NODE field is only caused by my adding a check for property.modular_content.length > 0 in normalize.js before submitting this issue. That check was designed just to save the bootstrap process from a few inexpensive Array.includes checks. But never mind, I removed it to always have the ____NODE field present.

But, the problem is that even with the length check removed, the createNode API still sometimes fails to create relationships.

It can be reproduced like that:

  • pull the latest commit (without the length check)
  • put a breakpoint right before the createNode is called
  • inspect the nonDefaultLanguageItemNodes and compare the node with the 8de2c58a-f4cc-5b2a-a132-b06ac9ebef9a ID with the result in the GraphiQL interface, as seen in the following images.

Watch
GraphiQL

is node.internal.contentDigest changed when after removed that check? because gatsby will keep nodes data in .cache directory and it will not mark nodes as dirty if contentDigest is same in next run - as quick check - try deleting .cache directory and run gatsby develop again and see if things will show up then

Deleting the .cache folder helped. Thank you!

I suppose this makes the issue resolved, doesn't it?

I think so. I'll close it, but if you run into similiar problems comment here or create new issue :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

totsteps picture totsteps  路  3Comments

rossPatton picture rossPatton  路  3Comments

timbrandin picture timbrandin  路  3Comments

kalinchernev picture kalinchernev  路  3Comments

benstr picture benstr  路  3Comments