datocms / gatsby-source-datocms

Official GatsbyJS source plugin to pull content from DatoCMS
MIT License
140 stars 50 forks source link

Add support for gatsby-plugin-image #149

Closed ascorbic closed 3 years ago

ascorbic commented 3 years ago

This PR adds support for the exciting new gatsby-plugin-image, by adding a new gatsbyImageData alongside the old fixed and fluid resolvers, which are now deprecated.

The query syntax no longer uses fragments, but instead uses arguments passed to the resolver:

query IndexQuery {
  allDatoCmsWork(sort: {fields: [position], order: ASC}) {
    nodes {
      coverImage {
        gatsbyImageData(
          width: 450
          placeholder: BLURRED
          imgixParams: {invert: true}
        )
      }
    }
  }
}

The imgixParams are the same as the old resolvers. There are additionally arguments that match ones used in the core gatsby plugin: layout, width, height, aspectRatio, backgroundColor. The placeholder argument is the same as before, but adds a new DOMINANT_COLOR option, which uses the value from the image.colors array. This is the default, and has the benefit of not needing to download anything at build time. The menaings of the other options, such as the different layout types, can be seen in the plugin reference guide.

This adds gatsby-plugin-image as a peer dependency, and the docs need to be updated to tell users to install the plugin.

If you are happy with the PR I can add updates to the docs as well.

stefanoverna commented 3 years ago

Awesome, thanks @ascorbic! I'll add some tests and let you know how it goes :)

stefanoverna commented 3 years ago

Alright, seems everything is working, released in v2.6.0. Thanks for your PR!

ascorbic commented 3 years ago

I would not suggest giving fm: "jpeg" in the README example, as we try to use auto format.

stefanoverna commented 3 years ago

Agreed!