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

Download images from Prismic to use in gatsby-image #14076

Closed
ppsirius opened this issue May 16, 2019 · 18 comments
Closed

Download images from Prismic to use in gatsby-image #14076

ppsirius opened this issue May 16, 2019 · 18 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@ppsirius
Copy link

I use gatsby-source-prismic-graphql and want to use gatsby-image. Plugin from prismic doesn't support that feature so I thinking about workaround.
I want to download files and then try to use plugin form images.
I have that query in page component (but also want to work with templates):

const homepageQuery = useStaticQuery(graphql`
    query PrismicQuery {
      prismic {
        allHomepages {
          edges {
            node {
              section1_image
            }
          }
        }
      }
    }`
)

I check gatsby-plugin-remote-images but I must give there nodeType but I don't have few of them, not one :[

@daydream05
Copy link
Contributor

daydream05 commented May 16, 2019

You would need to use gatsby-transformer-sharp and gatsby-plugin-sharp so you can use gatsby-image. On your query it would look something like this:

const homepageQuery = useStaticQuery(graphql`
    query PrismicQuery {
      prismic {
        allHomepages {
          edges {
            node {
              section1_image {
                localFile {
                  childImageSharp {
                    fluid(quality: 100) {
                      ...GatsbyImageSharpFluid_withWebp
                    }
                  }
                }
              }
            }
          }
        }
      }
    }`
)

And gatsby-config.

module.exports = {
  plugins: [`gatsby-plugin-sharp`, `gatsby-transformer-sharp`],
}

@ppsirius
Copy link
Author

@daydream05 gatsby-image under the hood use gatsby-transformer-sharp and this plugin also not supported.

@daydream05
Copy link
Contributor

daydream05 commented May 16, 2019

@ppsirius Have you tried it? This is how it's usually done with sources that doesn't have their own image processing. You pull from the source, and you apply transformer sharp on it. If you look at wordpress source plugin, this is how they query it as well.

I also use Prismic for one of my sites, and looking at my codebase, I can't think of any other way how I was able to do it.

Here's an example codebase of how to use gatsby-image with Prismic. If you check, it also uses gatsby-transformer-sharp and gatsby-plugin-sharp and the query uses localFile and childImageSharp

@LekoArts
Copy link
Contributor

@daydream05 He is using the GraphQL plugin, not the normal source plugin :)

@freiksenet Could you chime in here and maybe answer if this is possible / when this is possible?

@LekoArts LekoArts added the type: question or discussion Issue discussing or asking a question about Gatsby label May 17, 2019
@daydream05
Copy link
Contributor

@LekoArts good call! So sorry about that @ppsirius . These amazing people should be able to help you better

@ppsirius
Copy link
Author

@daydream05 Not at all, thanks to You I notice that I use a different plugin that doesn't support image optimization. I switch to right plugin and everything works fine 😎

@kamilDevguru
Copy link

@ppsirius so what is the right plugin?

@ppsirius
Copy link
Author

@kamilDevguru gatsby-source-prismic 😎

@mathiasha
Copy link

@ppsirius So you got gatsby-plugin-remote-images to work with images from Prismic? Would you be able to share some of your code?

@ppsirius
Copy link
Author

ppsirius commented Aug 2, 2019

@mathiasha As I mentioned earlier I use gatsby-source-prismic here You have code where I use it.

@umxr
Copy link

umxr commented Aug 7, 2019

How is it possible to use Gatsby's Image Processing with Prismic when i get a json string returned from my query?

@ppsirius
Copy link
Author

ppsirius commented Aug 7, 2019

@umxr you using the Prismic json the same as is written in Gatsby documentation. You could also look at my example

@umxr
Copy link

umxr commented Aug 7, 2019

@ppsirius im a little confused..In Prismic what is the type of section1_image is it an image? or is it something else.

@ppsirius
Copy link
Author

ppsirius commented Aug 7, 2019

yes

@umxr
Copy link

umxr commented Aug 7, 2019

@ppsirius I get this error if I try what you suggested.

Screenshot 2019-08-07 at 20 19 22

This is my query:

<StaticQuery
    query={graphql`
      query {
        prismic {
          allNavigations(type: "navigation") {
            edges {
              node {
                navigation_contact
                body {
                  ... on PRISMIC_NavigationBodyNavigation_item {
                    fields {
                      navigation_label
                      navigation_link {
                        ... on PRISMIC_Page {
                          _meta {
                            uid
                          }
                        }
                      }
                    }
                  }
                  ... on PRISMIC_NavigationBodySocial_link {
                    type
                    fields {
                      social_item_icon
                      social_item_link {
                        ... on PRISMIC__ExternalLink {
                          url
                        }
                      }
                      social_item_title
                    }
                  }
                }
                logo {
                  localFile {
                    childImageSharp {
                      fluid(maxWidth: 1920, quality: 90) {
                        ...GatsbyImageSharpFluid_withWebp
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    `}
    render={data => (
      <Header data={data.prismic.allNavigations.edges[0].node} {...props} />
    )}
  />

@ppsirius
Copy link
Author

ppsirius commented Aug 8, 2019

You use gatsby-source-prismic?
What exactly you see in grapQL playground on this logo?

@umxr
Copy link

umxr commented Aug 13, 2019

@ppsirius Hey, sorry for the delayed response. I was using the incorrect plugin. i switched over to gatsby-source-prismic and it all worked. Thanks!

@lucashfreitas
Copy link

I think most users have a confusion between two plugins available: gatsby-source-prismic-graphql and gatsby-source-prismic.

Please see this link: [https://user-guides.prismic.io/en/articles/3647135-how-to-migrate-a-project-from-gatsby-source-prismic-to-gatsby-source-prismic-graphql](gatsby source prismic vs source-prismic-graphql).

You can use localFile if you are using gatsby-source-prismic, otherwise you will get an error.

If you are using gatsby-source-prismic-graphql, you should see another attribute for gatsby image after image field by itself as the example below:

node { image_field image_fieldSharp { childImageSharp { fixed { base64 } } } }

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

8 participants