Use gatsby-image's GraphQL fragments for blurred-up and traced SVG images

Kyle Gill
InstructorKyle Gill
Share this video with your friends

Social Share Links

Send Tweet

Learn how to simplify the fields you include in your queries for image data by using GraphQL fragments. With this powerful abstraction, changing the fragment will change the behavior of your image, loading it as a minified blurred file or traced svg before loading the full size image when the rest of the content loads.

Instructor: [00:00] With an image where fields are queried in GraphQL, you can use GraphQL fragments provided by Gatsby as a shorthand, instead of writing out all the fields. In the query to get the image's data, instead of typing out each field individually, you can use fragments like GatsbyImageSharpFluid.

[00:14] If you check the data returned by the query, you'll see the same fields returned as before. Different fragments, like tracedSVG, will pull in other fields that will make the gatsby-image component behave in other ways, like adding a traced SVG placeholder, instead of a blurred image.