Gatsby createTypes don't create localFile using File

Viewed 235

I have a problem to run Gatsby when there is a field in graphql that is empty (in cms sometimes the field will be empty sometimes not). I managed to solve this problem by adding in gatsby-node.js via createTypes the missing content. Unfortunately just as for the text using the string type works fine so for the photo using the File type subfield localFile is not created. I need the localFile to appear even if there is no photo, the same way as photo is added. Does anyone have an idea how to solve this. Thanks a lot in advance for your help.

gatsby-node.js

exports.sourceNodes = ({ actions }) => {
 const { createTypes } = actions
 const typeDefs = ` type StrapiPageEstimateRealizations implements Node { 
     Title: String
     Description: String
     Img: File
} 

` 
createTypes(typeDefs) 
}

graphql when the photo field is empty

graphql when a picture is added in cms

1 Answers

File is not a native type so depending on the context, you need to add a custom type.

Try defining your custom type like:

type LocalFile {
  localFile: File @link(from: "localFile___NODE")
}

And then:

 const typeDefs = ` type StrapiPageEstimateRealizations implements Node { 
     Title: String
     Description: String
     Img: LocalFile 
} 

Useful resources:

Related