Comments (7)
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.
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.
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.
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.
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.
@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.
did you find how to handle this properly in the v2?
from gatsby-source-graphcms.
Related Issues (20)
- Assets and localizations HOT 2
- Previous and next navigation for posts filtered by Category in Gatsby project not working HOT 3
- [gatsby-source-graphcms]: Problem building GraphCMS nodes // Error: Bad Request HOT 1
- Dependency Dashboard
- on upgrading to Gatsby 4 return null on build HOT 9
- When build website get the following error "Cannot query field "allGraphCmsPost" on type "Query"" . HOT 2
- Problem building GraphCMS nodes when upgrading to Gatsby v4 HOT 8
- Local images are null on gatsby build, but correct in dev mode (Gatsby v4) HOT 36
- Make a note on Granular Permissions usage
- concurrency error HOT 2
- gatsbyImageData return a wrong structs for some images HOT 1
- Markdown nodes null in production HOT 8
- Add ability to serve images in Webp format HOT 5
- Update baseURI to 'https://media.graphassets.com'
- Gastby build - connect ETIMEDOUT HOT 4
- Gatsby V2 fails to build fragments when model has nested components
- Locales not working through relations HOT 1
- [Updated] How can I identify a referenced component's type? HOT 6
- Error: Too Many Requests HOT 11
- Gatsby 5 support? HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gatsby-source-graphcms.