I'm not sure if this is a bug, or intended behaviour, but if I were to create nodes with createNode where each node was something like this:
{
name: 'Chris',
age: null
},
{
name: 'Christopher',
age: null
},
{
name: null,
age: null
}
The field name would exist within GraphQL, but the field age would not because it has a value of null for every node that's created. Is this something that can be worked around?
I have a list of hockey matches, which take a hometeam, awayteam and a winningteam. The hockey season doesn't start for another month, so no matches have been played yet, hence no teams have won. This causes the winningteam field to be omitted from GraphQL, and then my GraphQL queries break.
I'm trying to use them within a filter, and also the body of the query.
This is limitation of schema creation - to create field Gatsby would need to know type of it, which Gatsby can't infer from null so it skips those fields. You can potentially workaround it by setting to empty string instead of null, which gatsby will pick up as string field.
Related issue: https://github.com/gatsbyjs/gatsby/issues/3344
Just found this which also happens with gatsby-source-drupal.
I was thinking of making a transformer to change null fields to empty strings, however this is probably not a nice generalization.
It even happens for gatsby-source-wordpress
Wouldn't it make more sense to default it to a string type?
You can use the new schema customization API to tell Gatsby that the fields exist https://www.gatsbyjs.org/blog/2019-03-04-new-schema-customization/
eg
type person {
name: String
age: String
}
Thanks @jonlow that was easier than I expected.
Most helpful comment
You can use the new schema customization API to tell Gatsby that the fields exist https://www.gatsbyjs.org/blog/2019-03-04-new-schema-customization/
eg