ldd / gatsby-source-github-api

Pull data into Gatsby from Github API v4
MIT License
65 stars 10 forks source link

Warning during node transformation when using gatsby-transformer-json #10

Closed Anahkiasen closed 5 years ago

Anahkiasen commented 5 years ago

Every time I build my Gatsby app I get this error from the plugin:

 ERROR

Plugin gatsby-transformer-json returned an error Could not find function loadNodeContent for plugin gatsby-source-github-api

  Error: Could not find function loadNodeContent for plugin gatsby-source-github-api

  - nodes.js:58 resolve
    [my-project]/[gatsby]/dist/db/nodes.js:58:15

  - new Promise

  - nodes.js:49 module.exports.loadNodeContent.node
    [my-project]/[gatsby]/dist/db/nodes.js:49:12

  - gatsby-node.js:62 Object.onCreateNode
    [my-project]/[gatsby-transformer-json]/gatsby-node.js:62:25

  - api-runner-node.js:230 runAPI
    [my-project]/[gatsby]/dist/utils/api-runner-node.js:230:37

  - api-runner-node.js:352 resolve
    [my-project]/[gatsby]/dist/utils/api-runner-node.js:352:15

  - debuggability.js:313 Promise._execute
    [my-project]/[bluebird]/js/release/debuggability.js:313:9

  - promise.js:488 Promise._resolveFromExecutor
    [my-project]/[bluebird]/js/release/promise.js:488:18

  - promise.js:79 new Promise
    [my-project]/[bluebird]/js/release/promise.js:79:10

  - api-runner-node.js:351 Promise.mapSeries.plugin
    [my-project]/[gatsby]/dist/utils/api-runner-node.js:351:12

  - util.js:16 tryCatcher
    [my-project]/[bluebird]/js/release/util.js:16:23

  - reduce.js:155 Object.gotValue
    [my-project]/[bluebird]/js/release/reduce.js:155:18

  - reduce.js:144 Object.gotAccum
    [my-project]/[bluebird]/js/release/reduce.js:144:25

  - util.js:16 Object.tryCatcher
    [my-project]/[bluebird]/js/release/util.js:16:23

  - promise.js:517 Promise._settlePromiseFromHandler
    [my-project]/[bluebird]/js/release/promise.js:517:31

  - promise.js:574 Promise._settlePromise
    [my-project]/[bluebird]/js/release/promise.js:574:18

The error is inconsequential and has the app builds fine. As far as I could tell, commenting out this line makes the warning go away but I'm not quite sure why it pops up in the first place. :s

ldd commented 5 years ago

Thanks! I'll investigate as soon as I have some time.

ldd commented 5 years ago

So! I've finally had some time to investigate this issue, and here's what I found out:

The trace that you gave me is very useful. I was able to reproduce the issue very easily, and the problem is in how gatsby-transformer-json decides to transform its files. It simply checks for mediaType.

Now, the Gatsby docs are relatively clear on my options. These boil down to:

Adding a content field seems unnecessary, not only because it is not recommended but because the data that we want is already in the data field. So no to this option.

loadNodeContent was not well documented, but the source is relatively straight forward to understand. For our purposes, since we have nothing to load, it would basically amount to having the content field. And so, we do not pick this option.

So, all that to say that I'm just going to change the mediaType.

gatsby-transformer-json will ignore this node, everyone is happy, and we can move on with life.

Final, final note: it is possible that someone wants to create their own transformer to the node this plugin creates. When and if such times comes, I will try to provide further assistance and maybe add a loadNodeContent field. But that seems like overkill. For now.

Thanks for letting me go down an interesting rabbithole @Anahkiasen !