gatsby-source-strapi icon indicating copy to clipboard operation
gatsby-source-strapi copied to clipboard

cannot fetch empty fields

Open deebov opened this issue 5 years ago • 8 comments

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: image

P.s. I would really appreciate if someone could help solving this issue 🙏

deebov avatar Nov 04 '19 07:11 deebov

Error suggests that you're querying allStrapiPosition, I'm confused. Also did you change public user permision so it can actually be read?

masives avatar Nov 14 '19 08:11 masives

same here

hugomallet avatar Nov 25 '19 16:11 hugomallet

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 avatar Dec 17 '19 12:12 rozpuszczalny

@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 avatar Jun 22 '20 22:06 waynehaffenden

@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: search-by-time-name

rozpuszczalny avatar Jul 02 '20 20:07 rozpuszczalny

@rozpuszczalny Thank you

waynehaffenden avatar Jul 02 '20 23:07 waynehaffenden

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 avatar Jul 12 '22 14:07 kjoscha

@kjoscha Thank you! You saved me. ♥️

mzbiejczuk avatar Sep 06 '22 12:09 mzbiejczuk

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!

moonmeister avatar Dec 27 '22 18:12 moonmeister