Get limited number of images from Gallery field

Hello there,

I’m trying to retrieve records via a GraphQL query, but my queries take too long because I’m querying records with a Gallery field that include dozens of images (even sometimes hundreds), when in fact I only want to retrieve the first image in this gallery. The amount of images retrieved is so large that it crashes Gatsby builds.

It seems that there is no option to limit the number of images returned by this Gallery field.

One of my ideas was to retrieve the first image by querying the SEO field, but it doesn’t contain any images.

Is it something easy to implement? Or can you think of a workaround for my specific issue?

Thank you,

Hello @nspehler are you using our Gatsby source for the build or a GraphQL source?

Because our source plugin fetches everything upfront and the queries are handled directly in Gatsby, so the problem might be internal to Gatsby.

Can you please share your query just to get a sense of what you are doing?


I’m using the gatsby-source-plugin, but it seems like the option to limit the number of images returned from an “Asset gallery” field isn’t available on either GraphQL APIs.

My query looks like the following:

allDatoCmsProperty {
  nodes {
    gallery {
        maxWidth: 1680
        imgixParams: { fm: "jpg", auto: "compress", w: "1680", q: 50 }
      ) {

I don’t know if you can apply the limit: to the gallery field, probably not, but you can give it a try.

Otherwise, have you seen this: GitHub - datocms/gatsby-source-datocms: Official GatsbyJS source plugin to pull content from DatoC

I think it can be faster. The problem in your case is that when you fetch a lot of images you are calling us to get some info and it can timeout.