Skip to content

[Updated] How can I identify a referenced component's type? #246

@SabbeRubbish

Description

@SabbeRubbish

[Updated] See this comment for the up to date problem.

Reproduction

You can reproduce the issue with my repo https://github.com/SabbeRubbish/graphcms-bug-repro
Used GraphCMS and latest gatsby default starter.
Added to gatsby-config.js:

exports.onCreateNode = ({ node, getNode, actions }) => {
  const { createNodeField } = actions

  createNodeField({
    node,
    name: `BLAH`,
    value: "BLAH",
  })
}

Expected behaviour

ALL nodes get a fields object with BLAH as key and BLAH as value.

Actual behaviour

ALL nodes except GraphCMS nodes get the extra field:
image
image

But not the GraphCMS nodes:
image
image

Use case

I want to add an extra field "Type" so that I can distinguish on components' types. For example, I have a page with 2 modular components that I can place on them: section with image or testimonials. But in my page template I need to know which one is which, which is why I want to add a _type field to be able to distinguish.

Thanks for any help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions