0
votes

Let's see. I have a Gatsby site, a lyrics site. Each song is a Markdown file with some frontmatter fields (title, album, author, etc). I have a GraphQL query for each author's page, and it filters through all the songs and returns the ones that match the author name I pass in.

I want to display more information about each author, so I added an authors.json file with name, bio and image for each one, and added a mapping to my gatsby config file, mapping frontmatter author to author name (from my json file). So far so good.

It works on most pages, I only had to update my queries from frontmatter { author } to frontmatter { author { name } }.

But the author page query doesn't work. I had a poke around in GraphiQL, and removing the filter makes it return all the mapped fields correctly, but of course, I need the filter.

I also tried hard coding the author value, as it's normally provided by the page context, but it also didn't work.

Not sure where I'm going wrong :/

I'll add some relevant snippets:

Frontmatter example:

---
title: Adeus camarada, adeus
author: Contra Mestre Rafael
album: Quando os berimbaus se encontram
tags: ["quadra"]
date: 2019-02-02
---

Author entry (authors json is an array of these):

{
    "name": "Contra Mestre Rafael",
    "bio": "Placeholder bio.",
    "image": "/images/authors/cm-rafael.jpg"
}

Query that isn't working:

    query($author: String) {
        allMarkdownRemark(
            limit: 2000
            sort: { fields: [frontmatter___date], order: DESC }
            filter: { frontmatter: { author: { eq: $author } } }
        ) {
            totalCount
            edges {
                node {
                    fields {
                        slug
                    }
                    frontmatter {
                        author {
                            name
                            bio
                            image
                        }
                        title
                    }
                }
            }
        }
    }

At the moment allMarkdownRemark returns null, and I expect it to return an array of nodes for each song that matches the author, and the mapped information of the author within each of those.

1
Hi @carolgilabert, would you share the relevant part of your gatsby-config? What does your mapping look like?Derek Nguyen

1 Answers

0
votes

This seems to be unsupported by Gatsby at the moment. A friend sent me this:

https://github.com/gatsbyjs/gatsby/issues/4614

I'll try and contribute a fix to Gatsby if I can :)