🎁

12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
05 : 09 : 40 : 06
1×
Become a member
to unlock all features
Autoplay

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

    Kyle GillKyle Gill
    gatsbyGatsby
    graphqlGraphQL

    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.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: 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.

    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.