Gatsby: Why title is undefined whereas Helmet and Metadata are defined?

Created on 7 Nov 2018  路  5Comments  路  Source: gatsbyjs/gatsby

Hi, what's missing?

My title is undefined...

index.js

capture d ecran 2018-11-07 a 18 24 24

gatsby-config.js

capture d ecran 2018-11-07 a 18 21 49

Result

capture d ecran 2018-11-07 a 18 24 41

Excepted

My homepage

question or discussion

All 5 comments

Found the solution but don't understand why.
I had to "merge" both query instead doing two export const query.

Now my metadata is displayed inside props.data.

Someone can explain why please?

Before

export const pageQuery = graphql`
  query HomeQuery {
    allContentfulBlogPost(
      filter: {
        node_locale: {
          eq: "fr"
        }
      }
      sort: { 
        fields: [publishDate], order: DESC 
      }
    ) {
      edges {
        node {
          node_locale
          title
          slug
          publishDate(formatString: "MMMM Do, YYYY")
          tags
          heroImage {
            sizes(maxWidth: 350, maxHeight: 196, resizingBehavior: SCALE) {
             ...GatsbyContentfulSizes_withWebp
            }
          }
          description {
            childMarkdownRemark {
              html
            }
          }
        }
      }
    }
  }
`

export const mainQuery = graphql`
  query MainQuery {
    site {
      siteMetadata {
        title
      }
    }
  }
`

After

export const pageQuery = graphql`
  query HomeQuery {
    allContentfulBlogPost(
      filter: {
        node_locale: {
          eq: "fr"
        }
      }
      sort: { 
        fields: [publishDate], order: DESC 
      }
    ) {
      edges {
        node {
          node_locale
          title
          slug
          publishDate(formatString: "MMMM Do, YYYY")
          tags
          heroImage {
            sizes(maxWidth: 350, maxHeight: 196, resizingBehavior: SCALE) {
             ...GatsbyContentfulSizes_withWebp
            }
          }
          description {
            childMarkdownRemark {
              html
            }
          }
        }
      }
    }
    site {
      siteMetadata {
        title
      }
    }
  }
`

you can only have one pagequery. and you should put all your queries in there. why would you need to define two?

you can only have one pagequery. and you should put all your queries in there. why would you need to define two?

Yeah I don't even know why I wanted to do this.

Just one last question.

So I can only have one main query by pages.
Whatever if I have multiples query Contentful, Markdown, json etc..., I have to merge them in one query and Gatbsy do the job?

Yes, if you have different sources and want to have them in one query you can do this:

query NamedQuery {
  posts: allMarkdownRemark {
    edges {
      node {
        id
      }
    }
  }
  categories: allSomethingElse {
    edges {
      node {
        id
      }
    }
  }
}

const myPosts = result.data.posts.edges
const myCategories = result.data.categories.edges

Thank you all!

Was this page helpful?
0 / 5 - 0 ratings