gatsby: [gatsby-transformer-remark] query on markdownRemark no longer returns added fields
Description
When doing a query on markdownRemark, fields added using createNodeFields are not present. This occurs only after running npm audit fix
, updating the gatsby package from 2.0.91 to 2.3.36 - gatsby-transformer-remark was unchanged from 2.2.0. With the previous version of gatsby, it worked fine.
Code is adding the fields in the setFieldsOnGraphQLNodeType method with createNodeField. console.log the nodes after calling createNodeField shows the fields correctly placed.
I checked if the fields are present on the allMarkdownRemark query in createPages and they were not.
They were also not present in /src/templates/post.jsx, in the following query:
export const pageQuery = graphql`
query BlogPostBySlug($slug: String!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
html
timeToRead
excerpt
frontmatter {
title
cover
date
category
tags
}
fields {
nextTitle
nextSlug
prevTitle
prevSlug
slug
date
}
}
}
`;
Steps to reproduce
gatsby new blog https://github.com/Vagr9K/gatsby-material-starter
cd blog
npm install
npm audit fix
(works fine if you leave this out)
npm run build
Expected result
Should build as before npm audit fix
Actual result
error GraphQL Error Encountered 1 error(s):
- Unknown field ‘nextTitle’ on type ‘MarkdownRemarkFields’.
It is looking for nextTitle
in the query above.
nextTitle
field was added at line 27 of gatsby-node.js in the setFieldsOnGraphQLNodeType method with createNodeField.
Environment
Run gatsby info --clipboard
in your project directory and paste the output here.
$ gatsby info --clipboard
System: OS: Windows 10 CPU: (12) x64 Intel® Core™ i7-8750H CPU @ 2.20GHz Binaries: Yarn: 1.12.3 - D:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.5.0 - D:\Program Files\nodejs\npm.CMD Languages: Python: 2.7.15 Browsers: Edge: 42.17134.1.0 npmPackages: gatsby: ^2.3.36 => 2.3.36 gatsby-image: 2.0.26 => 2.0.26 gatsby-plugin-catch-links: 2.0.9 => 2.0.9 gatsby-plugin-feed: 2.0.11 => 2.0.11 gatsby-plugin-google-analytics: 2.0.9 => 2.0.9 gatsby-plugin-lodash: 3.0.3 => 3.0.3 gatsby-plugin-manifest: 2.0.13 => 2.0.13 gatsby-plugin-netlify-cms: 3.0.9 => 3.0.9 gatsby-plugin-nprogress: 2.0.7 => 2.0.7 gatsby-plugin-offline: 2.0.21 => 2.0.21 gatsby-plugin-react-helmet: 3.0.5 => 3.0.5 gatsby-plugin-sass: 2.0.7 => 2.0.7 gatsby-plugin-sharp: ^2.0.35 => 2.0.35 gatsby-plugin-sitemap: 2.0.4 => 2.0.4 gatsby-plugin-twitter: 2.0.8 => 2.0.8 gatsby-remark-autolink-headers: 2.0.12 => 2.0.12 gatsby-remark-copy-linked-files: 2.0.8 => 2.0.8 gatsby-remark-images: 3.0.1 => 3.0.1 gatsby-remark-prismjs: 3.2.0 => 3.2.0 gatsby-remark-relative-images: ^0.2.2 => 0.2.2 gatsby-remark-responsive-iframe: 2.0.8 => 2.0.8 gatsby-source-filesystem: ^2.0.33 => 2.0.33 gatsby-transformer-remark: 2.2.0 => 2.2.0 gatsby-transformer-sharp: 2.1.10 => 2.1.10
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:4970
-
envinfo.js:1 Object.copySync [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:66948
-
envinfo.js:1 Object.t.writeSync.e [as writeSync] [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:48777
-
envinfo.js:1 [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:46934
-
envinfo.js:1 Promise.all.then.e [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:46949
-
util.js:16 tryCatcher [npm]/[gatsby-cli]/[bluebird]/js/release/util.js:16:2 3
-
promise.js:512 Promise._settlePromiseFromHandler [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:5 12:31
-
promise.js:569 Promise._settlePromise [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:5 69:18
-
promise.js:614 Promise._settlePromise0 [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:6 14:10
-
promise.js:694 Promise._settlePromises [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:6 94:18
-
promise.js:638 Promise._fulfill [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:6 38:18
-
promise_array.js:126 PromiseArray._resolve [npm]/[gatsby-cli]/[bluebird]/js/release/promise_arra y.js:126:19
-
promise_array.js:144 PromiseArray._promiseFulfilled [npm]/[gatsby-cli]/[bluebird]/js/release/promise_arra y.js:144:14
-
promise.js:574 Promise._settlePromise [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:5 74:26
-
promise.js:614 Promise._settlePromise0 [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:6 14:10
-
promise.js:694 Promise._settlePromises [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:6 94:18
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:4970
-
envinfo.js:1 Object.copySync [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:66948
-
envinfo.js:1 Object.t.writeSync.e [as writeSync] [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:48777
-
envinfo.js:1 [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:46934
-
envinfo.js:1 Promise.all.then.e [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:46949
-
util.js:16 tryCatcher [npm]/[gatsby-cli]/[bluebird]/js/release/util.js:16:2 3
-
promise.js:512 Promise._settlePromiseFromHandler [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:5 12:31
-
promise.js:569 Promise._settlePromise [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:5 69:18
-
promise.js:614 Promise._settlePromise0 [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:6 14:10
-
promise.js:694 Promise._settlePromises [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:6 94:18
-
promise.js:638 Promise._fulfill [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:6 38:18
-
promise_array.js:126 PromiseArray._resolve [npm]/[gatsby-cli]/[bluebird]/js/release/promise_arra y.js:126:19
-
promise_array.js:144 PromiseArray._promiseFulfilled [npm]/[gatsby-cli]/[bluebird]/js/release/promise_arra y.js:144:14
-
promise.js:574 Promise._settlePromise [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:5 74:26
-
promise.js:614 Promise._settlePromise0 [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:6 14:10
-
promise.js:694 Promise._settlePromises [npm]/[gatsby-cli]/[bluebird]/js/release/promise.js:6 94:18
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (2 by maintainers)
Commits related to this issue
- Refactor and streamline the implementation of next/previous paging. Based on the suggestions from https://github.com/gatsbyjs/gatsby/issues/13814. — committed to Vagr9K/gatsby-material-starter by Vagr9K 5 years ago
- Refactor and streamline the implementation of next/previous paging. Based on https://github.com/Vagr9K/gatsby-material-starter/commit/2f7bfa00f6a35d0371d8a2ec79446229c8a19fc7 and the suggestions from... — committed to Vagr9K/gatsby-advanced-starter by Vagr9K 5 years ago
- Refactor and streamline the implementation of next/previous paging. Based on https://github.com/Vagr9K/gatsby-material-starter/commit/2f7bfa00f6a35d0371d8a2ec79446229c8a19fc7 and the suggestions from... — committed to haikonguyen/haikonguyen.eu by Vagr9K 5 years ago
@neonguru sorry for the wait, when i was about to write this comment i was called away to take care of some errands.
Below is detailed the steps i took to make this work:
npm audit fix
, which for me bumped some dependencies.gatsby develop
with no changes whatsoever, i can confirm that the error pops up.gatsby-node.js
, especially to the following functions,onCreateNode
,setFieldsOnGraphQLNodeType
andaddSiblingNodes
. Starting fromonCreateNode
, it’s working as it should, with a little extra work, but it does the trick, it extends the node associated with markdown with the corresponding fields. Namelydate
andslug
, and then it pushes the node in question to a array calledpostNodes
.setFieldsOnGraphQLNodeType
as i’m somewhat familiar with Gatsby, but not an expert in any way shape or form, i went to the documentation page for that specific api call and from my read on it, it’s being used rather incorrectly. The reasoning why it’s used in the starter and how it’s used is beyond me, I can only speculate that probably at some time you could implement this approach.addSiblingNodes
function. Now it seems that’s the root of the issue, reading the code:It would seem that it iterates over the items that were injected while the
onCreateNode
api call is processing and then extend the node, by adding the fields. Now if you notice i intentionally left the following piece of code there:After it runs the file generated will contain the following, i’m only showing one item, to keep it short:
As you can see so it seems, that the fields are generated, but they are not, what’s being updated is the node inside the array, not the actual node needed. Probably at some point in time this would work, but as of now, it will not, i’ll leave to more experienced people with Gatsby, namely @sidharthachatterjee to elaborate on this. I tested out some permutations and they all yelded the same error.
gatsby-node.js
resulting in the following, the requires were left out to keep it a bit shorter:Key thing to take from this, pagination that was done through graphql field, is now made possible through Gatsby’s special prop
context
. It’s a trade off, but one of little consequence and which yelds the exact same result../src/templates/post.jsx
and one extra component, that being./src/components/PostSuggestions/index.jsx
.Starting with the template
./src/templates/post.jsx
, i tried to maintain the strucure as much as possible to prevent confusion, also the code is commented out, so that when you’re reading it know what is happening at every step, leaving out the imports to keep the code shorter../src/components/PostSuggestions/index.jsx
. Same as above is applied here:Issued
gatsby develop
and openedhttp://localhost:8000
and i’m presented with:Clicked on a random item yelded the following:
Feel free to provide feedback, so that we can close this issue, or continue to work on it till we find a solution. Also if you need i’m more than happy to push the code to repository so that you can take your time looking at it. And before i forget, sorry for the extra long comment.
@Vagr9K no need to thank, i’m glad that i was able to help out in solving this issue.
@neonguru i’m currently finishing up a reproduction for you. I’ll post back soon…Just doing some tweaks. Mind waiting just a little longer?