I'm just after some advice or an idea of the best practice to achieve something. I have these two queries working in GraphiQL:
query LegalLinks {
allMarkdownRemark(
filter: { frontmatter: { templateKey: { eq: "legal" } } }
) {
edges {
node {
frontmatter {
title
}
fields {
slug
}
}
}
}
}
query NavData {
allMarkdownRemark(filter: { frontmatter: { mainNav: { eq: true } } }) {
edges {
node {
frontmatter {
title
subtitle
}
fields {
slug
}
}
}
}
}
The first is looking for all pages that match on the legal
template, for mapping over and putting in the footer (privacy policy, cookies, etc.).
The second is getting all the pages that have been marked as appearing on the main navigation, so I can build a dynamic main navbar.
I can't put both queries in the layout component, so not sure of the best course of action. I could do the filtering in the render method of the layout and build the two datasets that way, but it feels a bit weird to use GraphQL to get _all_ the pages and then filter them at the component level, after all, isn't the main attraction of GraphQL to just query for the data you need?
Assistance greatly appreciated!
You can use aliasing:
http://graphql.org/learn/queries/#aliases
query Name {
legalLinks: allMarkdownRemark()
NavData: allMarkdownRemark()
}
Oh that's awesome! Thank you so much!
Most helpful comment
You can use aliasing:
http://graphql.org/learn/queries/#aliases