gatsby: __typename is not added automatically after relay-compiler was removed

Summary

I am using an if statement to determine the type of the GQL fragment, and render the right component accordingly. This was working well in gatsby 2.7.5, but this field no longer exists after upgrading Gatsby to 2.18.15

“gatsby-source-graphql”: “^2.1.29”

  • the data is coming from Contentful

Example code:

          if (component.__typename == 'CGQL_HeroCarousel') {
            return <HeroCarousel />;
          }

Example returned Json in 2.18.15:

{
sys: {id: "myId"}
name: "Component Name"
...
}

Example returned Json in 2.7.5:

{
__typename: "CGQL_HeroCarousel"
sys: {id: "myId"}
name: "Component Name"
....
}

“gatsby-node.js” has not changed, but included here for more information:

    {
      resolve: 'gatsby-source-graphql',
      options: {
        typeName: 'CGQL',
        fieldName: 'CGQL',
        url: getContentFulUrl(),
        headers: getContentFulHeader()
      }
    }

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 15 (10 by maintainers)

Most upvoted comments

Sure thing, I was following the thread but I’m away of my computer for the holidays.

I will do my best replicating this and will update.