2

I use Wordpress, Gatsby + GraphQL and I want to build a blog. Unfortunately all blog posts needs to have all "features" for example featured image.

The problem is when I remove all posts. So my blog is now empty but gatsby build fails because it expects featured image to exists. The same problem is if I have posts but they do not have featured image. If I want to run gatsby successfully I need at least one post with featured image.

Example GraphQL query

{
allWordpressPost {
    edges {
      node {
        id
        title
        content
        featured_media {
          source_url
        }
      }
    }
  }
}

Error

GraphQLError: Cannot query field "featured_media" on type "wordpress__POST".

I'm worried because my only solution is to create a dummy post with all these things. What if I want to create a blog for my client and he deletes this dummy post? Is there a better way?

I don't have much experience with gatsby so I would be happy for suggestions.

Thank you

  • use fragments for featured_media - should be treated as optional – xadm Jun 7 at 10:43
  • Could you show me example please? – moaes01 Jun 7 at 11:36
  • it isn't hard to search/google for 'gatsby fragment' - stackoverflow.com/a/51839893/6124657 – xadm Jun 7 at 12:56
  • It doesn't work. Still the same error. – moaes01 Jun 7 at 13:17
  • open an issue on github – xadm Jun 7 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.