Member-only story

Gatsby.js — More GraphQL Queries

John Au-Yeung
3 min readFeb 10, 2021

--

Photo by Markus Winkler on Unsplash

Gatsby is a static web site framework that’s based on React.

We can use it to create static websites from external data sources and more.

In this article, we’ll look at how to create a site with Gatsby.

Querying Data in Pages with GraphQL

We can query data in pages with GraphQL with Gatsby.

To do this, we write:

gatsby-config.js

module.exports = {
siteMetadata: {
title: "My Homepage",
description: "This is where I write my thoughts.",
},
}

src/pages/index.js

import React from "react"
import { graphql } from 'gatsby'
export const query = graphql`
query HomePageQuery {
site {
siteMetadata {
description
}
}
}
`
export default function Home({ data }) {
return (
<div>
Hello!
{data.site.siteMetadata.description}
</div>
)
}

We have the website’s metadata in gatsby-config.js .

Then we can get the data in our page by using a GraphQL query.

We create the query with the graphql tag in index.js .

We use it to get the description of our site.

--

--

No responses yet