Up and Running with Gatsby: Working with Data

Solution: Page Query


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 }) => (
    <NavBar />
    <p>This site was built on {}</p>

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