Gatsby: GraphQL data doesn't match markdown file

Created on 20 Jul 2020  路  7Comments  路  Source: gatsbyjs/gatsby

Summary

I am performing a query to get some content from a footer.md file in my project. I am then trying to build a button that links to another page using the links array from my file. However, when getting the data back with a GraphQL query, my link url is ../pages/prices instead of just /prices.

My footer.md file:

templateKey: footer
links:
  - url: /prices
    text: Prices

What actually comes back:

[{"url":"../pages/prices","text":"Prices"}]

How can I get just the original data back rather than having the additional ../pages/?

Thanks.

Reproducing

I have created a small repo that replicates the bug here: https://github.com/samwilliscreative/gatsby-bug
The key files being src\components\Footer.js and src\data\footer.md
When running the app, you can see that the JSON result of the graphQl query in the footer prints out the full ../pages/prices rather than /pages as seen in the markdown file.

Markdowremark bug upstream

All 7 comments

Hi!

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 馃挏

@LekoArts I've created a repo that replicates the issue here: https://github.com/samwilliscreative/gatsby-bug

I think the issue may be related loosley to https://github.com/gatsbyjs/gatsby/issues/950, specifically this comment https://github.com/gatsbyjs/gatsby/issues/950#issuecomment-300605907

It appears that this issue is exclusive to arrays, I have a specific button field rather than an array of buttons, and the link works.

Hiya!

This issue has gone quiet. Spooky quiet. 馃懟

We get a lot of issues, so we currently close issues after 30 days of inactivity. It鈥檚 been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 馃挭馃挏

Not stale please!

Hi!

I can definitely reproduce this. However I couldn't find where exactly this is happening, it is definitely after initial frontmatter processing, so it's somewhere when page is created, it seems. I'll assign our Subject Matter Expert to this so they can look into it.

Thank you for your patience!

After checking this out - it's the fmImagesToRelative helper function from gatsby-remark-relative-images that does it - after adding some debug logs in the package (you have this snippet in gatsby-node that calls it - https://github.com/samwilliscreative/gatsby-bug/blob/54fa5a8f3c6f07bfef5c7a26fcf2851fbfc34d94/gatsby-node.js#L50-L62 )

Result is following:
Screenshot 2020-08-12 at 17 06 48

So this issue should be reported in https://github.com/danielmahon/gatsby-remark-relative-images - I'm not sure if it's even possible to do generic fix for this case, and instead plugin configuration needs to be added there to - for example specify which fields shouldn't be converted (right now it "guesses" if some value is a path or not).

Was this page helpful?
0 / 5 - 0 ratings