Source code for Consuming Data with GatsbyJS Pluralsight Course.
- For module 2 - modules/1 branch
- For module 3 - modules/2 branch
- For module 4 - modules/3 branch
- For module 5 - modules/4 branch
Code snippets used throughout the course.
query MyQuery {
posts {
edges {
node {
id
title
slug
}
}
}
}
{
resolve: 'gatsby-source-wordpress',
options: {
url: 'http://your-wordpress-url/graphql'
}
}
query {
allWpPost {
nodes {
id
title
excerpt
slug
date(formatString: "MMMM DD, YYYY")
}
}
}
allWpPost(sort: {fields: [date]}) {
totalCount
nodes {
id
title
slug
date(formatString: "MMMM DD, YYYY")
featuredImage {
node {
sourceUrl
}
}
categories {
nodes {
name
}
}
excerpt
}
}
{data.allWpPost.nodes.map((node) => (
<Article id={node.id}
to={node.slug}
keywords={node.categories.nodes.name}
title={node.title}
date={node.date}
excerpt={node.excerpt} />
))}
allWpPost(sort: {fields: [date]}) {
nodes {
slug
}
}
result.data.allWpPost.nodes.forEach((node) => {
createPage({
path: node.slug,
component: path.resolve('./src/templates/post.js'),
context: {
slug: node.slug,
},
})
})
const post = data.allWpPost.nodes[0]
query($slug: String!) {
allWpPost(filter: { slug: { eq: $slug } }) {
nodes {
title
content
featuredImage {
node {
sourceUrl
}
}
}
}
}
'gatsby-transformer-sharp',
'gatsby-plugin-sharp'
imageUrl={node.featuredImage.node.sourceUrl}
<img src={props.imageUrl} alt={props.title} width="150px" height="160px" />
localFile {
childImageSharp {
fluid(maxWidth: 400, maxHeight: 250) {
...GatsbyImageSharpFluid
}
}
}
const image = data.allWpPost.nodes[0].featuredImage.node.localFile.childImageSharp.fluid
<Img fluid={image} key={image.src} />
For other snippets see the code-snippets
folder.