Skip to content

Instantly share code, notes, and snippets.

@michaelhayman
Created January 12, 2021 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelhayman/6a276125a58d818bd6c1b0428a23bec8 to your computer and use it in GitHub Desktop.
Save michaelhayman/6a276125a58d818bd6c1b0428a23bec8 to your computer and use it in GitHub Desktop.
module.exports = {
plugins: [
{
resolve: `gatsby-source-graphql`,
options: {
typeName: `GraphCMS`,
fieldName: `gcms`,
url: `https://api-eu-central-1.graphcms.com/v2/ckjp80jbpftcp01z10zldgn49/master`
}
}
]
}
import React from 'react'
import { graphql, useStaticQuery, Link } from 'gatsby'
const postQuery = graphql`
{
gcms {
posts {
id
title
slug
excerpt
author {
name
}
}
}
}
`
const Indexpost = () => {
const data = useStaticQuery(postQuery)
const {
gcms: {
posts
}
} = data
console.log('posts', data, posts)
return (
<div className="posts">
{posts.map(({ slug, ...post }) =>
<div key={slug}>
<Link to={`/posts/${slug}`}>{post.title}</Link>
<div>{post.excerpt}</div>
<div>{post.name}</div>
</div>
)}
</div>
)
}
export default Indexpost
module.exports = {
plugins: [
{
resolve: `gatsby-source-graphql`,
options: {
typeName: `GraphCMS`,
fieldName: `gcms`,
url: `redacated`
}
}
]
}
import React from 'react'
import { graphql, useStaticQuery, Link } from 'gatsby'
const postQuery = graphql`
{
gcms {
posts {
id
title
slug
excerpt
author {
name
}
}
}
}
`
const Indexpost = () => {
const data = useStaticQuery(postQuery)
const {
gcms: {
posts
}
} = data
console.log('posts', data, posts)
return (
<div className="posts">
{posts.map(({ slug, ...post }) =>
<div key={slug}>
<Link to={`/posts/${slug}`}>{post.title}</Link>
<div>{post.excerpt}</div>
<div>{post.name}</div>
</div>
)}
</div>
)
}
export default Indexpost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment