Gatsby group doesn't work in GraphQL with custom nested types

Viewed 39

I have the following types defined in Gatsby:

type Track implements Node {
  title: String!
  chapters: [Chapter] @link
}

type Chapter implements Node {
  title: String!
  videos: [Video] @link
}

type Video implements Node {
  title: String!
}

This is all set up and working nicely when I query data like this:

query {
  allTrack {
    chapters {
      videos {
        title
      }
    }
  }
}

However, when I try to use the group keyword in GraphQL, it returns a really weird response:

query {
  allTrack {
    group(field: chapters___videos___title) {
      fieldValue
      totalCount
    }
  }
}

// RESPONSE
{
  "data": {
    "allTrack": {
      "group": [
        {
          "fieldValue": "Title 1,Title 2",
          "totalCount": 5
        }
      ]
    }
  }
}

In other words, it seems to be adding all the titles together instead of counting them separately. If I just count the track titles, everything works perfectly.

Can anyone help with this?

0 Answers
Related