Gatsby
Up and Running with Gatsby: Working with Data

Solution: Page Query

PRO
Outline

Okay, let's add a page query to index.js.

First, we need to import graphql:

impot { graphql } from "gatsby"

I found a neat piece of data in the GraphiQL explorer called buildTime that also takes in a formatString. At the bottom of the page, I can add my page query:

export const query = graphql`
  query {
    site {
      buildTime(formatString: "MM-DD-YYYY hh:mm:ss")
    }
  }
`

Then, I can use that data in our component:

export default ({ data }) => (
  <Layout>
    <NavBar />
    <p>This site was built on {data.site.buildTime}</p>
  </Layout>
)

And that's it! Now we run the server, we should see our build time on the home page.

Let's add our footer in the next video.

 

I finished! On to the next chapter