[gatsby-source-graphql] No localFile on featuredImage from Wordpress
See original GitHub issueWhat’s the current situation with gatsby-image
and querying it through gatsby-source-graphql
. With REST API and gatsby-source-wordpress
the query looked like this:
featured_media {
alt_text
localFile {
childImageSharp {
fluid(maxWidth: 1200, maxHeight: 600, cropFocus: CENTER, quality: 100) {
...GatsbyImageSharpFluid
srcSet
}
}
}
}
The localFile
or imageSharp
is no where to find on the featured_media
when used along side gatsby-source-graphql
.
Is this on gatsby-source-graphql
’s end or does it have to do with some of the external plugins as such as gatsby-plugin-sharp
?
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
GatsbyImage not working in production site (Pulling data ...
I'm using Wordpress CMS to set featured images to posts, and trying to render those images in Gatsby. So far, it works when...
Read more >How to handle Images and make use of gatsby-image
We gonna make use of Gatsby's abilities to add custom resolvers, to customize the schema, so that WordPress images get handled as local...
Read more >Adding Images to a WordPress Site
What this tutorial covers: Why go through this tutorial? Installing the gatsby-source-wordpress plugin; Installing plugins to help with images; Creating GraphQL ...
Read more >gatsby-source-graphql
Gatsby plugin which adds a third-party GraphQL API to Gatsby GraphQL. Latest version: 5.3.1, last published: 9 days ago.
Read more >Creating a Gatsby Site with WordPress Data
Unlike WordPress, newer WPGraphQL releases do not support ... Next, we're going to install and configure the gatsby-source-graphql plugin.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @fabianderijk, the workaround was to use the
gatsby-source-filesystem
in combination with yourgatsby-source-graphql
package to fetch and create a media type that allows the usage offeaturedImage
. Below is the packages I included in mygatsby-config
file:And in my
gatsby-node
file I would then fetch the remote files and create nodes that would allow me to useImageSharp
:The above would create a query type
imageFile
onWP_MediaItem
, which allows you to query forImageSharp
. An example of this is seen below:Hope this clarified the issue. If not, feel free to reach out 👍.
Hi @h0rhay and @antoinerousseau. Sorry I haven’t been able to reach out sooner.
Things have changed in both Gatsby and the GraphQL plugin which made my previous answer redundant. In particular there’s changes to how we query the
featuredImage
and how the resolver is structured.Remark: my resolver handles issues with non-english letters being escaped by
encodeURI
. If this isn’t needed in your case you can omit the selective statement and encode function.Start by updating the resolver in
gatsby-node.js
:For the query we now have to care about the new structure of
featuredImage
. EveryfeaturedImage
node contains a nestednode
structure, which was absent from my previous example:This also means that any previous references to for example
data.wp.featuredImage.imageFile.childImageSharp.fluid
should be changed to contain thenode
so that it becomesdata.wp.featuredImage.node.imageFile.childImageSharp.fluid
. The references might contain adata
prefix as in my example, but depends on your particular setup.I hope this was of any assistance to you both. If that was not the case do not hesitate to reach out once again.