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

Question: How do I query two or 3 images instead of just all or one. #24

Closed
waldothedeveloper opened this issue Aug 24, 2020 · 2 comments

Comments

@waldothedeveloper
Copy link

I'm very excited about this plugin!
In the docs, we have:

  • allCloudinaryMedia to query all images (with a default limit of 10 btw)

  • cloudinaryMedia to fetch one image.

If I'm correct, then what if I need to query love heart.svg and logo.jpg in a single query???

Can something like that be achieved?

Fictitious example (code below doesn't work on graphql)

 const data = useStaticQuery(graphql`
        query CloudinaryImage {
            cloudinaryMedia(public_id: {eq: "cloudinary/love_heart" AND SOMETHING ELSE??????}) {
                secure_url
              }
          }
          `
    );
@waldothedeveloper
Copy link
Author

Never mind, I can use different stuff, for example, graphql aliases if I need multiple queries...glad I figured this out on my own :) 👍

@waldothedeveloper
Copy link
Author

In case someone will need an example in the future of what I was looking for:

import { useStaticQuery, graphql } from "gatsby"

export const getCloudinaryHeroImages = () => {
  const data = useStaticQuery(graphql`
    query getHeroImages {
      hero: cloudinaryMedia(
        public_id: { eq: "your_cloudinary_folder/hero_gadgets" }
      ) {
        secure_url
      }
      loveheart: cloudinaryMedia(
        public_id: { eq: "your_cloudinary_folder/love-heart" }
      ) {
        secure_url
      }
    }
  `)

  return data
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant