Git Product home page Git Product logo

Comments (7)

danielmahon avatar danielmahon commented on August 18, 2024 2

I was able to hack a workaround using setFieldsOnGraphQLNodeType. I added the following to gatsby-node.js to map a coverImage: null to coverImage: { handle: '' }. Then instead of checking for a null coverImage or handle in React, I check for an empty string.

exports.setFieldsOnGraphQLNodeType = (
  { type, store, pathPrefix, getNode, cache, reporter },
  pluginOptions
) => {
  if (type.name === 'Post') {
    // allow null coverImage fields
    type.nodes = type.nodes.map(node => {
      if (node.coverImage === null) {
        node.coverImage = {
          handle: '',
        };
      }
      return node;
    });
  }
};

Messy, but seems to work until they fix this. I'm honestly surprised Gatsby doesn't already support nullable fields...

from gatsby-source-graphcms.

Redmega avatar Redmega commented on August 18, 2024

cc: @rdela

I believe this has to do with the fact that gatsby ignores empty nodes and doesn't create the type. I'll look into it later this week

from gatsby-source-graphcms.

rdela avatar rdela commented on August 18, 2024

Yes I think you can find people discussing this in Gatsby issues in relation to the WordPress and Contentful plugins if anyone is feeling intrepid.

from gatsby-source-graphcms.

dotgreg avatar dotgreg commented on August 18, 2024

saw those ones as well, they discuss directly on gatsby project issue tracking because the plugins themselves are maintained inside the core project codebase. But it looks being an issue with the plugins themselves, not from gatsby core, no?

from gatsby-source-graphcms.

Redmega avatar Redmega commented on August 18, 2024

It's more related to the way gatsby internally creates types, I believe. If the field is empty the type will not be created.

@rdela Can you share links to those issues so I can read up? Can't seem to find them.

from gatsby-source-graphcms.

rdela avatar rdela commented on August 18, 2024

@Redmega Here are a couple from a quick search
gatsbyjs/gatsby#3495
gatsbyjs/gatsby#2564

Edit couple more:
gatsbyjs/gatsby#2937
gatsbyjs/gatsby#2539

from gatsby-source-graphcms.

Kikobeats avatar Kikobeats commented on August 18, 2024

did you find how to handle this properly in the v2?

from gatsby-source-graphcms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.