Skip to content
Coding4GaiAmaOpen Source straight from the jungle

#Query parent File node in GatsbyJS

mdx {
frontmatter {
parent {
... on File {

When querying a Markdown/MDX node in GatsbyJS I always wondered how to get information of the parent file and why only file.absolutePath has been included as mdx.fileAbsolutePath. Then one day I came across some GraphQL magic I didn’t fully understand and sadly couldn’t remember nor find again. 😅

That’s the main reason for this post. It serves as a note to myself and hopefully serves others as well as I think it’s quite usefull.

Thanks to a video about the new using GraphQL and Relay which showed inline fragments, leading me to the right syntax 🙏. By the way, I found the video pretty informative to watch including cool techniques to build a more accessible and user friendly web.

Why has only absolutePath been added to the md/mdx node?
I think it’s for filtering, because AFAIK you can’t use the inline fragment syntax in filters.

More about inline fragments in the GraphQL Docs.

Discuss on Twitter

Can Rau

Open Source & Rainforest Maintainer at 🌴