gatsby-source-strapi
gatsby-source-strapi copied to clipboard
cannot fetch empty fields
Hi there
Gatsby fails to build the project if I try to fetch an empty field from Strapi. e.g. I have the Post content type in Strapi but it does not contain any post. So, when I try to fetch allStrapiPost
it throws an error during the build process.
The error message:
P.s. I would really appreciate if someone could help solving this issue 🙏
Error suggests that you're querying allStrapiPosition, I'm confused. Also did you change public user permision so it can actually be read?
same here
I'm facing same issue. Currently I have to create dummy-content just to make sure that every GraphQL type is created properly, just to bypass this problem.
I've seen an API for quering content types in Strapi (it was /content-manager/content-types
and /content-manager/groups
), it may solve this problem, because we would be able to query correct types, but with no results. But a PR for this would be required, since it changes how gatsby-source-strapi
works now.
EDIT:
Hardcore workaround is to create type for content type, that might be unavailable. So for example, having an Article
type with:
-
content
- rich text -
title
- string
a type for Gatsby/GraphQL would look like this:
module.exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions;
const typeDefs = `
type StrapiArticle implements Node @infer {
title: String
content: String
created_at: Date @dateformat
updated_at: Date @dateformat
strapiId: Int
}
`;
createTypes(typeDefs);
};
Note for someone who would like to take it: https://www.gatsbyjs.org/docs/actions/#createTypes
@rozpuszczalny Thank you for this, what did you use for image/file types? Especially, that I'm using fluid images in Gatsby, thank you.
@waynehaffenden
I haven't used gatsby with images. However, you can go to /__graphql
playground, click in the upper right corner on "Docs >", and then type in a name of the type. See attached screenshot:
@rozpuszczalny Thank you
To prevent errors dealing with content-types without existing records, just use the gatsby-plugin-schema-snapshot
plugin. Set the "update" option to "true" and build your app with all content-types having at least one record (e.g. a dummy record). That creates a schema.gql
file in the root of your app folder. Afterwards, set the plugin's "update" option to "false" and remove your dummy record. No complaints anymore while gatsby builds :)
@kjoscha Thank you! You saved me. ♥️
Thanks for your interest in this project. This plugin is moving into the Gatsby User Collective and this repo will be archived. Please open an issue in that repository, submit a PR if you'd like to see this implemented, or join us on Discord if you have questions!