Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check if graphql query exists #5296

Closed
bogdancss opened this issue May 5, 2018 · 1 comment
Closed

How to check if graphql query exists #5296

bogdancss opened this issue May 5, 2018 · 1 comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@bogdancss
Copy link
Contributor

bogdancss commented May 5, 2018

Hey,

I've got a GraphQl query polling data from the WP api. The end point is allWordpressWpJobListing which works perfectly fine.

However, in the case that there are no job listings or that the ones that exist in WP are expired, the api endpoint does not return anything, which causes the following error:

GraphQLError: Cannot query field "allWordpressWp JobListing"

The query is being called in the gatsby-node file as well as in one of my pages.
My questions is how do I manage this - how can I check if the endpoint exists and if not, how to skip it?

Thanks

@pieh pieh added the type: question or discussion Issue discussing or asking a question about Gatsby label May 5, 2018
@pieh
Copy link
Contributor

pieh commented May 5, 2018

This is unfortunately known issue.

Two current workarounds are:

  • keep dummy entry in your wordpress CMS (for example title "DO NOT DELETE" so your content team won't remove it) so Gatsby will always have some data that it can use to create "endpoint"
  • in your gatsby-node programatically create nodes that will match signature of JobListing (same fields, same type that is used by gatsby-source-wordpress)

Both would need some property in that "dummy" data that would let you filter them out when you create pages / query for data in your page templates.

I will close it for now, as we have issue like this already ( for example #2212 ).

Here's some discussion about proper solution that could be implemented in the future in Gatsby - #3344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

2 participants