I am using gatsby with wordpress to display events from the events calendar API of wordpress . I am using the plugin gatsby-source-tribe-events to access the allTribeEvents graphql field . The problem is that if I have no events posted on wordpress the field allTribeEvents is not created and then if I run my graphql query on gatsby I get
Cannot query field "allTribeEvents" on type "Query"
So my problem is how to check if the field exists in graphql and query conditionally based on it .
My code :
React component to display events :
export default function Events() {
const data = useStaticQuery(graphql`
query EventsQuery {
allTribeEvents {
...
}
}`);
//then I return my component based on the data
}
So the point is that if no posts exist "allTribeEvents" is not created in grapqhl and I get an error