ehowey / gatsby-theme-catalyst

An opinionated set of integrated themes and starters as a boilerplate to accelerate development with GatsbyJS
MIT License
163 stars 15 forks source link

Error in function useSiteMetadata: Cannot read property 'mainNavLeft' of undefined #1278

Closed thomasmost closed 3 years ago

thomasmost commented 3 years ago

Okay, I could use some more help. My Sanity schema is updated, but use-site-metadata in gatsby-theme-catalyst-sanity seems to be pulling up mainNavLeft improperly.

Describe the bug The build succeeds but at runtime I see this:

Error in function useSiteMetadata in ./node_modules/gatsby-theme-catalyst-sanity/src/components/sanity/use-site-metadata.js:156 Cannot read property 'mainNavLeft' of undefined ./node_modules/gatsby-theme-catalyst-sanity/src/components/sanity/use-site-metadata.js:156

To Reproduce Steps to reproduce the behavior:

  1. Check out https://github.com/thomasmost/pscsite/tree/add-contact-page
  2. Make sure on add-contact-page branch
  3. Run npm install
  4. Run gatsby develop

Expected behavior A clear and concise description of what you expected to happen.

It seems like the latest graphql schema isn't being ingested properly by the latest version of the theme.

Screenshots

image

GraphQL looks like this:

{
  allSanityMainNav {
    nodes {
      mainNavLeft {
        id
      }
    }
  }
}

But use-site-metadata.js looks like this:

  // Build the menuLinks array from SANITY data
  const menuLinksLeft = data.allSanityMainNav.nodes[0].mainNavLeft.map(
    (menuLink) => ({
      name: menuLink.name,
      link: menuLink.link,
      location: "left",
      subMenu: menuLink.subMenu,
    })

Desktop (please complete the following information):

ehowey commented 3 years ago

Hey Thomas - sorry about that! I made some changes to make it easier to organize and manage menu items that is likely causing this due to changes the in graphql schema.

I can try to hop on a quick ZOOM call with you later this week. Take a quick look here: https://www.gatsbycatalyst.com/docs/migrating/

You will note that with v7.x I made changes to the SANITY schema for menus to make them drag/drop inside of SANITY. Unfortunately that is what is causing this error for you I believe. The fix is mostly just copy and pasting some files, redeploying the graphql schema from SANITY, and re-entering your menu items.