Skip to content

Commit f8d2f76

Browse files
committed
Add sample code showing off gatsby-image + image processing to query with GraphQL page
1 parent 2cec6f5 commit f8d2f76

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

docs/docs/querying-with-graphql.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,33 @@ Gatsby has rich support for processing images. Responsive images are a big part
159159

160160
Combined with a special Gatsby image component, [gatsby-image](/packages/gatsby-image/), you have a very powerful set of primatives for building sites with images.
161161

162+
This is what a component using `gatsby-images` looks like:
163+
164+
```jsx
165+
import React from "react";
166+
import Img from "gatsby-image";
167+
168+
export default ({ data }) => (
169+
<div>
170+
<h1>Hello gatsby-image</h1>
171+
<Img resolutions={data.file.childImageSharp.resolutions} />
172+
</div>
173+
);
174+
175+
export const query = graphql`
176+
query GatsbyImageSampleQuery {
177+
file(relativePath: { eq: "blog/avatars/kyle-mathews.jpeg" }) {
178+
childImageSharp {
179+
# Specify the image processing specifications right in the query.
180+
# Makes it trivial to update as your page's design changes.
181+
resolutions(width: 125, height: 125) {
182+
...GatsbyImageSharpResolutions
183+
}
184+
}
185+
}
186+
}
187+
`;
188+
162189
See also the following blog posts:
163190
164191
* [Making Website Building Fun](/blog/2017-10-16-making-website-building-fun/)

packages/gatsby-image/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ plugins: [
7878

7979
## How to use
8080

81-
This is what a component using `gatsby-images` looks like.
81+
This is what a component using `gatsby-images` looks like:
8282

8383
```jsx
8484
import React from "react";
@@ -95,7 +95,7 @@ export const query = graphql`
9595
query GatsbyImageSampleQuery {
9696
file(relativePath: { eq: "blog/avatars/kyle-mathews.jpeg" }) {
9797
childImageSharp {
98-
# Specify the image processing steps right in the query
98+
# Specify the image processing specifications right in the query.
9999
# Makes it trivial to update as your page's design changes.
100100
resolutions(width: 125, height: 125) {
101101
...GatsbyImageSharpResolutions

0 commit comments

Comments
 (0)