Skip to content

Commit c9d4f07

Browse files
ascorbicLB
and
LB
authored
docs(gatsby-source-contentful): Add info to readme on use with new image plugin (#29297)
* docs(gatsby-source-contentful): Add info to readme on use with new image plugin * Apply suggestions from code review Co-authored-by: LB <[email protected]> * Add link to plugin Co-authored-by: LB <[email protected]>
1 parent 0b6f2e3 commit c9d4f07

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

packages/gatsby-source-contentful/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,44 @@ To get **all** the `CaseStudy` nodes with `ShortText` fields `id`, `slug`, `titl
351351

352352
When querying images you can use the `fixed`, `fluid` or `resize` nodes to get different sizes for the image (for example for using [`gatsby-image`](https://www.gatsbyjs.org/packages/gatsby-image/)). Their usage is documented at the [`gatsby-plugin-sharp`](https://www.gatsbyjs.org/packages/gatsby-plugin-sharp/) package. The only difference is that `gatsby-source-contentful` also allows setting only the `width` parameter for these node types, the height will then automatically be calculated according to the aspect ratio.
353353

354+
## Using the new Gatsby image plugin
355+
356+
You can now use the beta [gatsby-plugin-image](https://gatsbyjs.com/plugins/gatsby-plugin-image/) to display high-performance, responsive images from Contentful. This plugin is the replacement for gatsby-image, and is currently in beta, but can help deliver improved performance, with a cleaner API. Support in gatsby-source-contentful is still experimental.
357+
358+
To use it:
359+
360+
1. Install the plugins:
361+
362+
```shell
363+
npm install gatsby-plugin-image gatsby-plugin-sharp
364+
```
365+
366+
2. Add the plugins to your `gatsby-config.js`:
367+
368+
```javascript
369+
module.exports = {
370+
plugins: [
371+
`gatsby-plugin-sharp`,
372+
`gatsby-plugin-image`,
373+
// ...etc
374+
],
375+
}
376+
```
377+
378+
3. You can then query for image data using the new `gatsbyImageData` resolver:
379+
380+
```graphql
381+
{
382+
allContentfulBlogPost {
383+
nodes {
384+
heroImage {
385+
gatsbyImageData(layout: FULL_WIDTH)
386+
}
387+
}
388+
}
389+
}
390+
```
391+
354392
## More on Queries with Contentful and Gatsby
355393

356394
It is strongly recommended that you take a look at how data flows in a real Contentful and Gatsby application to fully understand how the queries, Node.js functions and React components all come together. Check out the example site at

0 commit comments

Comments
 (0)