Reputation: 518
I am using Wordpress as a headless CMS to manage content in my Gatsby Site. I used Advanced Custom Fields to create custom fields to easily manage the fields and contents to curate and pull into my Gatsby Application. Everything was working fine till I decided to start my Gatsby Project not long ago and started getting null
errors. I went to the GraphQL page on Gatsby with this address localhost:8000/___graphql
to query my data there only to see that all my fields were now returning null
.
I also visited the remote wordpress page to test the GraphQL IDE but everything works fine there. I have cleared the cache of my Gatsby Application but I am still getting the same error.
Here is an example of such Query for a custom field called homePage
query MyQuery {
wpPage {
homePage {
heroSubtitle
heroTitle
heroPlaystoreCtaText
heroImage {
localFile {
childImageSharp {
gatsbyImageData(width: 614, height: 477, quality: 100, placeholder: BLURRED)
}
}
altText
}
}
}
}
All these fields are returning null even though they were all working 7 hours ago. The most baffling thing is that the same exact query works when I decided to query through allWpPage
and nodes
. Why is it working here and NOT working on specific WpPage
query. The first node result returns empty but the second node returns the correct data. Why did it suddenly stop working?
query MyQuery {
allWpPage {
nodes {
homePage {
heroSubtitle
heroTitle
heroPlaystoreCtaText
heroImage {
localFile {
childImageSharp {
gatsbyImageData(width: 614, height: 477, quality: 100, placeholder: BLURRED)
}
}
altText
}
}
}
}
}
Any help would be appreciated. Thank you!!!.
Upvotes: 0
Views: 1448
Reputation: 518
I finally found out the reason it wasn't working was because I added a new page which moved down the home page and caused it to always return null. I modified my query to general wpPages
query and filtered by /
(Home Page) which brought out the specific results for Home Page. Here is the Query I used now:
query HeroQuery {
hero: allWpPage(filter: {uri: {eq: "/"}}) {
edges {
node {
homePage {
heroSubtitle
heroTitle
heroPlaystoreCtaText
heroImage {
localFile {
childImageSharp {
gatsbyImageData(width: 614, height: 477, quality: 100, placeholder: BLURRED)
}
}
altText
}
}
}
}
}
}
Upvotes: 1