1

I am trying to fetch srcset with GraphQL from Craft4 but I don't really understand the syntax. In my twig Templates I use image.getSrcset(['1x','2x'],'myTransformHandle') and I'm trying to translate that to GraphQl
If I use srcset(sizes: ["1x","2x"]) it returns a set with the original image and one upscaled to double the size which doesn't seem that useful.
Has anyone worked with this and knows how to get a useful result?
Thanks

2 Answers 2

1

Inside asset interface you can put the srcset field, here is an example:

{
  asset {
    srcset(sizes:["1x", "1.5x", "2x"])
  }
}
1

I found some answers in this post right here: https://github.com/craftcms/cms/issues/11982 although it still seems like GQL srcset is highly unflexible. But maybe this helps someone:

myTransformHandle: image @transform(handle: "myTransformHandle") {    
    srcset(sizes:["1x","2x"])
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.