Answered

How to get all images from an Image Gallery through Gatsby GraphQL?

This is posted on behalf of a user:

How do I get references to all the images from an Image Gallery through GraphQL? I can only get the Gallery ID and I do not know where to go from there.

I want to use gatsby-image to optimize all the images in an Image Gallery so that my weather component can load optimized versions of our custom weather images.

I am able to provide the source code of the component in question, if needed.

1

Comments

4 comments
  • Official comment

    Right now, the Agility CMS Gatsby Source Plugin does not source Galleries. We've opened an issue for this on the GitHub repo. It can be found here.

    If you have to use Galleries (an alternative is just creating our own Content Definition that does the same thing), you could extend the `onCreateNode` method and check for content items that have a reference to a Gallery, then you can use the `getGallery` method in the `@agility/content-fetch` REST API to get the data, then, you can use `createRemoteFileNode` to download the images locally and include them in your GraphQL node - just like we do for regular Image fields.

     

    Comment actions Permalink
  • I should clarify that the Image Gallery is attached to a shared content item. So I can get the ID of the image gallery on that shared content item, but that is all the detail that is offered in GraphQL that I can see.

    I even used the Documentation Explorer in GraphQL and was unable to find a lead as to where I could find more information on the images in this image gallery.

    0
    Comment actions Permalink
  • Thank you for the fix and the alternative! I will have to think about which one I need to use. Leaning towards the alternative as I think it will make things less confusing for the end user if they update this field like all the other ones and not have to learn a new workflow just for Image Galleries.

    0
    Comment actions Permalink
  • Yes, there are also some limitations around Galleries in general to be aware of.

    1. You cannot add custom meta data fields
    2. They don't follow the same Multi-language paradigm as content - there is no native multi-language support
    3. Changing a gallery (adding or removing images) does not support content workflows, so there is no moderation or publishing flow - if you make a change it is simply live automatically

    The one thing that galleries are good at is the ability to quickly drag and drop to upload a batch of images. In the future, we may look at providing a similar functionality for regular linked content fields which may render Galleries redundant. It is something we are looking at.

    1
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post