I have a Gatsby project, and using Wordpress as my source. I've created a custom post type named "events" that has ACF fields connected. One of the ACF fields is a flexible content (content_events).
I'm using the following query, but only works if all those flexbile content parts exists on the post, meaning if the author has not added one of the ones Im trying to get data from then the GraphQL query will fail. I get the following error: Fragment cannot be spread here as objects of type "WordPressAcf_large_textWordPressAcf_medium_textUnion" can never be of type "WordPressAcf_image".
I've heard about schemas in Gatsby, but not sure how to implement it? Or if there is another way to solve this?
Current query:
query ($id: Int!) {
allWordpressWpEvents(filter: {wordpress_id: {eq: $id}}) {
edges {
node {
title
wordpress_id
acf {
signup_title
signup_text
location
date
image {
localFile {
childImageSharp {
fluid(maxWidth: 1440) {
...GatsbyImageSharpFluid_withWebp
}
}
}
}
content_events {
__typename
... on WordPressAcf_large_text {
id
text
}
... on WordPressAcf_medium_text {
id
text
}
... on WordPressAcf_image {
id
image {
localFile {
childImageSharp {
fluid(maxWidth: 1440) {
...GatsbyImageSharpFluid_withWebp
}
}
}
}
}
}
form_sections {
post_name
}
}
}
}
}
}